In addition to the primary bars, I've added an additional data series when processing reaches State.Configure.
From the documentation, it looks like I should be able to access this data when processing reaches State.DataLoaded. But if I attempt to access the bar, barArry or any of the derivative arrays (Closes, etc.) at that time, they are null.
If I step through the code, it looks like the object transitions to State.Historical after State.DataLoaded and starts processing bars and adding them to the series data (it's calling OnBarUpdate during this time). After some number of bars, the object transitions to State.Transition and then State.Realtime. After it enters State.Realtime, no further bar updates occur (this behavior is expected since the chart is set for daily data, so realtime bar updates would not occur intraday).
If I look at the bar series for both the primary and secondary bars at the time processing enters State.Transition, it's much less than the number of bars I asked for. For example, when I asked for 50 bars (BarsToLoad == 50), at the time the processing entered State.Transition, the series data had a count of 18. I checked the date range, and that's accurate for the number of bars that I requested.
Can someone clarify 1) Whether all data is actually available at the time State.DataLoaded is processed, and if so, how do I access it? 2) Anything that I might have missed? 3) How I should be coding this to receive all the bars of data that I'm requesting?
The following snippet demonstrates the issue I'm seeing. I set a breakpoints on the CurrentValue assignments in the State.DataLoaded and State.Transition clauses to explore the data available for the object.
protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Testing."; Name = "Testing"; Calculate = Calculate.OnBarClose; MarketSymbol = @"SPY"; } else if (State == State.Configure) { // Apply the same bar period to the market symbol as the primary // data series. BarsPeriod barsPeriod = new BarsPeriod() { BarsPeriodType = BarsPeriod.BarsPeriodType, Value = BarsPeriod.Value, }; BarsRequiredToPlot = BarsToLoad; // Get the market symbol as daily data. Index = 1 AddDataSeries(MarketSymbol, barsPeriod); } else if(State == State.DataLoaded) { CurrentValue = 0.0; } else if(State == State.Transition) { // Transition from historical data to realtime data. CurrentValue = 0.0; } }
Comment