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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    42 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    50 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    31 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    91 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    54 views
    0 likes
    Last Post PaulMohn  
    Working...
    X