- ago
Cannot access NamedSeries TimeSeries from barHistory
Initialize Exception (CallPut_TSLA.12.23.2021) Line 49 - Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
at WealthLab.Core.DateSynchedList`1.get_Item(Int32 idx)
at WealthScript2.MyStrategy.Initialize(BarHistory putCallbars) in :line 49
at WealthLab.Backtest.UserStrategyExecutor.NewAlgo(List`1 symbols)

CODE:
BarHistory barPCr = GetHistory(bar, "PCR_" + bar.Symbol.Split('_')[1]);       foreach (var ns in barPCr.NamedSeries)          {             WriteToDebugLog("KEY: " + ns.Key);                         TimeSeries TS = ns.Value;             WriteToDebugLog("COUNT: " + TS.Count);             Double a = TS[2];             TimeSeries tt = TS.Clone();                             PlotTimeSeries(tt, ns.Key, "PCR", _baseColor, _line);          }
0
743
Solved
5 Replies

Reply

Bookmark

Sort
- ago
#1
Looks like there is no data at the bar #2 i.e. the bar count is less than 3.
0
- ago
#2
If directly load the #2 bar from bar, it works fine. The namedseris has 249 data points.
0
- ago
#3
What about the BarHistory object you sync with ("bar")?
0
- ago
#4
The bar itself is fine. The close timeseries data is also fine in 2nd bar. The only issues are namedseries of 2nd bar.
0
- ago
#5
The following code works

CODE:
          //create the unsynchronized indicator          BarHistory optionSpy = GetHistoryUnsynched("MAX_SPX.01.05.2022", HistoryScale.Minute5);          TimeSeries maxVol = optionSpy.NamedSeries["max_volume_call"];          //sychrnize it with the data being processed          maxVol = TimeSeriesSynchronizer.Synchronize(maxVol, bars);          //Plot it          PlotTimeSeries(maxVol, "Max Vol", "Vol", Color.Red);
1
Best Answer

Reply

Bookmark

Sort