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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      152 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      89 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      131 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      127 views
      1 like
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      107 views
      0 likes
      Last Post CarlTrading  
      Working...
      X