Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

"accessing an index with a value that is invalid" question

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

    "accessing an index with a value that is invalid" question

    Hello,
    I have an indicator called RMI that I've been using for years without an issue. A few days ago I got the error message "You are accessing an index with a value that is invalid since it's out of range. I did not change any of the source code to cause the error.
    The message said this was happening on bar 17. I opened the code and found this block:
    Code:
    private int                                period    = 14;
    private int                                shift    = 3;
    if (CurrentBar < (Period + Shift)) 
       {
          return;
       }
    Since this was happening on bar 17 I changed the code to:
    Code:
    if (CurrentBar < (Period + (Shift + 1))) 
       {
          return;
       }
    Now everything is working again. Can someone give me an idea why this indicator would suddenly stop working for this reason?

    #2
    Hello CaptainAmericaXX,

    This would depend on the object that had the indexing error.

    For example, calling Close[1] on the very first bar will cause this error.

    The reason for this is because there will not be a bar ago, essentially there is not enough data at bar 0 to calculate to look a bar ago.

    The script will start from the far left of the chart at the very beginning where the CurrentBar will equal 0 and then start working to the right, calling each bar for OnBarUpdate();

    What you would nee to do instead is wait for after the first bar to be built from both data series and then run your if check for closes, to ensure that you have enough data.


    This may not be the exact issue and is just an example, as the error in your script will depend on what index is being used and on what object. (you can print the .Count and see what the count is of the object)
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    576 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    334 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    553 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    551 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X