graph AverageTrueRange[atrtrailingperiod](close)
To plot prices on the chart GRAPHONPRICE is best suited.
Alright thanks. Would be nice if someone could answer the question before and explain it. I do not have that understanding about ATR
To answer unequivocally, with a Yes or No, we would have to set up the Trailing Stop and the GRAPH in the code.
We are also, at the same time, trying to get our own code / Systems working robustly (and living our lives etc 🙂 ).
I like to see things through to a conclusion, so I will set up the TS on XBT / USD later or might be tomorrow and let you know my findings. Hopefully I will learn something in the process! 🙂
If anybody wants to contribute in the meantime, feel free.
thanked this post
Right, attached is where I am at so far! 🙂
@Grahal
What code are you using to have such a good curve with so many trades?
@Grahal
I mean what kind of entries?
This does not graph the distance from ONCE trailingstoplong = 10. As the distance is never in that curve once more than 10 and my algo running on and have active position has a running trailingstop. Which means that does not plot the ATR distance that I was looking for 🙁
atrtrail = AverageTrueRange[atrtrailingperiod]((close/10)*pipsize)/1000
trailingstartl = round(atrtrail*trailingstoplong)
Well this is explaining how trailing for long is started. My question is, is this part “AverageTrueRange[atrtrailingperiod]((close/10)*pipsize)/1000” affected by market and I guess it is..
Which means just another %trail is much better to run backtest with when the market have recently went up alot or have most data on the from one other market relation
Then optmizing that trailing over 200k bars is just dumb? As for example way back ONCE trailingstoplong = 10 would emean that trailing would start at a MUCH lower amount of latent gain than when market has 2x, 3x or even 10x.
Sorry for multiple messages but no edit button 🙁
With this “Then optmizing that trailing over 200k bars is just dumb” with ATR trailing ofcourse. %trail will allways be more robust than ATR trailing..
Even a %Trail will not work for 10 years. At least I haven’t seen one yet.
Or Grahal?
Well I like to work with maximum data avalaible. Ofcourse all have there own methods.
But it would be good if ATR would work the same way at all times, that would solve all issues. Is it possible replacing this ((close/10)*pipsize)/1000 with something that would not affect marketprice
This is the ATR trail that I use (coded by Paul). I only use it on 2 or 3 systems but my understanding is that it reads the highs and lows over a certain period (default = 14) and moves the stop in accordance with that range, ie the stop only moves up when a new high is achieved, often to just below the last dip.
Typical values for the atr distance are between 3 and 10, but this is definitely not the trail start distance. TBH, after years of using it, it is still a mystery to me at what point the trail starts to move. I always use it in conjunction with a breakeven code, so I always know when that kicks in – then some at point the trail moves up, but it’s all very mysterious (to me) .
I know this doesn’t answer your question, but perhaps you’ll find it helpful anyway. I don’t think the instrument value (ie whether it’s 1000 or 8000) makes any difference; as the name implies, it’s looking at a range, rather than a value.
// atr trailing stop
once trailingstopATR = 1
if trailingstopATR = 1 then
//====================
once tsincrements = 0 // set to 0 to ignore tsincrements
once tsminatrdist = 3
once tsatrperiod = 14 // ts atr parameter
once tsminstop = IG // IG minimum stop distance
tssensitivity = 2 // 1 = close 2 = High/Low 3 = Low/High 4 = typicalprice (not use once)
//====================
if barindex=tradeindex then
trailingstoplong = 6 // ts atr distance
trailingstopshort = 6 // ts atr distance
else
if longonmarket then
if tsnewsl>0 then
if trailingstoplong>tsminatrdist then
if tsnewsl>tsnewsl[1] then
trailingstoplong=trailingstoplong
else
trailingstoplong=trailingstoplong-tsincrements
endif
else
trailingstoplong=tsminatrdist
endif
endif
endif
if shortonmarket then
if tsnewsl>0 then
if trailingstopshort>tsminatrdist then
if tsnewsl<tsnewsl[1] then
trailingstopshort=trailingstopshort
else
trailingstopshort=trailingstopshort-tsincrements
endif
else
trailingstopshort=tsminatrdist
endif
endif
endif
endif
tsatr=averagetruerange[tsatrperiod]((close/10))/1000
//tsatr=averagetruerange[tsatrperiod]((close/1)) // (forex)
tgl=round(tsatr*trailingstoplong)
tgs=round(tsatr*trailingstopshort)
if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
tsmaxprice=0
tsminprice=close
tsnewsl=0
mypositionpriceatr = 0
endif
positioncountatr = abs(countofposition)
if tsnewsl > 0 then
if positioncountatr > positioncountatr[1] then
if longonmarket then
tsnewsl = max(tsnewsl,positionprice * tsnewsl / mypositionpriceatr)
else
tsnewsl = min(tsnewsl,positionprice * tsnewsl / mypositionpriceatr)
endif
endif
endif
if tssensitivity=1 then
tssensitivitylong=close
tssensitivityshort=close
elsif tssensitivity=2 then
tssensitivitylong=high
tssensitivityshort=low
elsif tssensitivity=3 then
tssensitivitylong=low
tssensitivityshort=high
elsif tssensitivity=4 then
tssensitivitylong=typicalprice
tssensitivityshort=typicalprice
endif
if longonmarket then
tsmaxprice=max(tsmaxprice,tssensitivitylong)
if tsmaxprice-positionprice>=tgl then
if tsmaxprice-positionprice>=tsminstop then
tsnewsl=tsmaxprice-tgl
else
tsnewsl=tsmaxprice-tsminstop
endif
endif
endif
if shortonmarket then
tsminprice=min(tsminprice,tssensitivityshort)
if positionprice-tsminprice>=tgs then
if positionprice-tsminprice>=tsminstop then
tsnewsl=tsminprice+tgs
else
tsnewsl=tsminprice+tsminstop
endif
endif
endif
if longonmarket then
if tsnewsl>0 then
sell at tsnewsl stop
endif
if tsnewsl>0 then
if low crosses under tsnewsl then
sell at market // when stop is rejected
endif
endif
endif
if shortonmarket then
if tsnewsl>0 then
exitshort at tsnewsl stop
endif
if tsnewsl>0 then
if high crosses over tsnewsl then
exitshort at market // when stop is rejected
endif
endif
endif
mypositionpriceatr = positionprice
endif
ATR distance that I was looking for
What TF are you running on?
This Topic is discussing an ATR based Trailing Stop, the ‘ATR distance’ is therefore related to TF.