[SIZE="2"]{ public class KLL391v2 : Strategy { private ATR ATR1; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Strategy here."; Name = "KLL391v2"; Calculate = Calculate.OnBarClose; EntriesPerDirection = 1; EntryHandling = EntryHandling.AllEntries; IsExitOnSessionCloseStrategy = true; ExitOnSessionCloseSeconds = 30; IsFillLimitOnTouch = false; MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix; OrderFillResolution = OrderFillResolution.Standard; Slippage = 0; StartBehavior = StartBehavior.WaitUntilFlat; TimeInForce = TimeInForce.Gtc; TraceOrders = false; RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose; StopTargetHandling = StopTargetHandling.PerEntryExecution; BarsRequiredToTrade = 200; // Disable this property for performance gains in Strategy Analyzer optimizations // See the Help Guide for additional information IsInstantiatedOnEachOptimizationIteration = true; PeriodoATR = 20; Multipos = 0.5; Multineg = -0.5; Multicero = 0.0; } else if (State == State.Configure) { ATR1 = ATR(Convert.ToInt32(PeriodoATR)); SetStopLoss(@"", CalculationMode.Currency, ATR1[0], false); } } protected override void OnBarUpdate() { if (CurrentBars[0] < 200) return; // Set 1 if (((Open[50]-Low[1]) > (Multipos * ATR1[0])) && ((Close[25]-Open[32]) > (Multicero * ATR1[0]))) { EnterLong(Convert.ToInt32(DefaultQuantity), ""); } // Set 2 if (((Open[35]-Open[5]) < (Multineg * ATR1[0])) && ((High[25]-Close[57]) < (Multicero * ATR1[0]))) { EnterShort(Convert.ToInt32(DefaultQuantity), ""); } } #region Properties [NinjaScriptProperty] [Range(1, int.MaxValue)] [Display(ResourceType = typeof(Custom.Resource), Name="PeriodoATR", Order=1, GroupName="NinjaScriptStrategyParameters")] public int PeriodoATR { get; set; } [NinjaScriptProperty] [Range(-1, double.MaxValue)] [Display(ResourceType = typeof(Custom.Resource), Name="Multipos", Description="Multiplicador positivo", Order=2, GroupName="NinjaScriptStrategyParameters")] public double Multipos { get; set; } [NinjaScriptProperty] [Range(-1, double.MaxValue)] [Display(ResourceType = typeof(Custom.Resource), Name="Multineg", Description="Multiplicador negativo", Order=3, GroupName="NinjaScriptStrategyParameters")] public double Multineg { get; set; } [NinjaScriptProperty] [Range(-1, double.MaxValue)] [Display(ResourceType = typeof(Custom.Resource), Name="Multicero", Description="Multiplicador cero", Order=3, GroupName="NinjaScriptStrategyParameters")] public double Multicero { get; set; } #endregion } }[/SIZE]
[SIZE="2"]Strategy 'KLL391v2': Error on calling 'OnStateChange' method: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.[/SIZE]
I´ve tried changing different things but nothing works. There´s enoguh bars to load, so I´m lost wondering what can be wrong in my simple strategy code.
Any clues??
Thank you in advance
Comment