STOP LOSS using ATR
Forums › ProRealTime English forum › ProOrder support › STOP LOSS using ATR
- This topic has 7 replies, 3 voices, and was last updated 1 year ago by deltasystem.
-
-
07/13/2022 at 12:58 PM #197222
Hello,
I’ve been trying different Stop Loss techniques and I have come up with something using ATR. Ive added it to my code as a trailing stop loss but it seems that it is not be calculated as I want it to be. It seems it is not trailing the highest or lowest price made.I am using a 15 minute time frame. Can anyone help me out here ??
1SET STOP PTRAILING WeightedAverage[14](AverageTrueRange[2](close))*2thankyou !
07/13/2022 at 2:25 PM #197228If you insert below in your code, the value will show you the number of points price needs to move before the TS starts to move.
When Set Stop PTrailing does start to move, it only moves 1 point for every 1 point change in price.
1GRAPH WeightedAverage[14](AverageTrueRange[2](close))*21 user thanked author for this post.
07/13/2022 at 2:51 PM #197229Hi GraHal,
thank you. As far as I can see the Stop Loss is not moving up or down correctly with new price highs or lows depending on long or short. Ive attached a screen shot. Am I correct in assuming that the stop loss for this marked 15 minute bar will be 104,67 and will only change after the bar has closed? In this case (I went short on the open of the bar at 12653,3) the price then went down to 12631,5 before rising and I was closed out at 12716,5. From my understanding the StopLoss should have trailed 21 points which means it would have bee 83 points from my entry point so around 12736 but this as not the case since I was closed out at 12716,5. Or am I taking the wrong value for the stop loss? Should i be taking the value on the graph of the 15 minute bar before the trade opens?
If you look at the 2nd screenshot I did and the marked bar which is also a trade I cannot understand how the trade as stopped out so much lower than I am assuming the Stop Loss should be. How much should the trailing stop loss have been, max 84 right? Or possibly even less if I am reading wrongly and it should be the value from the bar before.
I really appreciate your help!
07/13/2022 at 3:33 PM #197233Replacing SET STOP ?TRAILING with a trailing stop code snippet is usually recommended.
07/13/2022 at 4:48 PM #197236I’m sorry I don’t know what a snippet is…
07/13/2022 at 5:07 PM #197237It’s a piece of code that replaces the built-in TRAILING instruction.
It’s quite easy to use, actually you don’t even need to code, just copy & paste lines 17- 56 (at https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/) and append them at the end of your code after removing the SET STOP PTRAILING line.
This is the code:
12345678910111213141516171819202122232425262728293031323334353637383940//*********************************************************************************//trailing stop functiontrailingstart = 20 //trailing will start @trailinstart points profittrailingstep = 5 //trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF//*********************************************************************************You only have to set the two values trailingstart and trailingstep to the ones you prefer.
2 users thanked author for this post.
07/13/2022 at 6:25 PM #197243what a snippet is
Click on below and you will have a pleasant surprise! 🙂
1 user thanked author for this post.
07/13/2022 at 7:07 PM #197245Wow! thanks a million!
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on