Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Get ATR of Instrument from Addon

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

    Get ATR of Instrument from Addon

    Hello,

    I'm trying to get the ATR value of an Instrument from an Addon.

    So, i try to get ATR indicator without success.

    An finally i tried to compute the ATR in a BarRequest but the returned value is false.

    Can you maybe help me to find the good value ?

    Here my sample:
    PHP Code:
    barsRequest.Request(new Action<BarsRequest, ErrorCode, string>((bars, errorCode, errorMessage) =>
    {
    for (int i = 0; i < bars.Bars.Count; i++)
    {
    double high0 = bars.Bars.GetHigh(i);
    double low0 = bars.Bars.GetLow(i);
    
    if (i == 0)
    {
    _atr.Add(high0 - low0);
    }
    else
    {
    double close1 = bars.Bars.GetClose(i-1);
    double trueRange = Math.Max(Math.Abs(low0 - close1), Math.Max(high0 - low0, Math.Abs(high0 - close1)));
    double value = ((Math.Min(i + 1, Period) - 1 ) * _atr[_atr.Count-1] + trueRange) / Math.Min(i + 1, Period);
    _atr.Add(value);
    NinjaTrader.Code.Output.Process(string.Format("val ue: {0}", value), PrintTo.OutputTab1);
    }
    }
    })); 
    
    johnok
    NinjaTrader Ecosystem Vendor - Trade With Me

    #2
    Hello johnok,

    Thank you for the question.

    Indicators can't be called from an addon so to calculate an ATR you would essentially need to copy over the logic from the ATR and remake it using the bars request. There are no Series or any other bar related mechanics in an addon, the BarsRequest would be the primary way for an addon to get historical data or subscribe to realtime data.

    An finally i tried to compute the ATR in a BarRequest but the returned value is false.
    I am not certain I understand what you mean by it returns false, are you referring to the bars request returning false? Your calculation logic would have to go within the bars request and you would need to use a private class level variable to store the result so it can be used outside the bars request.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    627 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    359 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    105 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    562 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    567 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X