Using limit orders for targets in strategy

Forums ProRealTime English forum ProOrder support Using limit orders for targets in strategy

Viewing 14 posts - 1 through 14 (of 14 total)
  • #72176

    Hi!

    I’m new to the platform and I’m writing a strategy where I have multiple targets. So I figured I’d use SELL X SHARES AT Y LIMIT to setup my targets for a long. However, these never seem to execute when I place them after the market buy. Any ideas what I could be doing wrong?

    Any pointers are hugely helpful!

    #72192

    In line 2 one of your conditions states that lines 3 through 14 have to be executed when NOT LongOnMarket, so, one you are on market they will NOT be executed.

    Moreover, closing partial positions is not allowed as of this version of ProOrder.

     

    #72222

    Aha! I’m not used to programming languages that evaluate the conditions for each line within the statement. I changed it around, now it looks like this. It seems to work for the exit but the stop loss never triggers. :/

     

    #72232

    What stop loss? There is no stop loss in that code just two orders to sell at a higher price.

    #72233

    This works only for the first bar after entry, because line 12 resets placeExitOrders  to zero, preventing the limit order from being placed on subsequent bars!

    Simply comment out that line.

    You could also remove or comment out line 4 and modify line 8 since placeExitOrders is not needed.

    All you have to check to place a SELL order is that your strategy is LONGONMARKET.

     

    #72247

    Sorry, I was a bit quick with the code. The below is what I meant.

    This will immediately after the market buy; set a stop and a limit exit. But it doesn’t seem to work really. Are limit orders only valid one bar?

    #72249

    Your code buys at next bar open but at that point you are not long on market so it does not set the stop loss of limit order. It does this on the next bar closure and each bar after that.

    Yes limit and stop orders are only valid for one bar. Orders placed with SET are valid until triggered or the position is closed.

    Put your SET STOP and LIMIT order in with your IF NOT LONGONMARKET and remove the SET STOP from the IF LONGONMARKET.

    As Robert said the PlaceExitOrders condition is not needed so delete it.

    #72251

    Hmm. Sorry if I’m a bit slow. If they are only valid one bar, how can I refresh them and keep them at the value I first decided when I entered the trade? In this case the stop should always be the at previous bar low from the entry bar.

    Really appreciate the responses! Thanks people.

    #72258

    Do you have accumulating positions or just one position? In other words do you want the stop loss to be at the low before the first position bought or the adjusted to the low before the last position bought with each trade?

    #72260

    Forget that last question as the IF NOT OnMarket tells me my answer!

    Also just realised that in your last code you use SET to put the stoploss order on the market. As I said in the previous post this ‘Sets’ the order on the market so you do not need to repeat the instruction. Only Sell at Limit and Sell at Stop orders have to be repeated at each bar. What is wrong in your code is that you are setting the StopLoss at Market Price when it should be a value such as 50 or 60 pips or dollars. Use close – low[1] to calculate this value.

     

    #72275

    Thanks a lot, it’s actually working now. I must’ve misunderstood the documentation regarding the $LOSS, I read it as it should take the market price as an argument as you say. If I would like to set the initial limit order based on data from where the buy signal was generated, how would I in theory keep that order alive and kicking several bars further down the trade?

    #72317

    This part of your code is already doing that. At every new bar if you are still long on the market it replaces the LIMIT order on the market. PositionPrice has not changed as you have not bought any new positions.

    In fact as your code is not accumulating positions then you do not really need the Limit order. Any of the following would do the same job:

     

    #72334

    Indeed! But let’s say I calculate a Fibonacci level based on the previous 50 bars to my entry. Now I want to use one of these levels as my target and continously move this as we go. I could use SET TARGET, but is there any way to use a LIMIT instead? Or I guess if closing partial positions is not supported in ProOrder, then this kind of thing is not supposed to be supported?

    Anyways, thanks a lot. I’ve got a working strategy right now due to your help!

    #72343

    Save whatever levels you calculate at the time of opening the trade within the IF NOT ONMARKET and then use these levels later in the code to change your target or stop loss on each bar close with a limit or stop order.

    Partial closure is not possible at the moment but is due for release hopefully later this year.

    I’m actually out sailing at the moment and most likely to go out of 4G range soon so I may have to come back to this later if there are any other questions!

Viewing 14 posts - 1 through 14 (of 14 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login