Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Indicator bars error "index was out of bounds of the array"

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

    #16
    Originally posted by CSharpTrader View Post
    Hi Koganam, I am... it's logically the same as Joydeeps' earlier suggestion, that just checked them both individually with the ||.
    In that case, you will need some Print() statements to isolate the line that is causing the error.

    Here is the method that I use: ref: this post http://www.ninjatrader.com/support/f...gun#post245553 in this thread: http://www.ninjatrader.com/support/f...gun#post245458, which unsurprisingly is about that exact error.

    Comment


      #17
      I have visual studio... I'll turn there first, as annoying it can be to try to debug live indicators. I'm hoping Joydeep has additional insight, too. Print statements.... 80's debugging, the horror!! Thanks though.

      Comment


        #18
        Originally posted by CSharpTrader View Post
        I have visual studio... I'll turn there first, as annoying it can be to try to debug live indicators. I'm hoping Joydeep has additional insight, too. Print statements.... 80's debugging, the horror!! Thanks though.
        I also use an IDE for final debugging. The shotgun Print() method simply shows me where to focus, instead of having multiple breakpoints to work through. I agree that it at first felt like stone age debugging, but I found that it saves me a whole lot of time, and allows me quick, laser-like focus. YMMV.

        Comment


          #19
          Joydeep, Koganam... I've got the error line.

          3rd line down after if (BarsInProgress==0):

          double keyPriceViolationLevelPriorDay = EMA(Closes[1],slowMA)[0]*1.0025;

          Hope this helps. It's more specific but I'm still at a loss..

          Comment


            #20
            Originally posted by CSharpTrader View Post
            Joydeep, Koganam... I've got the error line.

            3rd line down after if (BarsInProgress==0):

            double keyPriceViolationLevelPriorDay = EMA(Closes[1],slowMA)[0]*1.0025;

            Hope this helps. It's more specific but I'm still at a loss..
            That is a different kettle of fish.

            You are trying to access BarsArray[1] (i.e., Closes[1])from a tick triggered in BarsArray[0] (i.e., BarsInProgress 0). You may simply not have enough bars in BarsArray[1] at the time of access. You may want to double check the value of BarsArray[1] at the time of the access.

            Comment


              #21
              Btw I had been struggling to get it sync'd with VS2010 the whole time, thanks for the patience..

              Comment


                #22
                I thought that's what the original check CurrentBars[1] < slowMA + 12 addressed... don't we have enough bars if that returns true?

                Comment


                  #23
                  Originally posted by CSharpTrader View Post
                  I thought that's what the original check CurrentBars[1] < slowMA + 12 addressed... don't we have enough bars if that returns true?
                  At first blush, yes, but you think that you have isolated the problem to that particular line, and you are getting a very specific error which seems to imply a certain explanation. If you care to post the entire code, I am willing to give it a run in my environment. You might also try restarting NT, just to be sure that you are not running into a .NET snafu.

                  I do not mean to be patronizing, but I have made this mistake so often myself, that I sometimes just ask to make sure: "Are you sure that you recompiled after you made the edit?"

                  Comment


                    #24
                    No problem. Here it is in the latest form, below. Yup, recompiled (I too tend to make mistakes that are more absent- minded than higher- level). I attached the process to visual studio debug, and that line was the one that threw the out of bounds index error (despite passing the test in the initial check for # bars). I'll restart now per your suggestion. Fingers crossed. Thanks again.

                    Code:
                    protected override void OnBarUpdate()
                            {
                                for (int index = 0; index < BarsArray.Length; index++) 
                                {
                                    if (CurrentBars[index] < (slowMA+12)) return;
                                }
                                
                                
                                if(BarsInProgress==0)
                                {
                                    //Check for uptrend
                                    int uptrendCheckCount = 0;
                                    int countOfClosesOverSlowEma = 0;
                                    double keyPriceViolationLevelPriorDay = EMA(Closes[1],slowMA)[0]*1.0025;
                                    double keyPriceViolationLevelToday = EMA(Closes[1],slowMA)[0] + Math.Abs(EMA(Closes[1],slowMA)[0] - EMA(Closes[1],slowMA)[1]);
                                    
                                    for(int i=0;i<10;i++)
                                    {
                                        if((EMA(Closes[1],fastMA)[i] >= EMA(Closes[1],medMA)[i]) && (EMA(Closes[1],medMA)[i] >= EMA(Closes[1],slowMA)[i]))
                                        {
                                            uptrendCheckCount++;
                                        }
                                        
                                        if(Closes[1][i+1] >= EMA(Closes[1],slowMA)[i+1])
                                        {
                                            countOfClosesOverSlowEma++;
                                        }
                                    }
                                    
                                    if((countOfClosesOverSlowEma==10)&&(uptrendCheckCount==10))
                                    {
                                        if(Lows[1][0] <= keyPriceViolationLevelPriorDay)
                                        {
                                            if((Close[0] > Open[0])&&(Close[0] > keyPriceViolationLevelToday))
                                            {
                                                Plot0.Set(1);
                                            }
                                        }
                                    }
                                }
                            }

                    Comment


                      #25
                      Originally posted by CSharpTrader View Post
                      No problem. Here it is in the latest form, below. Yup, recompiled (I too tend to make mistakes that are more absent- minded than higher- level). I attached the process to visual studio debug, and that line was the one that threw the out of bounds index error (despite passing the test in the initial check for # bars). I'll restart now per your suggestion. Fingers crossed. Thanks again.

                      Code:
                      protected override void OnBarUpdate()
                              {
                                  for (int index = 0; index < BarsArray.Length; index++) 
                                  {
                                      if (CurrentBars[index] < (slowMA+12)) return;
                                  }
                       
                       
                                  if(BarsInProgress==0)
                                  {
                                      //Check for uptrend
                                      int uptrendCheckCount = 0;
                                      int countOfClosesOverSlowEma = 0;
                                      double keyPriceViolationLevelPriorDay = EMA(Closes[1],slowMA)[0]*1.0025;
                                      double keyPriceViolationLevelToday = EMA(Closes[1],slowMA)[0] + Math.Abs(EMA(Closes[1],slowMA)[0] - EMA(Closes[1],slowMA)[1]);
                       
                                      for(int i=0;i<10;i++)
                                      {
                                          if((EMA(Closes[1],fastMA)[i] >= EMA(Closes[1],medMA)[i]) && (EMA(Closes[1],medMA)[i] >= EMA(Closes[1],slowMA)[i]))
                                          {
                                              uptrendCheckCount++;
                                          }
                       
                                          if(Closes[1][i+1] >= EMA(Closes[1],slowMA)[i+1])
                                          {
                                              countOfClosesOverSlowEma++;
                                          }
                                      }
                       
                                      if((countOfClosesOverSlowEma==10)&&(uptrendCheckCount==10))
                                      {
                                          if(Lows[1][0] <= keyPriceViolationLevelPriorDay)
                                          {
                                              if((Close[0] > Open[0])&&(Close[0] > keyPriceViolationLevelToday))
                                              {
                                                  Plot0.Set(1);
                                              }
                                          }
                                      }
                                  }
                              }
                      Not enough information. What other barSeries have you added, and with what parameters? You are referencing Closes[1]. Where did you define the additional barSeries?

                      Comment


                        #26
                        *Gulp* It's me. As per my earlier comment on stupid mistakes (aren't they all?) I didn't have the 2nd data series added in the initialize method. Sorry. I had developed this as a strategy first, and just copied over OnBarUpdate(). Big waste of time.

                        We're running now, with a nice new issue. Getting alerts in the alerts window that don't match my conditions expressed in the code. The Plot0.Set(1) has a breakpoint, and the instrument that hits it doesn't generate an alert, but matches my conditions, and the one that does generate an alert, doesn't match the conditions, nor does it hit the breakpoint. Glad I love writing code.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by cre8able, Yesterday, 07:24 PM
                        1 response
                        13 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by cocoescala, 10-12-2018, 11:02 PM
                        6 responses
                        939 views
                        0 likes
                        Last Post Jquiroz1975  
                        Started by gbourque, Today, 06:39 AM
                        1 response
                        4 views
                        0 likes
                        Last Post NinjaTrader_Erick  
                        Started by cmtjoancolmenero, Yesterday, 03:58 PM
                        1 response
                        17 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Started by benmarkal, Yesterday, 12:52 PM
                        3 responses
                        23 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Working...
                        X