Forums › ProRealTime English forum › ProOrder support › Need help to code a more dynamic trailing stop › Reply To: Need help to code a more dynamic trailing stop
02/01/2018 at 8:03 AM
#61167
I have developed a slightly different approach that works well for me so far.
I attempt to calculate a very accurate ATR right before opening a new position using something like this:
1 |
ATR = average[max(1,10)](((AverageTrueRange[5](close)[17])+(AverageTrueRange[5](close)[12])+(AverageTrueRange[8](close)[2]))/3) |
Then using this ATR value I calculate the following levels once at open using WF optimization:
- Target i.e. 10*ATR
- Trailing Initiate i.e. 6*ATR
- Stop i.e. 5*ATR
Only once a close beyond the Trailing Initiate level is registered I start trailing. Here is a example of how I do it:
1 2 3 4 5 |
If longonmarket and close < positionprice + (highest[barindex-tradeindex](close) - positionprice)*0.6 Then Sell at Market ElsIf shortonmarket and close > positionprice - (positionprice - lowest[barindex-tradeindex](close))*0.6 Then Exitshort at Market EndIf |