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 bmartz, 03-12-2024, 06:12 AM
              4 responses
              32 views
              0 likes
              Last Post bmartz
              by bmartz
               
              Started by Aviram Y, Today, 05:29 AM
              4 responses
              12 views
              0 likes
              Last Post Aviram Y  
              Started by algospoke, 04-17-2024, 06:40 PM
              3 responses
              28 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by gentlebenthebear, Today, 01:30 AM
              1 response
              8 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by cls71, Today, 04:45 AM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Working...
              X