Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

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

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

  • billythekid72
    replied
    Thank you for the reply.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    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.

    Leave a comment:


  • 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​​

Latest Posts

Collapse

Topics Statistics Last Post
Started by ms52390, 06-20-2024, 03:48 PM
2 responses
14 views
0 likes
Last Post ms52390
by ms52390
 
Started by ccrone2024, Today, 05:13 AM
0 responses
5 views
0 likes
Last Post ccrone2024  
Started by ttodua, Today, 03:40 AM
0 responses
6 views
0 likes
Last Post ttodua
by ttodua
 
Started by ttodua, Today, 03:18 AM
0 responses
5 views
0 likes
Last Post ttodua
by ttodua
 
Started by TraderKnG, Today, 01:30 AM
0 responses
13 views
0 likes
Last Post TraderKnG  
Working...
X