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 charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        67 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        150 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        162 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        99 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        287 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X