Stop & Target
Forums › ProRealTime English forum › ProOrder support › Stop & Target
- This topic has 8 replies, 2 voices, and was last updated 8 years ago by Seb.
-
-
03/30/2016 at 4:17 PM #4640
Hi everyone,
I have a question concerning stop losses and targets, not really for a specific strategy.
Stop loss for longs: How would I code a stop loss that is 3 points below the lowest low of the 5 bars preceding the signal bar (also include the signal bar itself)? The stop must not trail the position.
Stop loss for shorts: How would I code a stop loss that is 3 points above the highest high of the 5 bars preceding the signal bar (also include the signal bar itself)? The stop must not trail the position.
Target for longs/shorts: How would I code a target that is twice the distance between the entry level and the stop level away from the entry level? (target is 2 * risk)
Greetings, Seb
03/30/2016 at 4:49 PM #4644Hello Seb,
You should use the LOSS instruction that defines a stoploss in pips/points values. To find a this value you’ll have to subtract your lowest low value to the current open price (which represent the price where your trade is executed) and then add your 3 points distance to the result.
Here is a simple code example for what you want to achieve here :
1234567myMACD = MACD[12,26,9](close)long = myMACD crosses over 0IF long AND NOT LONGONMARKET THENBUY 1 LOT AT MARKETSET STOP LOSS (Open-Lowest[5](low))+3*pipsizeENDIFAnd vice-versa for the SELL stoploss. For the takeprofit parameter, you’ll just have to use the TARGET instruction.
03/31/2016 at 10:09 AM #4683Thank you Nicolas, I completed the MACD example with the target instruction, long-only to begin with:
12345678myMACD = MACD[12,26,9](close)long = myMACD crosses over 0IF long AND NOT LONGONMARKET THENBUY 1 LOT AT MARKETSET STOP LOSS (Open-Lowest[5](low))+3*pipsizeSET TARGET PROFIT 2*((Open-Lowest[5](low))+3*pipsize)ENDIFIt doesn’t give me the results I was looking for unfortunately. I uploaded an image in the attachment with the ProBacktest entry and exit points.
The first entry is at 9275.1. The 5 period low is 9137.3, the stop should be 3 points lower at 9134.3. This gives the position a risk of 9275.1 – 9134.3 = 140.8. The target should be two times the risk, at 9275.1 + (2*140.8) = 9556.7. The position exits at 9392.5 though?!
The second position opens at 9517.5. The 5 period low is 9360.5, so the stop should be 3 points lower at 9357.5. The position gets stopped out at 9380.9 though?!
I have no clue why it takes different exit points, do you know what causes this?
03/31/2016 at 12:01 PM #4688You got a more clear view of your code with variable for your SL and TP like this :
1234567891011myMACD = MACD[12,26,9](close)long = myMACD crosses over 0IF long AND NOT LONGONMARKET THENBUY 1 LOT AT MARKETmySL = (Open-Lowest[5](low))+3*pipsizeSET STOP LOSS mySLSET TARGET PROFIT 2*mySLENDIFYour stoploss and takeprofit values are different because each conditions are only tested once a bar. In live trading, that’ll be different because SL and TP would be written into the broker order book.
You can debug and see your “mySL” variable on backtest result by adding this line below at the end of your code :
1GRAPH mySL as "stoploss"Then you’ll get your variable drawn on chart like the picture attached.
03/31/2016 at 1:58 PM #4703Merci,
The graph shows that the stoploss value stays constant from the signal bar and the exits are the according to the SL and TP commands.
But the stoploss value doesn’t represent the distance from the 5 period lowest low to the entry plus the extra 3 points strangely enough. Could it be that the mySL line is not correct?
03/31/2016 at 2:27 PM #470703/31/2016 at 4:34 PM #471403/31/2016 at 7:36 PM #472403/31/2016 at 8:03 PM #4727 -
AuthorPosts
Find exclusive trading pro-tools on