Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How is the ATR correctly Calculated ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How is the ATR correctly Calculated ?

    Hi there,

    Question : if the ATR is the SMA of the TrueRange, then ATR(1) should be the TrueRange, correct ?

    If that is true, then why SMA(10) of ATR(1) is not equal to ATR(10) ?

    Is this the correct way to calculate ATR ?
    protected override void OnBarUpdate()
    {
    if(CurrentBar < 1 ) return;
    diff[0] = Math.Max(Math.Abs(Low[0] - Close[1]), Math.Max(High[0] - Low[0], Math.Abs(High[0] - Close[1]))); //High[0] - Low[0];
    Value[0] = smaDiff[0];
    }

    assuming that
    else if (State == State.DataLoaded)
    {
    diff = new Series<double>(this);
    smaDiff = SMA(diff, Period);
    }​​

    This code shows a value similar but not equal to ATR
    Which is the correct code please ?

    #2
    Hello justanothertrader,

    Thank you for your post.

    ATR does not use the SMA in it's calculations. From the Help Guide, the ATR measures:

    "The True Range indicator is the greatest of the following:

    -current high less the current low.

    -the absolute value of the current high less the previous close.

    -the absolute value of the current low less the previous close."



    ATR(10) is not the same as the SMA of ATR because they are not the same calculation. This is why they are two different indicators.

    The code for the ATR indicator is open source. You can look at it in the NinjaScript Editor.

    Please let us know if you have any further questions.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    75 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    45 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    26 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    32 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    62 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X