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 CaptainJack, 05-29-2026, 05:09 AM
    0 responses
    244 views
    0 likes
    Last Post CaptainJack  
    Started by CaptainJack, 05-29-2026, 12:02 AM
    0 responses
    157 views
    0 likes
    Last Post CaptainJack  
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    165 views
    1 like
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    250 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    200 views
    0 likes
    Last Post CarlTrading  
    Working...
    X