Better True ATR
Forums › ProRealTime English forum › General trading discussions › Better True ATR
This topic contains 16 replies, has 4 voices, and was last updated by Leo 1 week, 3 days ago.
Attachments list


12/03/2017 at 10:47 PM #54616
Good Day Everyone
I am looking for some inputs regarding calculating a better true reflection of ATR rather than just using the simple ATR calculated over n amount of periods.
My thoughts here are to get rid of the extremes (suxh as price spikes) that tend to skew ATR.
So two approaches I have tried so far is;
Calculating the Median ATR using i.e. 3 data samples;
12345678910ATR1 = AverageTrueRange[x](close)ATR2 = AverageTrueRange[x](close)[x]ATR3 = AverageTrueRange[x](close)[x+x]If (ATR1 > ATR2 and ATR1 < ATR3) or (ATR1 > ATR3 and ATR1 < ATR2) ThenATR = ATR1ElsIf (ATR2 > ATR1 and ATR2 < ATR3) or (ATR2 > ATR3 and ATR2 < ATR1) ThenATR = ATR2ElsIf (ATR3 > ATR1 and ATR3 < ATR2) or (ATR3 > ATR2 and ATR3 < ATR1) ThenATR = ATR3EndIfOr taking i.e. 3 ‘random data samples and calculating the average (although this will still contain extremes)
1ATR = (ATR + (AverageTrueRange[15](close)[20]+AverageTrueRange[5](close)[15]+AverageTrueRange[15](close))/3)/2Does anyone else maybe have some thoughts around this?
1 user thanked author for this post.
12/03/2017 at 11:09 PM #54617Just wrote this to calculate a 5 data sample Median ATR value Disclaimer: I haven’t checked my logic on this yet, so might be incorrect.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253ATR1 = AverageTrueRange[x](close)[x*0]ATR2 = AverageTrueRange[x](close)[x*1]ATR3 = AverageTrueRange[x](close)[x*2]ATR4 = AverageTrueRange[x](close)[x*3]ATR5 = AverageTrueRange[x](close)[x*4]ATRP = 0ATRN = 0For N = 0 to 4 DoIf AverageTrueRange[x](close)[x*T] > AverageTrueRange[x](close)[x*0] ThenATRP = ATRP + 1EndIFIf AverageTrueRange[x](close)[x*T] > AverageTrueRange[x](close)[x*1] ThenATRP = ATRP + 1EndIFIf AverageTrueRange[x](close)[x*T] > AverageTrueRange[x](close)[x*2] ThenATRP = ATRP + 1EndIFIf AverageTrueRange[x](close)[x*T] > AverageTrueRange[x](close)[x*3] ThenATRP = ATRP + 1EndIFIf AverageTrueRange[x](close)[x*T] > AverageTrueRange[x](close)[x*4] ThenATRP = ATRP + 1EndIfIf AverageTrueRange[x](close)[x*T] < AverageTrueRange[x](close)[x*0] ThenATRN = ATRN + 1EndIFIf AverageTrueRange[x](close)[x*T] < AverageTrueRange[x](close)[x*1] ThenATRN = ATRN + 1EndIFIf AverageTrueRange[x](close)[x*T] < AverageTrueRange[x](close)[x*2] ThenATRN = ATRN + 1EndIFIf AverageTrueRange[x](close)[x*T] < AverageTrueRange[x](close)[x*3] ThenATRN = ATRN + 1EndIFIf AverageTrueRange[x](close)[x*T] < AverageTrueRange[x](close)[x*4] ThenATRN = ATRN + 1EndIfIf ATRP = 2 and ATRN = 2 ThenIf T = 0 ThenATR = ATR1ElsIf T = 1 ThenATR = ATR2ElsIf T = 2 ThenATR = ATR3ElsIf T = 3 ThenATR = ATR4ElsIf T = 4 ThenATR = ATR5EndIfEndIfNext12/04/2017 at 8:53 AM #5462512/04/2017 at 9:01 AM #5462812/04/2017 at 9:02 AM #5463012/04/2017 at 9:04 AM #5463112/04/2017 at 9:06 AM #54632Noticed the start of my loop at line 6 got lost: For N = 0 to 4 Do
Are you sure about N, not T instead? (I’ll update the code)
12/04/2017 at 9:20 AM #5463412/04/2017 at 11:06 AM #54656Also realize I only required half of the If’s as for a uneven number I only have to measure one side of the values to find the median.
123456789101112131415161718192021222324252627282930313233343536373839ATR1 = AverageTrueRange[x](close)[x*0]ATR2 = AverageTrueRange[x](close)[x*1]ATR3 = AverageTrueRange[x](close)[x*2]ATR4 = AverageTrueRange[x](close)[x*3]ATR5 = AverageTrueRange[x](close)[x*4]ATRP = 0For N = 0 to 4 DoIf AverageTrueRange[x](close)[x*T] > AverageTrueRange[x](close)[x*0] ThenATRP = ATRP + 1EndIFIf AverageTrueRange[x](close)[x*T] > AverageTrueRange[x](close)[x*1] ThenATRP = ATRP + 1EndIFIf AverageTrueRange[x](close)[x*T] > AverageTrueRange[x](close)[x*2] ThenATRP = ATRP + 1EndIFIf AverageTrueRange[x](close)[x*T] > AverageTrueRange[x](close)[x*3] ThenATRP = ATRP + 1EndIFIf AverageTrueRange[x](close)[x*T] > AverageTrueRange[x](close)[x*4] ThenATRP = ATRP + 1EndIfIf ATRP = 2 ThenIf T = 0 ThenATR = ATR1ElsIf T = 1 ThenATR = ATR2ElsIf T = 2 ThenATR = ATR3ElsIf T = 3 ThenATR = ATR4ElsIf T = 4 ThenATR = ATR5EndIfEndIfNext12/04/2017 at 11:15 AM #54663I have found that instead of calculating the ATR over the entire barindex as suggested below:
1ATR= average[max(1,barindex)](averagetruerange[14])To rather focus on the actual trading period that my algorithm usually runs i.e. between 09h00 and 22h00.
I can even calculate this for the last n trading sessions/days to get a better average.
12/04/2017 at 12:17 PM #54678Or you could use a minimum of a long period and short period ATR to smooth out the spikes.
1234ATR1 = AverageTrueRange[HighATR]ATR2 = AverageTrueRange[LowATR]LowestATR = MIN(ATR1, ATR2)Indicator with three ATR values for comparison attached.
12/04/2017 at 12:34 PM #54682@vonasi. clever.
However at this stage I am still getting the most consistent results by sampling from different periods and using an average among them.
1ATR = (ATR + (AverageTrueRange[15](close)[20]+AverageTrueRange[5](close)[15]+AverageTrueRange[15](close))/3)/212/04/2017 at 2:01 PM #54698Plotting a graph of your ‘sampling from different periods’ calculation I still get some very big spikes. I don’t know what you are using the ATR results for but if it was for setting Take Profits or Stop Losses this could leave you to some very big TP and SL positions. My ‘lowest of 2’ calculation removes these spikes but at the price of less sensitivity of what is actually happening right now. I am yet to persuade myself that ATR is of any benefit for setting TP and SL positions as it is either too lagging or too spikey. As a method of seeing market volatility it is however quite good – ATR is increasing so something is happening!
12/04/2017 at 2:11 PM #54699I use it as follow:
At position open calculate dynamic TP and SL thresholds using ATR*x (point where TP and SL will be trailed based on then current volatility). Thus it is simply to calculate the level where TP and SL will become applicable in order to give the price enough wiggle room to ‘decide’ on direction. I also update the threshold level at specific times during the day.
12/04/2017 at 2:16 PM #54700 
AuthorPosts