Better True ATR

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #54616 quote
    juanj
    Participant
    Master

    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;

    ATR1 = 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) Then
    ATR = ATR1
    ElsIf (ATR2 > ATR1 and ATR2 < ATR3) or (ATR2 > ATR3 and ATR2 < ATR1) Then
    ATR = ATR2
    ElsIf (ATR3 > ATR1 and ATR3 < ATR2) or (ATR3 > ATR2 and ATR3 < ATR1) Then
    ATR = ATR3
    EndIf

    Or taking i.e. 3 ‘random data samples and calculating the average (although this will still contain extremes)

    ATR = (ATR + (AverageTrueRange[15](close)[20]+AverageTrueRange[5](close)[15]+AverageTrueRange[15](close))/3)/2

    Does anyone else maybe have some thoughts around this?

    stefou102 thanked this post
    #54617 quote
    juanj
    Participant
    Master

    Just 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.

    ATR1 = 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 = 0
    ATRN = 0
    For N = 0 to 4 Do
    If AverageTrueRange[x](close)[x*T] > AverageTrueRange[x](close)[x*0] Then
    ATRP = ATRP + 1
    EndIF
    If AverageTrueRange[x](close)[x*T] > AverageTrueRange[x](close)[x*1] Then
    ATRP = ATRP + 1
    EndIF
    If AverageTrueRange[x](close)[x*T] > AverageTrueRange[x](close)[x*2] Then
    ATRP = ATRP + 1
    EndIF
    If AverageTrueRange[x](close)[x*T] > AverageTrueRange[x](close)[x*3] Then
    ATRP = ATRP + 1
    EndIF
    If AverageTrueRange[x](close)[x*T] > AverageTrueRange[x](close)[x*4] Then
    ATRP = ATRP + 1
    EndIf
    If AverageTrueRange[x](close)[x*T] < AverageTrueRange[x](close)[x*0] Then
    ATRN = ATRN + 1
    EndIF
    If AverageTrueRange[x](close)[x*T] < AverageTrueRange[x](close)[x*1] Then
    ATRN = ATRN + 1
    EndIF
    If AverageTrueRange[x](close)[x*T] < AverageTrueRange[x](close)[x*2] Then
    ATRN = ATRN + 1
    EndIF
    If AverageTrueRange[x](close)[x*T] < AverageTrueRange[x](close)[x*3] Then
    ATRN = ATRN + 1
    EndIF
    If AverageTrueRange[x](close)[x*T] < AverageTrueRange[x](close)[x*4] Then
    ATRN = ATRN + 1
    EndIf
    If ATRP = 2 and ATRN = 2 Then
    If T = 0 Then
    ATR = ATR1
    ElsIf T = 1 Then
    ATR = ATR2
    ElsIf T = 2 Then
    ATR = ATR3
    ElsIf T = 3 Then
    ATR = ATR4
    ElsIf T = 4 Then
    ATR = ATR5
    EndIf
    EndIf
    Next

     

    #54625 quote
    Nicolas
    Keymaster
    Master

    Why not using a simple long term average of ATR of X periods? This is a real median IMO:

    indi = average[max(1,barindex)](averagetruerange[14])
    

     

    #54628 quote
    juanj
    Participant
    Master

    Noticed the start of my loop at line 6 got lost: For N = 0 to 4 Do

    #54630 quote
    juanj
    Participant
    Master

    @Nicolas, I didn’t really think of that to be honest. Will try it and see what gives the most consistent results.

    #54631 quote
    Nicolas
    Keymaster
    Master

    Sorry about that, I’m currently upgrading some things in the website and text formatting errors sometimes appear.. I’m hoping to fix the issue this week 😐 

    #54632 quote
    Nicolas
    Keymaster
    Master
    Noticed 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)

    #54634 quote
    juanj
    Participant
    Master

    Yes sorry it is T and on line 6 not 9. Replying from my phone. 

    #54656 quote
    juanj
    Participant
    Master

    Also 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.

    ATR1 = 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 = 0
    For N = 0 to 4 Do
    
    If AverageTrueRange[x](close)[x*T] > AverageTrueRange[x](close)[x*0] Then
    ATRP = ATRP + 1
    EndIF
    If AverageTrueRange[x](close)[x*T] > AverageTrueRange[x](close)[x*1] Then
    ATRP = ATRP + 1
    EndIF
    If AverageTrueRange[x](close)[x*T] > AverageTrueRange[x](close)[x*2] Then
    ATRP = ATRP + 1
    EndIF
    If AverageTrueRange[x](close)[x*T] > AverageTrueRange[x](close)[x*3] Then
    ATRP = ATRP + 1
    EndIF
    If AverageTrueRange[x](close)[x*T] > AverageTrueRange[x](close)[x*4] Then
    ATRP = ATRP + 1
    EndIf
    
    If ATRP = 2 Then
    If T = 0 Then
    ATR = ATR1
    ElsIf T = 1 Then
    ATR = ATR2
    ElsIf T = 2 Then
    ATR = ATR3
    ElsIf T = 3 Then
    ATR = ATR4
    ElsIf T = 4 Then
    ATR = ATR5
    EndIf
    EndIf
    Next

     

    #54663 quote
    juanj
    Participant
    Master

    I have found that instead of calculating the ATR over the entire barindex as suggested below:

    ATR= 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.

    #54678 quote
    Vonasi
    Moderator
    Master

    Or you could use a minimum of a long period and short period ATR to smooth out the spikes.

    ATR1 = AverageTrueRange[HighATR]
    ATR2 = AverageTrueRange[LowATR]
    
    LowestATR = MIN(ATR1, ATR2)

    Indicator with three ATR values for comparison attached.

    Lowest-ATR-of-2.itf
    #54682 quote
    juanj
    Participant
    Master

    @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.

    	
    ATR = (ATR + (AverageTrueRange[15](close)[20]+AverageTrueRange[5](close)[15]+AverageTrueRange[15](close))/3)/2

     

    #54698 quote
    Vonasi
    Moderator
    Master

    Plotting 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!

    #54699 quote
    juanj
    Participant
    Master

    I 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.

    #54700 quote
    Vonasi
    Moderator
    Master

    If you find a way to get good TP and SL sizing from ATR then please share it as I’m yet to find any method that works consistently due to the laggy/spiky thing!

Viewing 15 posts - 1 through 15 (of 17 total)
  • You must be logged in to reply to this topic.

Better True ATR


General Trading: Market Analysis & Manual Trading

New Reply
Author
author-avatar
juanj @juanj Participant
Summary

This topic contains 16 replies,
has 4 voices, and was last updated by Leo
8 years, 3 months ago.

Topic Details
Forum: General Trading: Market Analysis & Manual Trading
Language: English
Started: 12/03/2017
Status: Active
Attachments: 1 files
Logo Logo
Loading...