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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    41 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    20 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    28 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    45 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    37 views
    0 likes
    Last Post CarlTrading  
    Working...
    X