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 Segwin, 05-07-2018, 02:15 PM
            14 responses
            1,788 views
            0 likes
            Last Post aligator  
            Started by Jimmyk, 01-26-2018, 05:19 AM
            6 responses
            837 views
            0 likes
            Last Post emuns
            by emuns
             
            Started by jxs_xrj, 01-12-2020, 09:49 AM
            6 responses
            3,293 views
            1 like
            Last Post jgualdronc  
            Started by Touch-Ups, Today, 10:36 AM
            0 responses
            12 views
            0 likes
            Last Post Touch-Ups  
            Started by geddyisodin, 04-25-2024, 05:20 AM
            11 responses
            62 views
            0 likes
            Last Post halgo_boulder  
            Working...
            X