Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

When can I access an added data series in State == State.DataLoaded ?

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

    When can I access an added data series in State == State.DataLoaded ?

    Hello,

    I added a ^VIX data series in my code, please see below:

    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Tick, 1);

    AddDataSeries("^VIX", BarsPeriodType.Day, 1);
    ​}


    When I try to access the ^VIX data series in State.DataLoaded, please see below

    else if (State == State.DataLoaded)
    {
    Print("=========================================== ===========");
    Print("^VIX 10 days moving average" + EMA(BarsArray[2], 10)[0]);
    Print("=========================================== ===========");​
    }


    I got the following error message:

    Strategy 'AGG6BarDailyMonthlyVIX': Error on calling the 'OnStateChange' method: Object reference not set to an instance of an object.

    However, if I access the same data series in OnBarUpdate(), it worked fine. Please advise how can t I access it when data has been loaded in State.DataLoaded? Thanks

    else if (BarsInProgress == 2)
    {
    Print("=========================================== ===========");
    Print("^VIX 10 days EMA " + EMA(BarsArray[2], 10)[0]);
    Print("=========================================== ===========");
    }


    Billy​​

    #2
    Hello billythekid72,

    Bar data is not available until the bar data is processed in OnBarUpdate().

    You can initialize an indicator in State.DataLoaded, change colors, properties, etc, but it has not yet started processing data.

    To use an index [0] and get a bar value, this must be done in OnBarUpdate() where data is processed.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you for the reply.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by mlarocco, 06-20-2025, 11:12 AM
      1 response
      51 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by futurenow, 12-06-2021, 05:49 PM
      19 responses
      1,028 views
      0 likes
      Last Post Redders
      by Redders
       
      Started by mathfrick2023, 05-08-2025, 12:51 PM
      8 responses
      141 views
      0 likes
      Last Post Yogaman
      by Yogaman
       
      Started by several, 04-22-2025, 05:21 AM
      1 response
      299 views
      0 likes
      Last Post Lukasxgtx  
      Started by NTEducationTeam, 06-12-2025, 02:30 PM
      0 responses
      54 views
      0 likes
      Last Post NTEducationTeam  
      Working...
      X