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 Hwop38, 05-04-2026, 07:02 PM
      0 responses
      161 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Started by CaptainJack, 04-24-2026, 11:07 PM
      0 responses
      309 views
      0 likes
      Last Post CaptainJack  
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      245 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      349 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      179 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Working...
      X