Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to get the correct ATR to display

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

    How to get the correct ATR to display

    My objective is to print a line of text at the bottom of a chart window that contains the daily ATR for the one-minute series I am charting. I can get through most of the gyrations okay (I think) except I seem to be pulling the wrong value. The instrument on the 1-minute chart is MES. In the OnStateChange() event, if (State == State.Configure) I
    AddDataSeries(BarsPeriodType.Day, 1);
    Then, when (State == State.DataLoaded), I print out the following values for BarsArray[0] and BarsArray[1]:
    Instrument.FullName, Instrument.MasterInstrument.Name, Instrument.MasterInstrument.TradingHours.Name, and TradingHours.Name.
    The four values are identical for both BarsArray members, and I assume this is because the call to AddDataSeries uses the BarsArray[0] information as a starting point when creating [1].

    Here's the problem: When I display the data box and hover over the next-to-last bar on the daily chart for the same instrument, the value displayed in the data box for ATR(Daily,14) is 93.23; but when I extract
    double atr = ATR(BarsArray[1], 14)[1];
    on my minute chart and print the result to the output window, I get 74.5 (I do a little massaging to get the value of the next-highest tick to display) - so nearly a 20 point difference.
    FWIW, when I do the same exercise with the one minute chart and data box, the numbers are acceptably close (though I kind of expect them to be identical; still, I'm not gonna quibble over a few thousandths of a cent).
    Any suggestions would be appreciated, thanks. As an alternative to making the numbers agree, if anybody knows which one is correct, please point that out and explain. I assume the value on the daily chart as calculated by NT is the answer, but I want to derive that programmatically for myself. I suppose I could dive into the NT indicator code...


    #2
    Hello rick0735,

    Is the ATR added directly to the same 1 minute chart the script printing the value is added to?

    Have you manually added a 1 day series to the chart and used that as the input series for the atr?
    (If not, may I confirm the ATR added to the chart is using the 1 minute series as the input series?)

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Sorry, I guess my attempt to keep the question compact only obfuscated things. Thanks for looking at thhis.
      As I was preparing a more code-like readable response, I noticed the following line in the code I found somewhere in the NinjaScript help files This happens in StateChange = State.Configure:

      // the host must also call the exact same AddDataSeries() call in it's code as well
      AddDataSeries(BarsPeriodType.Day, 1);
      ​So I added the 1-Day series to the main chart as well, in a new panel (which I minimized). All values line up properly now.

      Funny how things improve when you're forced to explain the problem more clearly. You can close this.. Thanks.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      579 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      334 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      554 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      551 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X