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 carnitron, Today, 08:42 PM
    0 responses
    6 views
    0 likes
    Last Post carnitron  
    Started by strategist007, Today, 07:51 PM
    0 responses
    8 views
    0 likes
    Last Post strategist007  
    Started by StockTrader88, 03-06-2021, 08:58 AM
    44 responses
    3,974 views
    3 likes
    Last Post jhudas88  
    Started by rbeckmann05, Today, 06:48 PM
    0 responses
    9 views
    0 likes
    Last Post rbeckmann05  
    Started by rhyminkevin, Today, 04:58 PM
    4 responses
    58 views
    0 likes
    Last Post dp8282
    by dp8282
     
    Working...
    X