ATR Stop Loss query
Forums › ProRealTime English forum › ProOrder support › ATR Stop Loss query
- This topic has 6 replies, 3 voices, and was last updated 5 years ago by
sulimaster.
-
-
01/14/2020 at 10:07 PM #116821
Hi
In the below code, is the ATR related stop loss level re-calculated after close of every bar when trade is on market? I want to use the ATR of the bar just before the trade was executed. Any ideas how this can be coded please?
Thanks
Sachin
12345678910111213141516171819202122232425262728293031// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivatedx = AroonUp[10]y = AroonDown[10]// Conditions to enter long positionsIF (x > y) THENBUY 1 PERPOINT AT MARKETENDIF// Conditions to exit long positionsIF (y > x) THENSELL AT MARKETENDIF// Conditions to enter short positions//IF (y > x) THENSELLSHORT 1 PERPOINT AT MARKETENDIF// Conditions to exit short positionsIF (x > y) THENEXITSHORT AT MARKETENDIFSET STOP LOSS AverageTrueRange[14](close)01/14/2020 at 10:51 PM #116825123456789101112131415161718192021222324252627282930313233343536373839// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivatedIF OnMarket THENSL = 0ELSESL = AverageTrueRange[14](close)ENDIFx = AroonUp[10]y = AroonDown[10]// Conditions to enter long positionsIF (x > y) THENBUY 1 PERPOINT AT MARKETENDIF// Conditions to exit long positionsIF (y > x) THENSELL AT MARKETENDIF// Conditions to enter short positions//IF (y > x) THENSELLSHORT 1 PERPOINT AT MARKETENDIF// Conditions to exit short positionsIF (x > y) THENEXITSHORT AT MARKETENDIFIF SL > 0 THENSET STOP LOSS SLENDIFyou need to calculate and set SL only when not Onmarket, once a trade is opened it must no be set anymore.
1 user thanked author for this post.
01/14/2020 at 10:54 PM #116826Try this (not tested). The ATR stop is fixed at the ATR value at the close of the decision bar which is the one before the trade is actually executed. Not sure if you mean this bar or the one before the decision bar so just change the [0] to [1] in AverageTrueRange[14](close[0]) if it is the the ATR of the bar before the decision bar that you mean.
12345678910111213141516171819202122232425262728293031// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivatedx = AroonUp[10]y = AroonDown[10]// Conditions to enter long positionsIF not longonmarket and(x > y) THENBUY 1 PERPOINT AT MARKETSET STOP LOSS AverageTrueRange[14](close[0])ENDIF// Conditions to exit long positionsIF (y > x) THENSELL AT MARKETENDIF// Conditions to enter short positions//IF not shortonmarket and (y > x) THENSELLSHORT 1 PERPOINT AT MARKETSET STOP LOSS AverageTrueRange[14](close[0])ENDIF// Conditions to exit short positionsIF (x > y) THENEXITSHORT AT MARKETENDIF1 user thanked author for this post.
01/14/2020 at 10:57 PM #116827Roberto – you beat me by three minutes but your code will not set the stop loss until the trade has been open for one bar.
2 users thanked author for this post.
01/14/2020 at 11:30 PM #116829Thanks Vonasi
Yes, ATR at close of the decision bar. Your code will execute both rows 10 and 11? No need for AND or anything else after MARKET on row 10 and before SET on row 11?
01/14/2020 at 11:53 PM #116831No. Any time SET is read in the code it sends an order to your broker. That order stays on the market till it is either filled or it is cancelled or changed by another SET instruction being read in the code.
1 user thanked author for this post.
01/15/2020 at 12:18 AM #116833Thank you Vonasi. Learnt something very useful today.
FYI – I’ve done a quick test and it seems to work
-
AuthorPosts
Find exclusive trading pro-tools on