Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Index was out of range

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

    Index was out of range

    I code as follows, but nothing get ploted on the chart, and I got the message that" ...Default Error on calling the 'OnBarUpdate' method for indicator ... on bar 0: Index was out of range. Must be non-negative and less than the size of the collection.Parameter name: index" Any suggestion to fix this problem?


    if(High[0] == MAX(High,10)[0]){
    Plot0.Set(Close[10]);}
    else {Plot0.Set(0);}

    #2
    randomwalker, you likely run into this issue explained here -

    BertrandNinjaTrader Customer Service

    Comment


      #3
      I am pretty sure that on my chart there are more than 10 bars plotted. That is why I get confused.

      Comment


        #4
        That's not relevant, at the start of the chart you still try accessing a value from 10 bars back with your code, which will not work if you don't guard against it with the snippet provided.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Ok. I got it. It is pretty good explanation. Thanks Bertrand.
          Last edited by randomwalker; 06-15-2010, 08:46 AM.

          Comment


            #6
            random,

            Do this
            Code:
            if(CurrentBar < 10)
            return;
            
            if(High[0] == MAX(High,10)[0]){
                Plot0.Set(Close[10]);}
            else {Plot0.Set(0);}
            You should always check the log tab when things don't seem to be right. It will usually give you some info on the issue.
            mrlogik
            NinjaTrader Ecosystem Vendor - Purelogik Trading

            Comment


              #7
              Originally posted by mrlogik View Post
              random,

              Do this
              Code:
              if(CurrentBar < 10)
              return;
               
              if(High[0] == MAX(High,10)[0]){
                  Plot0.Set(Close[10]);}
              else {Plot0.Set(0);}
              You should always check the log tab when things don't seem to be right. It will usually give you some info on the issue.
              Thanks, mrlogik. I did exactly what you provided, and it works. Yes, I agree, log tab always gives helpful info. Previously, I missed that because I always minimize the ControlCenter.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by AaronKoRn, Today, 09:49 PM
              0 responses
              6 views
              0 likes
              Last Post AaronKoRn  
              Started by carnitron, Today, 08:42 PM
              0 responses
              9 views
              0 likes
              Last Post carnitron  
              Started by strategist007, Today, 07:51 PM
              0 responses
              10 views
              0 likes
              Last Post strategist007  
              Started by StockTrader88, 03-06-2021, 08:58 AM
              44 responses
              3,976 views
              3 likes
              Last Post jhudas88  
              Started by rbeckmann05, Today, 06:48 PM
              0 responses
              9 views
              0 likes
              Last Post rbeckmann05  
              Working...
              X