Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

MTF indicator : System.ArgumentOutOfRangeException* error

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    MTF indicator : System.ArgumentOutOfRangeException* error

    Hello,
    I'm programming an multi time frame indicator. I have a System.ArgumentOutOfRangeException*error but I can't understand why.

    Main indicator

    Code:
    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

    Code:
    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
    
    	}
    }
    In attached debugging screenshot you can notice that CurrentBar is 27 and the error occurs when the program try to acces the Low[12].

    I can understant why?
    Could you help me?

    Thank you in advance.

    Michel
    Attached Files

    #2
    Hello elechim,

    Thank you for your note.

    Your current bar check for your secondary series,

    Code:
     CurrentBars[1] < 1
    Should check that there are more bars than the period you are trying to reference. For example you only require 1 bar, however Period is set to 14.

    Code:
    	DM1 = Decoupage(BarsArray[1],Periodi,true);
    If you were to change your current bar check to,

    Code:
     CurrentBars[1] < 20
    Does this resolve the issue?

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      nothing different

      Hi Alan,

      Thank you for your response.
      I try to change CurrentBars[1] < 1 to CurrentBars[1] < 120 : unfortunately the problem remains the same.

      See attached files.

      Regards,

      Michel
      Attached Files

      Comment


        #4
        Hello elechim,

        There isn't enough information from the screen shots to know exactly however you are using High[i] rather than Highs[1][i] which would explicitly refer to the secondary series. High[i] would refer to the bars in progress, which may or may not have enough bars. Furthermore you could use CurrentBars[1] to refer to the current bar of the secondary series.

        I would suggest removing the additional data series from the script and seeing if the script runs, replace all High/Close/CurrentBars with




        You could also try the following for loop instead of the one you're using,

        Code:
        for(int i=0; i<nb; i++)
        Or

        Code:
        for(int i=0; i<CurrentBars[1]-1; i++)
        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Hello Alan,
          I have created a indicator ("decoupage") which looks for the HH, HL, LL, LH points of Dow's theory, but I would like to show in the same chart Dow's points on units of time different.
          To get there I thought to create another indicator which several time frames bars series s and call the indicator "decoupage" but I have a lot of problem to have enough bars.... . Should I do differently?
          Thank you in advance,
          Michel

          Comment


            #6
            Hello Michel,

            It would not be an issue to pull in several data series of different time frames and plot calculations from those additional data series on the primary series.

            I would suggest studying the following section in the helpguide, as well as the first two indicators which plot secondary data series calculations on the primary series. You could also see the Pivot indicator preloaded with NinjaTrader.

            HelpGuide: Multi-Time Frame & Instruments


            Opening Price (R1)


            InsideBarWithShadow


            I’ve provided a link covering debugging which you may find helpful.
            Debugging: http://ninjatrader.com/support/forum...ead.php?t=3418

            You can also contact a professional NinjaScript Consultants who would be eager to create or modify this script at your request or assist you with your script. Please let me know if you would like our business development follow up with you with a list of professional NinjaScript Consultants who would be happy to create this script or any others at your request.

            Please let us know if you need further assistance.
            Alan P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by judysamnt7, 03-13-2023, 09:11 AM
            4 responses
            53 views
            0 likes
            Last Post DynamicTest  
            Started by ScottWalsh, Today, 06:52 PM
            4 responses
            33 views
            0 likes
            Last Post ScottWalsh  
            Started by olisav57, Today, 07:39 PM
            0 responses
            5 views
            0 likes
            Last Post olisav57  
            Started by trilliantrader, Today, 03:01 PM
            2 responses
            19 views
            0 likes
            Last Post helpwanted  
            Started by cre8able, Today, 07:24 PM
            0 responses
            6 views
            0 likes
            Last Post cre8able  
            Working...
            X