Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 alifarahani, Today, 09:40 AM
    6 responses
    39 views
    0 likes
    Last Post alifarahani  
    Started by Waxavi, Today, 02:10 AM
    1 response
    18 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Started by Kaledus, Today, 01:29 PM
    5 responses
    15 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by Waxavi, Today, 02:00 AM
    1 response
    12 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Started by gentlebenthebear, Today, 01:30 AM
    3 responses
    17 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X