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 terofs, Yesterday, 04:18 PM
              1 response
              21 views
              0 likes
              Last Post terofs
              by terofs
               
              Started by CommonWhale, Today, 09:55 AM
              1 response
              3 views
              0 likes
              Last Post NinjaTrader_Erick  
              Started by Gerik, Today, 09:40 AM
              2 responses
              7 views
              0 likes
              Last Post Gerik
              by Gerik
               
              Started by RookieTrader, Today, 09:37 AM
              2 responses
              13 views
              0 likes
              Last Post RookieTrader  
              Started by alifarahani, Today, 09:40 AM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Working...
              X