Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Accessing an Index out of range

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

    Accessing an Index out of range

    Here is the code I am trying to convert.

    if ((SMA(100) [0] < SMA(200) [0]) && (SMA(100) [0] > SMA(100) [1]) && (EMA(13) [0] > EMA(13) [1]))

    When I use [1] it works fine. But I want to compare with [5]

    As soon as I replace [1] with [5], then I get ....

    Error on calling OnBarUpdate method on bar 0. You are accessing an index with a value that is invalid since it is out-of-range

    How do I get passed this?

    I had the same problem with LinReg using CrossAbove and CrossBelow.

    #2
    Hello CheetaFish,

    Are you checking there is at least 5 bars?

    if (CurrentBar < 5)
    return;


    or

    if (CurrentBar > 5)
    {
    // execute code
    }
    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
    666 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    376 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    110 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    575 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    580 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X