I have coded a custom BarsType named 'RangeBarsTypeVola' which is the standard RangeBarsType with a modification that does calculate the bars.BarsPeriod.Value ( = bar range) dynamically as 10% of the prior session daily range. When applied to a chart it looks fine. But when I run a strategy in the Strategy Analyzer I get the following error message:
I have attached my script. My modifications compared to the standard RangeBarsType are just a few lines and are found in the OnDataPoint method and named #region Added code 1 and #region Added code 2.
if (isNewSession) { #region Added code 1 // Recalc. bars.BarsPeriod.Value at the beginning of a new session if (bars.Count > 0 ) { double priorSessionRange_10percent = (sessionHigh - sessionLow) * 0.1; // new range in ticks bars.BarsPeriod.Value = (int) Math.Round(priorSessionRange_10percent/bars.Instrument.MasterInstrument.TickSize); } // Set initial values for new session sessionHigh = close; sessionLow = close; #endregion SessionIterator.GetNextSession(time, isBar); }
#region Added code 2 // Update. sessionHigh, sessionLow sessionHigh = close > sessionHigh ? close : sessionHigh; sessionLow = close < sessionLow ? close : sessionLow; #endregion }
Comment