Stop and Take Profit Multiple of ATR
Forums › ProRealTime English forum › ProBuilder support › Stop and Take Profit Multiple of ATR
- This topic has 12 replies, 2 voices, and was last updated 2 years ago by lilo789.
-
-
07/13/2016 at 7:09 PM #10456
Hi,
I”ve spent some considerable time trying to set ONCE a profit and Take profit as a multiple of say an ATR(14) but without success. The code runs without error but doesn’t do anything. Can you help please?
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivatedDEFPARAM FLATBEFORE = 070000 // Flat before this timeDEFPARAM FLATAFTER = 205000 // Flat after this time//use ATR14 to set targets and stops//Set Stop and Targets//reset stop and targetIF NOT ONMARKET THENSt= 0Tp= 0// set Stop and target//ONCE St = ROUND((AverageTrueRange[14](CLOSE))*2)*PointSize//ONCE Tp = ROUND((AverageTrueRange[14](CLOSE))*2)*PointSize//prices to enter tradesBuyPrice = High[0]+2*PointSizeSellPrice = Low[0]-2*PointSize// Conditions to enter long positionsindicator1 = Stochastic[14,5](close)c1 = (indicator1 < 25)indicator2 = Average[20](close)indicator3 = Average[50](close)c2 = (indicator2 > indicator3)IF c1 AND c2 THENBUY 1 PERPOINT AT BuyPrice STOPENDIF// set stopIF LONGONMARKET THENSt = BuyPrice - ROUND((AverageTrueRange[14](CLOSE))*2)*PointSizeTp = BuyPrice + ROUND((AverageTrueRange[14](CLOSE))*2)*PointSizeENDIF// Conditions to exit long positionsindicator4 = Stochastic[14,5](close)c3 = (indicator4 CROSSES UNDER 75)IF c3 THENSELL AT MARKETENDIF// Conditions to enter short positionsindicator5 = Stochastic[14,5](close)c4 = (indicator5 > 75)indicator6 = Average[50](close)indicator7 = Average[20](close)c5 = (indicator6 > indicator7)IF c4 AND c5 THENSELLSHORT 1 PERPOINT AT SellPrice STOPENDIF// set stopIF SHORTONMARKET THENSt = SellPrice + ROUND((AverageTrueRange[14](CLOSE))*2)*PointSizeTp = SellPrice - ROUND((AverageTrueRange[14](CLOSE))*2)*PointSizeENDIF// Conditions to exit short positionsindicator8 = Stochastic[14,5](close)c6 = (indicator8 CROSSES OVER 25)IF c6 THENEXITSHORT AT MARKETENDIF// Stops and targets// STOP AND TARGETSET STOP LOSS StSET TARGET PPROFIT TpENDIF07/14/2016 at 12:34 PM #10460You should compute them like this, without making any conversion to POINTS and set them as decimal values, not price ones:
123//stoploss and takeprofit for long positionsSt = ROUND((AverageTrueRange[14](CLOSE))*2)Tp = ROUND((AverageTrueRange[14](CLOSE))*2)and use these instructions to set them:
12SET STOP LOSS StSET TARGET PROFIT TpWithout the “P” which is made to set POINTS/PIPS stoploss and takeprofit
If you are using the strategy on EURUSD for example, you should expect St and Tp to be : 0.0016 , and that’s the kind of value that LOSS and PROFIT need.
07/14/2016 at 2:33 PM #10467Thanks for looking at this Nicolas, however, neither the stops nor take profits are working on the DAX. e.g. on the tester a buy entry at 9:30, yesterday, was made at 9930.3. By 11:50 this was in profit of 72.5 points it was finally closed at 20:50 at 9943.8. Not sure which ATR the program will use but the entry bar was 15.30219 and the previous ATR 16.4528.
Not sure what actually closed the trade as the stochastic crossed under 75 four times before closing the trade.
I enclose my revised code for reference would appreciate your consideration.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivatedDEFPARAM FLATBEFORE = 070000 // Flat before this timeDEFPARAM FLATAFTER = 205000 // Flat after this time//use ATR14 to set targets and stops//Set Stop and Targets//reset stop and targetIF NOT ONMARKET THENSt= 0Tp= 0//prices to enter tradesBuyPrice = High[0]+2*PointSizeSellPrice = Low[0]-2*PointSize// Conditions to enter long positionsindicator1 = Stochastic[14,5](close)c1 = (indicator1 < 25)indicator2 = Average[20](close)indicator3 = Average[50](close)c2 = (indicator2 > indicator3)IF c1 AND c2 THENBUY 1 PERPOINT AT BuyPrice STOPENDIF// set stopIF LONGONMARKET THENSt = ROUND((AverageTrueRange[14](CLOSE))*2)Tp = ROUND((AverageTrueRange[14](CLOSE))*2)ENDIF// Conditions to exit long positionsindicator4 = Stochastic[14,5](close)c3 = (indicator4 CROSSES UNDER 75)IF c3 THENSELL AT MARKETENDIF// Conditions to enter short positionsindicator5 = Stochastic[14,5](close)c4 = (indicator5 > 75)indicator6 = Average[50](close)indicator7 = Average[20](close)c5 = (indicator6 > indicator7)IF c4 AND c5 THENSELLSHORT 1 PERPOINT AT SellPrice STOPENDIF// set stopIF SHORTONMARKET THENSt = ROUND((AverageTrueRange[14](CLOSE))*2)Tp = ROUND((AverageTrueRange[14](CLOSE))*2)ENDIF// Conditions to exit short positionsindicator8 = Stochastic[14,5](close)c6 = (indicator8 CROSSES OVER 25)IF c6 THENEXITSHORT AT MARKETENDIF// Stops and targets// STOP AND TARGETSET STOP LOSS StSET TARGET PROFIT TpENDIF07/14/2016 at 6:14 PM #1047107/14/2016 at 6:37 PM #1047207/15/2016 at 8:29 AM #1047707/18/2016 at 5:10 PM #1056307/18/2016 at 7:44 PM #1057007/19/2016 at 8:49 AM #1058411/07/2022 at 10:53 AM #203747Hi everybody,
I hope you will appreciate this TV script : https://www.tradingview.com/script/ofwFdl2A-stoch-supertrd-atr-200ma/
It features:
– ATR StopLoss using the price + an ATR multiplier
-ATR TakeProfit using the price + the same ATR mult * 2 so it creates a 1:2 Risk/Reward
– a trade breakeaven stop
The sl/tp are fixed once the trade is launched and do not look to update along the trade.
All these gives a better maxDD, specially the breakeven feature.
Cheers 🙂
11/07/2022 at 2:26 PM #20376311/07/2022 at 4:21 PM #20377111/09/2022 at 7:49 PM #203878Hi again
There you are:
https://www.prorealcode.com/topic/atr-take-profit-stop-breakeven/
Kind Regards
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on