• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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 -

    http://www.ninjatrader.com/support/f...ead.php?t=3170
    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 U0000999, Yesterday, 11:49 PM
              1 response
              5 views
              0 likes
              Last Post NinjaTrader_ChrisSch  
              Started by Mberg, Today, 03:29 AM
              0 responses
              4 views
              0 likes
              Last Post Mberg
              by Mberg
               
              Started by TazoTodua, Today, 03:24 AM
              0 responses
              4 views
              0 likes
              Last Post TazoTodua  
              Started by ahadari28, Yesterday, 04:01 PM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_ChrisSch  
              Started by NinjaCustomer, Today, 12:14 AM
              1 response
              5 views
              0 likes
              Last Post NinjaTrader_Marco  
              Working...
              X