Using limit orders for targets in strategy
Forums › ProRealTime English forum › ProOrder support › Using limit orders for targets in strategy
- This topic has 13 replies, 3 voices, and was last updated 5 years ago by Vonasi.
-
-
06/04/2018 at 10:00 AM #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?
Entry/exit code123456789101112131415// Conditions to enter long positionsIF NOT LongOnMarket AND c1 and c2 and c3 and c4 and c5 THENBUY 1 CONTRACTS AT MARKET// 20 pip above entry targett1 = positionprice + (pipsize * 20)// Fibonacci targethh = highest[50](close)ll = lowest[50](close)t2 = ll + ((hh - ll) * 1.272)SELL 1 CONTRACTS AT t1 LIMITSELL 1 CONTRACTS AT t2 LIMITENDIFAny pointers are hugely helpful!
06/04/2018 at 10:50 AM #72192In 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.
06/04/2018 at 2:11 PM #72222Aha! 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. :/
12345678910111213// Conditions to enter long positionsIF NOT LongOnMarket AND c1 and c2 and c3 and c4 and c5 THENBUY 1 CONTRACTS AT MARKETplaceExitOrders = 1ENDIF// Conditions to exit long positionsIf LongOnMarket AND placeExitOrders THENSET TARGET pPROFIT 60SELL 1 CONTRACTS AT positionprice + (pipsize * 20) LIMITgraph low[1]placeExitOrders = 0ENDIF06/04/2018 at 2:23 PM #7223206/04/2018 at 2:24 PM #72233This 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.
06/04/2018 at 2:48 PM #72247Sorry, I was a bit quick with the code. The below is what I meant.
123456789101112// Conditions to enter long positionsIF NOT LongOnMarket AND c1 and c2 and c3 and c4 and c5 THENBUY 1 CONTRACTS AT MARKETplaceExitOrders = 1ENDIF// Conditions to exit long positionsIf LongOnMarket AND placeExitOrders THENSET STOP $LOSS low[1]SELL 1 CONTRACTS AT positionprice + (pipsize * 20) LIMITplaceExitOrders = 0ENDIFThis 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?
06/04/2018 at 3:13 PM #72249Your 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.
06/04/2018 at 3:46 PM #72251Hmm. 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.
06/04/2018 at 4:23 PM #7225806/04/2018 at 4:31 PM #72260Forget 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.
06/04/2018 at 9:02 PM #72275Thanks 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?
06/05/2018 at 6:51 AM #723171234// Conditions to exit long positionsIf LongOnMarket THENSELL 1 CONTRACTS AT positionprice + (pipsize * 20) LIMITENDIFThis 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:
123SET STOP LOSS xSET STOP pLoss xSET STOP $LOSS x06/05/2018 at 9:24 AM #72334Indeed! 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!
06/05/2018 at 10:39 AM #72343Save 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!
-
AuthorPosts
Find exclusive trading pro-tools on