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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      576 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      334 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      553 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      551 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X