I'm getting the "... index outside of bounds error". I've tried to see where the error originates by using prints, but I can't fix the issue.
public class KAMASecondarySeries : Indicator { private Series<double> diffSeries; private double fastCF; private double slowCF; private SUM sum; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionKAMA; Name = NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameKAMA; Fast = 2; IsSuspendedWhileInactive = true; IsOverlay = true; Period = 10; Slow = 30; RangePeriod = 4; AddPlot(Brushes.DodgerBlue, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameKAMA); } else if (State == State.Configure) { AddDataSeries(BarsPeriodType.Range, RangePeriod); //fastCF = 2.0 / (Fast + 1); //slowCF = 2.0 / (Slow + 1); } else if (State == State.DataLoaded) { fastCF = 2.0 / (Fast + 1); slowCF = 2.0 / (Slow + 1); diffSeries = new Series<double>(this); sum = SUM(diffSeries, Period); } } protected override void OnBarUpdate() { Print(Time[0]+" 1 "); if (CurrentBars[0] < RangePeriod && BarsInProgress== 0 ) { Value[0] = Input[0]; //Print(Time[0]+" Value[0] "+Value[0]); Print(Time[0]+" 2 "); return; } if (CurrentBars[1] < Period && BarsInProgress== 1) { Value[0] = Input[0]; Print(Time[0]+" 3 "); return; } Print(Time[0]+" Value[0] "+Value[0]); Print(Time[0]+" 4 "); if (BarsInProgress == 1 && CurrentBars[1] > Period) { double input0 = Input[0]; diffSeries[0] = CurrentBar > 0 ? Math.Abs(input0 - Input[1]) : input0; double signal = Math.Abs(input0 - Input[Period]); double noise = sum[0]; Print(Time[0]+" signal "+signal); // Prevent div by zero if (noise == 0) { Value[0] = Value[1]; return; } Print(Time[0]+" xValue[0] "+Value[0]); double value1 = Value[1]; *** This Print #5 line does not print, suggesting the Value[1] is incorrect *** Print(Time[0]+" 5 "); Value[0] = value1 + Math.Pow((signal / noise) * (fastCF - slowCF) + slowCF, 2) * (input0 - value1); } if (BarsInProgress == 0 && CurrentBars[0] > Period ) Value[0] = Values[1][0]; } #region Properties [Range(1, 125), NinjaScriptProperty] [Display(ResourceType = typeof(Custom.Resource), Name = "Fast", GroupName = "NinjaScriptParameters", Order = 0)] public int Fast { get; set; } [Range(5, int.MaxValue), NinjaScriptProperty] [Display(ResourceType = typeof(Custom.Resource), Name = "Period", GroupName = "NinjaScriptParameters", Order = 1)] public int Period { get; set; } [Range(1, 125), NinjaScriptProperty] [Display(ResourceType = typeof(Custom.Resource), Name = "Slow", GroupName = "NinjaScriptParameters", Order = 2)] public int Slow { get; set; } [Range(1, int.MaxValue), NinjaScriptProperty] [Display(ResourceType = typeof(Custom.Resource), Name = "RANGE Period", GroupName = "NinjaScriptParameters", Order = 3)] public int RangePeriod { get; set; } #end
Comment