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 DannyP96, 05-18-2026, 02:38 PM
    1 response
    70 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    131 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    77 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    242 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    328 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X