Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

index out of range

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

    index out of range

    Hello,
    I'm creating a simple indicator that draws a diamond when the following conditions are true.
    if(Close[0] > VMAZones (9, 2, 18).Lower[0]
    && Close[0] < VMAZones (9, 2, 18).Upper[0]
    && ADX(10)[3] > 24
    && CrossBelow(DM(10).DiPlus, DM(10).DiMinus, 1))
    {
    DrawDiamond("Short" + CurrentBar, true, 0, High[0] + 1, Color.Red);
    }
    I get an error in the Log that says "Index was out of range. Must be non-negative and less than the size of the collection". I have no idea what that means. Can anyone help me out? Thanks.

    #2
    Hello CaptainAmericaXX,

    You are likley trying to access a value that is not in range of the context of the code.

    Please see the following forum post which will help explain the issue further and try the resolution as outlined in the post:



    It is most likley the ADX(10)[3] portion which is causing issues. You should make sure you're using a value of at least 3 for the currentbar

    The fix would be adding a similar snippet:

    if(CurrentBar < 3)
    return;
    MatthewNinjaTrader Product Management

    Comment


      #3
      That did it. Thank you for the explanation!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by kinfxhk, 07-14-2026, 09:39 AM
      0 responses
      125 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by kinfxhk, 07-13-2026, 10:18 AM
      0 responses
      105 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by kinfxhk, 07-13-2026, 09:50 AM
      0 responses
      84 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by kinfxhk, 07-13-2026, 07:21 AM
      0 responses
      104 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by kinfxhk, 07-11-2026, 02:11 AM
      0 responses
      83 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Working...
      X