Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Invalid Index error

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

    Invalid Index error

    Hello,

    I'm getting this error on my strategy:

    "You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart."

    To avoid it I wrote this code on the beginning of the OnBarUpdate():

    if (CurrentBar < 10)
    return;

    But the error remains. It's a multiinstrument strategy. Perhaps I should use CurrentBars[0] ?


    thanks

    #2
    Correct guillembm, you would need to add a check for all bars objects in your script like - http://www.ninjatrader.com/support/h...ub=CurrentBars
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Unfortunately I still receive the same message. I changed the code to:

      if ((CurrentBars[0] < 10 || CurrentBars[1] < 10 || CurrentBars[2] < 10 || CurrentBars[3] < 10) && !Historical)
      {
      if (NoBarsWarned == false)
      {
      SendMail("[email protected]", "[email protected]", "NO BARS", "NO BARS");
      NoBarsWarned = true;

      }

      return;
      }

      And I receive the same message error. The funny thing is that I only receive this error around 3 in the morning (GMT + 1). I suppose it happens during a restart task or similar in IB. But I think this code should still work.

      thanks

      Comment


        #4
        guillembm, same outcome if you don't check for a hardcoded integer value, but the BarsRequired set?
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Originally posted by guillembm View Post
          Unfortunately I still receive the same message. I changed the code to:

          if ((CurrentBars[0] < 10 || CurrentBars[1] < 10 || CurrentBars[2] < 10 || CurrentBars[3] < 10) && !Historical)
          {
          if (NoBarsWarned == false)
          {
          SendMail("[email protected]", "[email protected]", "NO BARS", "NO BARS");
          NoBarsWarned = true;

          }

          return;
          }

          And I receive the same message error. The funny thing is that I only receive this error around 3 in the morning (GMT + 1). I suppose it happens during a restart task or similar in IB. But I think this code should still work.

          thanks
          You need to remove the highlighted condition and let is stand on its own: CurrentBars[x] are always historical, so your net condition will always be false, which is why the block is never entered.

          Comment


            #6
            Sorry, I don't understand your answer.

            Min. bars required is set to 20 on the strategy settings. Should I write it on Initialize()?

            On the help guide it says " In a multi-series strategy this restriction applies only for the primary Bars object"

            What if a secondary instrument is not receiving the appropriate number of bars?

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by algospoke, Yesterday, 06:40 PM
            2 responses
            23 views
            0 likes
            Last Post algospoke  
            Started by ghoul, Today, 06:02 PM
            3 responses
            14 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by jeronymite, 04-12-2024, 04:26 PM
            3 responses
            45 views
            0 likes
            Last Post jeronymite  
            Started by Barry Milan, Yesterday, 10:35 PM
            7 responses
            22 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by AttiM, 02-14-2024, 05:20 PM
            10 responses
            181 views
            0 likes
            Last Post jeronymite  
            Working...
            X