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

Multiple Data Series and "Index was outside the bounds of the array." error

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

    Multiple Data Series and "Index was outside the bounds of the array." error

    I am using an indicator on a 1020 tick ES chart and wanting incorporate data from a 4080 tick chart.

    I have this in Initialize:
    Add(PeriodType.Tick, 4080);

    I have this in OnBarUpdate:
    if (CurrentBar < 120) return;

    This seems to be causing my error as it is the only place I refer to the additional series:
    Code:
    Plot5.Set(0);
    if (Math.Sign(EMA(Closes[1],10)[0] - EMA(Closes[1],80)[0]) > 0) PlotColors[5][0] = Color.Green;
    else PlotColors[5][0] = Color.Red;
    There seem to be more than enough bars available for calculations, what am I missing?

    #2
    Hello drmartell,

    This likely has to do with accessing bars for the secondary series when they are unavailable from the first. There will be a 1000tick bar before a 4000 tick bar. To resolve you use a similar statement but with CurrentBars - the exact number here depends on how your 1000 tick and 4000 tick bars relate together.

    if (CurrentBars[1] < 120) return;
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks Ryan,

      I am not quite following yet.

      I tried this instead:
      if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired) return;

      That gave me:
      Error on calling 'OnBarUpdate' method for indicator 'test' on bar 87: Index was outside the bounds of the array.

      Then I changed my 'Days to load' from 30 to 90 and the error changed to:
      Error on calling 'OnBarUpdate' method for indicator 'test' on bar 36: Index was outside the bounds of the array.

      So I am not clear on the part about "how your 1000 tick and 4000 tick bars relate together". How do I determine and account for that?

      Comment


        #4
        You will need to increase the bars required for the secondary series. You are calculating your EMA based on 80 bars so will need at least that number for your bars required.

        if (CurrentBars[0] <= BarsRequired || CurrentBars[1] < 80)
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          OK I did that, now I get this:
          Error on calling 'OnBarUpdate' method for indicator 'test' on bar 274: Index was outside the bounds of the array.

          Comment


            #6
            drmartell, can you please give this check below a try for your script?

            if (CurrentBars[0] < 0 || CurrentBars[1] < 0) return;

            If it does still give you an error, can you please attach it here so we could give it a run on our end?

            Thanks,
            BertrandNinjaTrader Customer Service

            Comment


              #7
              OK here it is.

              Thank you for looking at it.
              Attached Files

              Comment


                #8
                One issue with your code is that you reference 6 plots but only have 5 added in the Initialize() method. Need to add an additional Plot5.

                Add(new Plot(new Pen(Color.FromKnownColor(KnownColor.Orange), 4), PlotStyle.Block, "Plot5"));
                Last edited by NinjaTrader_RyanM1; 02-15-2011, 10:16 AM.
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Hilarious! Thanks Ryan, I wish they were all that easy.

                  Too bad it doesn't throw a more specific error in this case.

                  It's working now anyhow

                  Comment


                    #10
                    Glad that sorted out the issue. Thanks for the follow - up, drmartell.
                    Ryan M.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by sidlercom80, 10-28-2023, 08:49 AM
                    168 responses
                    2,262 views
                    0 likes
                    Last Post sidlercom80  
                    Started by Barry Milan, Yesterday, 10:35 PM
                    3 responses
                    10 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by WeyldFalcon, 12-10-2020, 06:48 PM
                    14 responses
                    1,429 views
                    0 likes
                    Last Post Handclap0241  
                    Started by DJ888, 04-16-2024, 06:09 PM
                    2 responses
                    9 views
                    0 likes
                    Last Post DJ888
                    by DJ888
                     
                    Started by jeronymite, 04-12-2024, 04:26 PM
                    3 responses
                    41 views
                    0 likes
                    Last Post jeronymite  
                    Working...
                    X