I'm programming an multi time frame indicator. I have a System.ArgumentOutOfRangeException*error but I can't understand why.
Main indicator
namespace NinjaTrader.NinjaScript.Indicators.Perso { public class Decoupage5M : Indicator { private Decoupage DM1; private Decoupage DM30; private Decoupage DM5; // Variable de travail private int idx5 = 0; private int idx1 = -1; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"In 5min Découpage in M30 e in M1"; Name = "Decoupage5M"; IsOverlay = true; IsSuspendedWhileInactive = true; //Disable this property if your indicator requires custom values that cumulate with each new market data event. //See Help Guide for additional information. IsSuspendedWhileInactive = true; Periodi = 14; AddPlot(new Stroke(Brushes.Orange, 4), PlotStyle.Cross, "M30"); AddPlot(new Stroke(Brushes.DodgerBlue, 2), PlotStyle.Cross, "M5"); AddPlot(new Stroke(Brushes.MediumAquamarine, 1), PlotStyle.Cross, "M1"); } else if (State == State.Configure) { AddDataSeries(Data.BarsPeriodType.Minute, 1); AddDataSeries(Data.BarsPeriodType.Minute, 30); } else if (State == State.DataLoaded) { DM5= Decoupage(BarsArray[0],Periodi,true); // DM1 = Decoupage(BarsArray[1],Periodi,true); } } protected override void OnBarUpdate() { if (CurrentBars[0] < 1 || CurrentBars[1] < 1 || CurrentBars[2] < 1) return; // 1 minutes #region 1min else if (BarsInProgress == 1) { int id = 0; DM1 = Decoupage(BarsArray[1],Periodi,true); ////>>>>>> THE PROBLEM OCCUR HERE !!!! >>>>>>>>>>>>>>>>>>> if(DM1[0] != 0) { } Print(" 1 min: "+ CurrentBars[1]+ " "+ Times[1][0]);// +" "+ DM1[0]); } #endregion 1min } #region Properties [NinjaScriptProperty] [Range(1, int.MaxValue)] [Display(Name="Periodi", Description="Periodi delle medie mobili", Order=1, GroupName="Parameters")] public int Periodi { get; set; } [Browsable(false)] [XmlIgnore] public Series<double> M30 { get { return Values[0]; } } [Browsable(false)] [XmlIgnore] public Series<double> M5 { get { return Values[1]; } } [Browsable(false)] [XmlIgnore] public Series<double> M1 { get { return Values[2]; } } #endregion } }
Second indicator
amespace NinjaTrader.NinjaScript.Indicators.Perso { public class Decoupage : Indicator { private SMA smaH; // Moyenne mobile calée sur le plus haut private SMA smaL; // Moyenne mobile calée sur le plus bas // Variables de travail private int LastPoint = 0; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Cet indicateur vise à faire le découpage "; Name = "Decoupage"; IsOverlay = true; IsSuspendedWhileInactive = true; AddPlot(new Stroke(Brushes.DodgerBlue,2), PlotStyle.Cross, "Decoupe"); PerSMA = 14; IndexYesNo = false; //Se true rinvia l'indice della barra dove il picco o la cavità si trova } else if (State == State.Configure) { smaH = SMA(High,PerSMA); smaL = SMA(Low,PerSMA); } } protected override void OnBarUpdate() { // if (CurrentBar < 1) // return; //Initialisation du LastPoint if(LastPoint == 0) { if(Close[0] > smaH[0]) // Recherche d'un pick { LastPoint = CurrentBar; } else if(Close[0] < smaL[0]) // Recherche d'un creux { LastPoint = CurrentBar *-1; } } // Recherche d'un creux else if (LastPoint < 0 && Close[0] > smaH[0]) { int nb = CurrentBar + LastPoint; //LastPoint est négatif int idxc = 0; double creux = Low[0]; LastPoint = CurrentBar ; for (int i = 0; nb > 0 && i <= nb; i++) { if(Low[i] < creux) { creux = Low[i]; idxc = i; } } if (IndexYesNo) { if (idxc == 0) // Questa cagata serve per riuscire a definire se high o low nel caso in cui l'indice é a zero Decoupe[0] = -0.0000001; else Decoupe[0] = Convert.ToDouble(idxc) * -1; } else Decoupe[idxc] = creux; } // Recherche d'un pic else if (LastPoint > 0 && Close[0] < smaL[0]) { int nb = CurrentBar - LastPoint; int idxp = 0; double pic = High[0]; LastPoint = CurrentBar * -1; for (int i = 0; nb > 0 && i <= nb; i++) { if(High[i] > pic) { pic = High[i]; idxp = i; } } if (IndexYesNo) { if (idxp == 0) Decoupe[0] = 0.0000001; else Decoupe[0] = Convert.ToDouble(idxp); } else Decoupe[idxp] = pic; } } #region Properties [NinjaScriptProperty] [Range(1, int.MaxValue)] [Display(Name="PerSMA", Description="Nombre de périodes pour les SMA", Order=1, GroupName="Parameters")] public int PerSMA { get; set; } [Browsable(false)] [XmlIgnore] public Series<double> Decoupe { get { return Values[0]; } } [NinjaScriptProperty] [Display(Name="IndexYesNo", Description="Remplacer val par index?", Order=2, GroupName="Parameters")] public bool IndexYesNo { get; set; } #endregion } }
I can understant why?
Could you help me?
Thank you in advance.
Michel
Comment