Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Index Out of Range for multi-series

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

    #16
    Since I couldn't get the barsAgo (Times[1][barsAgo]) to work properly I found out I can use BarsArray[1] to access all the historical data. I'm not sure why NT8 isn't populating barsAgo correctly, but my indicator is working correctly now. In case you have the same problem use:
    BarsArray[1].GetTime(index),
    BarsArray[1].GetHigh(index), ect...to get OHLC for the secondary series. This works every time correctly for me.

    Comment


      #17
      Hello habibalex,

      During our remote session we found that by adding the indicator I have provided in post #13 to an ES 03-16 1 Minute chart with 5 days to load using <Use instrument settings> as the session template, we are able to reproduce the error on your computer.

      Reducing the code was able to highlight than an error can be triggered in the original script by adding to this script to a 1 Minute chart with 5 days to load as the indicator loads without typing into the text box. This textbox may also be causing an error at the time it is triggered with the parameters sent to findFlips as well.

      The next step is to understanding what line of code is causing the first error and why. Then we can address the error being generated by the text box.

      The script is going to have a secondary data series. There is no check in OnBarUpdate to decide which data series this findFlips method on. This means that OnBarUpdate is going to trigger for every bar for both the primary and secondary data series. It is important to know which data series is processing when the method is called.

      I've added a few prints:

      To the beginning on OnBarUpdate() I have added:
      Code:
      Print(string.Format("{0} | BIP: {1} | CurrentBar: {2} | Times[1].Count: {3} | Times[1].Count - 2: {4} | State: {5}", Time[0], BarsInProgress, CurrentBar, Times[1].Count, (Times[1].Count - 2), State));
      This lets me know when the first condition will evaluate as true.

      When calling findFlips I print the values used in the call:
      Code:
      Print(string.Format("{0} | CurrentBars[0]: {1} | CurrentBars[1]: {2} | calling findFlips({3}, {4}, {5})", Time[0], CurrentBars[0], CurrentBars[1], (Times[1].Count - 1), 0, .5));
      To the for loop in findFlips I have added:
      Code:
      Print(string.Format("key: {0} | BarsArray[0].Count: {1} | BarsArray[1].Count: {2} | Times[1].Count - 1 - key: {3}", key, BarsArray[0].Count, BarsArray[1].Count, (Times[1].Count - 1 - key)));
      This tells me when the condition in the findFlips method is true in the loop.

      Last I print:
      Code:
      Print(string.Format("CurrentBars[1]: {0} | endI: {1}", CurrentBars[1], endI));
      This tells me if you are calling a bar from Times[1] before that bar is evaluated in historical data.


      The last print is what is important.
      I am getting the following output:
      CurrentBars[1]: 151 | endI: 252
      Indicator 'FlipsTest': Error on calling 'OnBarUpdate' method on bar 755: Object reference not set to an instance of an object.

      This is telling me that as the primary bar series of 1 minute hits bar 755, the 5 minute bar series does not have that many bars. When the 1 minute series is on bar 755, the 5 minute series is on bar 151 (because there are 1/5th as many bars).

      So CurrentBars[1] is on bar 151 but we are calling Times[1][252] and there isn't a bar there in the 5 minute series yet.

      Attached is the script with the prints added so that you can see how I have arrived at this conclusion.
      Attached Files
      Last edited by NinjaTrader_ChelseaB; 12-29-2015, 02:58 PM.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        habibalex,

        The next step would be to use the prints to find what is happening in your script when the textbox is being used.

        Specifically the print in the if statement with the print of Times[1][endI].
        Print(string.Format("CurrentBars[1]: {0} | endI: {1}", CurrentBars[1], endI));


        If you want to have the script trigger after the last historical bar, you can do this by checking that the CurrentBars[0] is equal to the BarsArray[0].Count minus 1 (because this index is 0 based) and CurrentBars[1] (for the second index) is also equal to its BarsArray[1] index (also minus 1).

        if (State == State.Historical && CurrentBars[0] == (BarsArray[0].Count - 1) && CurrentBars[1] == (BarsArray[1].Count - 1))


        But in the code there should be a check that the index about to be used, in this case endI, is less than the CurrentBar count for that BarsInProgress index (CurrentBars[1]).

        if (endI > CurrentBars[1])
        {
        Print(Times[1][endI];
        }


        You could also only process this on the secondary BarsInProgress index and return if the BarsInProgress is not the secondary series, the series for which the time is being printed. This would be added to the first line of OnBarUpdate().
        if (BarsInProgress != 1)
        return;
        Chelsea B.NinjaTrader Customer Service

        Comment


          #19
          On ES using a 1 minute chart w/ the session set to <Use Instrument Settings> (CME US Index Futures RTH ) I get the following output from your indicator:

          key: 80 | BarsArray[0].Count: 1035 | BarsArray[1].Count: 207 | Times[1].Count - 1 - key: 126
          CurrentBars[1]: 40 | endI: 80
          Indicator 'FlipsTest': Error on calling 'OnBarUpdate' method on bar 205: 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.

          It is still failing on Line 89: Print(Times[1][endI]); Times[1].Count = 207 so endI should be valid between 0 and 206. endI is only 80 when the code is failing.

          Comment


            #20
            Hello habibalex,

            Thank you for including the output.

            The issue is that there are only 40 bars of the secondary series processed when this is called. (i.e. CurrentBars[1] is on bar 40)

            Look at the print you have provided.

            CurrentBars[1]: 40 | endI: 80

            The secondary series has only processed 40 bars (likely because this is a larger time frame than the primary series).

            However, you are calling the time of a bar on the secondary series 80 bars ago (endI).

            You cannot call a bar 80 bars ago when there are only 40 bars processed in that series.
            Last edited by NinjaTrader_ChelseaB; 12-30-2015, 08:31 AM.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by sidlercom80, 10-28-2023, 08:49 AM
            169 responses
            2,268 views
            0 likes
            Last Post QuantKey_Bruce  
            Started by Irukandji, Yesterday, 02:53 AM
            2 responses
            17 views
            0 likes
            Last Post Irukandji  
            Started by adeelshahzad, Today, 03:54 AM
            0 responses
            3 views
            0 likes
            Last Post adeelshahzad  
            Started by CortexZenUSA, Today, 12:53 AM
            0 responses
            3 views
            0 likes
            Last Post CortexZenUSA  
            Started by CortexZenUSA, Today, 12:46 AM
            0 responses
            1 view
            0 likes
            Last Post CortexZenUSA  
            Working...
            X