Normal atr trailingstop
Forums › ProRealTime English forum › ProOrder support › Normal atr trailingstop
- This topic has 42 replies, 5 voices, and was last updated 2 years ago by Franro.
Tagged: atr, atr trailing stop, graph, GRAPHONPRICE, stop, trailing, trailing stop
-
-
04/15/2022 at 5:06 AM #191778
Thanks for the answer none. Well it is not random going back in time when indices was much lower you could see that for example a distance of 5 could have MFE for example 50 euro and be a win still. But when indicies or the market has 2x that price the MFE tends to higher to make it a win (easily checked in bt). And btw.. I use it with atr distances > 10 also.
grahal I run it on all tf basicly but I have noticed it is less robust with fewer trades and when the most trades are for example at a much lower level and the market has gone up much recently. As it would require a much higher MFE which does not seem logical to me.
04/15/2022 at 5:15 AM #191780I must add does not seem logical to me and robust that way? But still it is the best trailingstop in times of results (gain, drawdown, losses).
This type of atr trailing would be really good I think with scale with time acceleration (the longer time in market a bigger step). Because I run this on 1 hour tf also. Let say a system consolidates and you are at 1000 euro gain. Then ts wont move and after x days the system is still open with same gain and stoploss. That both costs money (overnight fees etc.) and maybe the entry that was taken days ago is not so validate anymore.
04/15/2022 at 5:30 AM #191781You can increase your trailing stop by an additional X pips every N bars on market:
12345678910Once N = 50 //50 barsOnce X = 20 * PipSize //20 pipsOnce M = 1.10 //1.10 multiplierMyTrailingStop = …..If OnMarket and (((BarIndex - TradeIndex) MOD N) = 0) thenMyTrailingStop = MyTrailingStop + X//MyTrailingStop = MyTrailingStop * MEndifI also included a MULTIPLIER line, instead of a constant value. You can choose between the two.
1 user thanked author for this post.
04/15/2022 at 5:37 AM #191782ts12345678910111213141516171819Once N = 50 //50 barsOnce X = 20 * PipSize //20 pipsOnce M = 1.10 //1.10 multiplierMyTrailingStop = atrtrailIf OnMarket and (((BarIndex - TradeIndex) MOD N) = 0) thenMyTrailingStop = MyTrailingStop + XEndifONCE trailingStopType = 1ONCE trailingstoplong = 10ONCE trailingstopshort = 6ONCE atrtrailingperiod = 100ONCE minstop = 1atrtrail = AverageTrueRange[atrtrailingperiod]((close/10)*pipsize)/1000trailingstartl = round(atrtrail*trailingstoplong).... goes on with my stop posted.Where am I doing wrong here?
04/15/2022 at 6:52 AM #191783Firstly you have to reference any variable AFTER it’s been defined (the code is executed sequentially), as atrtrail has not yet been defined in line 4.
Secondly, if you write line 4 that way, you’ll always change it’s value each bar, thus making increases vanish. You should make sure it NEVER drops (if LongOnMarket) below the previous one:
12MyTrailingStop = max(atrtrail,MyTrailingStop) //LONG sideMyTrailingStop = min(atrtrail,MyTrailingStop) //SHORT side04/15/2022 at 6:57 AM #19178404/15/2022 at 8:14 AM #191785There you go:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071/*beyond adding the above lines, I also changed it a bit to make sure it never drops (when LongOnMarket) or rises (when ShortOnMarket) compared to the currently retained value*/if not OnMarket thenif close crosses over average[100] thenbuy at marketelsif close crosses under average[100] thensellshort at marketendifendifset stop ploss 250set target pprofit 500ONCE trailingStopType = 1ONCE trailingstoplong = 10ONCE trailingstopshort = 6ONCE atrtrailingperiod = 100ONCE minstop = 1Once N = 5 //5 barsOnce X = 5 * PipSize //5 pipsOnce M = 1.10 //1.10 Long multiplierOnce P = 0.90 //0.90 Short multiplieratrtrail = AverageTrueRange[atrtrailingperiod]((close/10)*pipsize)/1000trailingstartl = round(atrtrail*trailingstoplong)trailingstartS = round(atrtrail*trailingstopshort)if trailingStopType = 1 THENTGL =trailingstartlTGS=trailingstartsif not onmarket thenMAXPRICE = 0MINPRICE = closePREZZOUSCITA = 0ENDIFif longonmarket thenMAXPRICE = MAX(MAXPRICE,close)if MAXPRICE-tradeprice(1)>=TGL*pointsize thenif MAXPRICE-tradeprice(1)>=MINSTOP thenPREZZOUSCITA = max(MAXPRICE-TGL*pointsize,PREZZOUSCITA)ELSEPREZZOUSCITA = max(MAXPRICE - MINSTOP*pointsize,PREZZOUSCITA)ENDIFIf ((BarIndex - TradeIndex) MOD N) = 0 thenPREZZOUSCITA = PREZZOUSCITA + X//PREZZOUSCITA = PREZZOUSCITA * MEndifENDIFENDIFif shortonmarket thenMINPRICE = MIN(MINPRICE,close)if tradeprice(1)-MINPRICE>=TGS*pointsize thenIF PREZZOUSCITA = 0 THENPREZZOUSCITA = 9999999 //make sure there's a value large enough to be later used with MIN()ENDIFif tradeprice(1)-MINPRICE>=MINSTOP thenPREZZOUSCITA = min(MINPRICE+TGS*pointsize,PREZZOUSCITA)ELSEPREZZOUSCITA = min(MINPRICE + MINSTOP*pointsize,PREZZOUSCITA)ENDIFIf ((BarIndex - TradeIndex) MOD N) = 0 thenPREZZOUSCITA = PREZZOUSCITA - X//PREZZOUSCITA = PREZZOUSCITA * PEndifENDIFENDIFif onmarket and PREZZOUSCITA>0 thenEXITSHORT AT PREZZOUSCITA STOPSELL AT PREZZOUSCITA STOPENDIFENDIFgraphonprice PREZZOUSCITA coloured(255,0,0,255)1 user thanked author for this post.
04/15/2022 at 8:17 AM #191786Lines 1-3 are the newly supported multi-line comments. The “ADD PRT CODE” button doesn’t recognize them yet (ProOrder does, though), but will be updated asap.
2 users thanked author for this post.
04/15/2022 at 10:24 AM #19179104/15/2022 at 10:38 AM #191792Either one, it would be good testing the other one.
Example 1. count bars from entry (if trailing has started and it has gone like x bars on 1hour chart maybe the trade just got lucky and would be better to close faster as trailing has kicked in)
Example 2. count bars from trailing (if trade was not “lucky” but has been a long time in trailing phase but not proceed)
Which one is the code above and how can I change it to the other one.
04/15/2022 at 11:22 AM #191793Good questions Franro and good ideas!
I read ‘N’ as number of bars since trade entry without Trailing Stop started and so … get out quick with small profit as ExitPrice + X?
This TS is getting better all the time and I am making myself learn stuff as I go along … onward and upward!!! 🙂
Let’s see what Roberto has to say?
1 user thanked author for this post.
04/15/2022 at 12:36 PM #191794N is related to the start of the trade (TradeIndex). A difference is then computed each bar, with the current BarIndex, to detect when it reaches a multiple of N (I set it to 5, but yoyu can set it to any value, if yoy set it to, say, 99999 it will automatically be disabled, as it’s such a huge number that it will not easily reach a multiple of it!), each time that occurs it’s an increase of your trailing stop.
Use GRAPH extensively to spot values and expressions:
123graph BarIndexgraph TradeIndexgraph (Barindex - TradeIndex) MOD N04/15/2022 at 1:52 PM #191796Ok so if I put for example 5 to N
and X to 5.Does this mean after 5 bars, 5 pips will be added to trailing when its starting? And lets say after 20 bars.. and trailing has not started, when its starts it is going to add 5×20=100 pips to it and so on?
If it is like that there will not be a possiblity to get it better? Because finding a combination that suits N and X would be almost impossible? Then it would be better to just after ANY bars close trade.
..
I hope it works like this: If I put N to 5 it counts the bars and X is started FIRST when trailing is started (which I guess how it will work also)? And then X (in pips will be added each time trailing updates in this case 1hour timeframe)
-
AuthorPosts
Find exclusive trading pro-tools on