Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bars indices out of range

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

    Bars indices out of range

    Hello!
    is there here in Ninjatrader away to solve such problem?
    I am building a strategy, but I am facing a problem while compiling the code. I am reciving the message like: " Error on calling 'OnBarUpdate' method on bar 14: 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."

    I have the following code:

    HTML Code:
    if(CurrentBar < 14) return;
    for(int i = 14; i >= 0; i--)
    {
        double  myRsi = RSI(14, 3)[i+8];
    }
    When I have: if(CurrentBar < 0) return;, I received the error message already for the bar 0;

    In my code, when i = 14,
    HTML Code:
     myRsi = RSI(14, 3)[14+8]
    ,
    what ist already beyong the 14 I have in my loop.

    How could I solve this problem since I am frequently encountering such problems in my codes? Which condition could be suitable in this case so that I could have the value of myRsi at position 14+8 for example?

    #2
    if (CurrentBar < 14+8) return;

    Comment


      #3
      Thanks Bldavid for your reply.

      Sorry for the post before this correction. Yes it works.
      Many thanks!!!
      Last edited by Stanfillirenfro; 07-26-2021, 07:09 AM.

      Comment


        #4
        Hello Stanfillirenfro,

        Thanks for your post.

        bltdavid is correct. You would need to ensure that there are enough bars loaded on the chart for the data being processed. For example, if you want to call the RSI with a barsAgo value of 14 + 8 (22), then you would need to use a CurrentBar check to see if 22 bars have loaded. ( ex: if (CurrentBar < 22) return; )

        See this help guide page for more information: https://ninjatrader.com/support/help...nough_bars.htm

        Let us know if we may assist further.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        601 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        347 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        559 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        558 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X