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 CaptainJack, 05-29-2026, 05:09 AM
      0 responses
      249 views
      0 likes
      Last Post CaptainJack  
      Started by CaptainJack, 05-29-2026, 12:02 AM
      0 responses
      161 views
      0 likes
      Last Post CaptainJack  
      Started by charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      165 views
      1 like
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      250 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      203 views
      0 likes
      Last Post CarlTrading  
      Working...
      X