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

error You are accessing an index with a value that is invalid since its out of range

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

    error You are accessing an index with a value that is invalid since its out of range

    System.Exception: 'MRO' on bar 0 threw exception: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
    at NinjaTrader.Indicator.IndicatorBase.MRO(Condition condition, Int32 instance, Int32 lookBackPeriod)
    at NinjaTrader.Indicator.Trending.OnBarUpdate()


    the code segment is here.

    i cannot think of a reason why i would get this exception.


    if(High[0]!=1)
    {
    if((High[0]>High[1] ) && (High[1]>High[2] ))
    {

    HigherHigh.Set(1);

    if(HigherHigh[1] != 1)
    {
    // check if this instance is greater than the last higher high
    int barsago=MRO(delegate {return HigherHigh[1] == 1;}, 2, 100);
    if(High[0]>High[ barsago])
    {
    higherhighBoolSeries.Set(true);

    }


    }



    }

    #2
    Hi junkone,

    Your MRO lookback period is 100, so consider adding something like this to prevent accessing bars at the start of the series:

    if (CurrentBar < 100) return;

    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      that makes no sense. i am running the strategy on a 1 minute bar and i can see data running into several hours backwards.
      100 bars =1 hour 40 minutes worth of data.

      something is definiltely wrong if i have to add a currentbar<100 filter.

      Comment


        #4
        You want it to prevent it accessing values that aren't there. Maybe modify with this if the first 100 bars are critical:

        if (CurrentBar < 2) return;

        int barsago=MRO(delegate {return HigherHigh[1] == 1;}, 2, Math.Min(CurrentBar + 1, 100));
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by junkone View Post
          System.Exception: 'MRO' on bar 0 threw exception: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
          at NinjaTrader.Indicator.IndicatorBase.MRO(Condition condition, Int32 instance, Int32 lookBackPeriod)
          at NinjaTrader.Indicator.Trending.OnBarUpdate()


          the code segment is here.

          i cannot think of a reason why i would get this exception.


          if(High[0]!=1)
          {
          if((High[0]>High[1] ) && (High[1]>High[2] ))
          {

          HigherHigh.Set(1);

          if(HigherHigh[1] != 1)
          {
          // check if this instance is greater than the last higher high
          int barsago=MRO(delegate {return HigherHigh[1] == 1;}, 2, 100);
          if(High[0]>High[ barsago])
          {
          higherhighBoolSeries.Set(true);

          }


          }



          }
          You cannot access High[2] until there are at least 3 bars on the chart. You want to use an escape condition:

          Code:
          if (CurrentBar < 2) return;
          before your code accessing the bars.

          Comment


            #6
            Originally posted by NinjaTrader_RyanM View Post
            Hi junkone,

            Your MRO lookback period is 100, so consider adding something like this to prevent accessing bars at the start of the series:

            if (CurrentBar < 100) return;

            http://www.ninjatrader.com/support/f...ead.php?t=3170
            Hi This is such a frequently reported problem as I searched the forum. Could this exception be systematically handled, so that we do not need to worry about this anymore?

            Comment


              #7
              Hello,

              I agree that this does come up quite often. I will add this as a feature request for development to review.

              I look forward to being of further assistance.
              JesseNinjaTrader Customer Service

              Comment


                #8
                BarsRequiredToTrade

                hellow, Ninjatrader Support"

                Hi, I'm encountering the usual problem that's been discussed over and over on this forum.

                it is the "Error on calling 'OnBarUpdate' method on bar 835: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart."

                I have a question.
                (1) when running a strategy, when does the strategy start calculating the indicator values? Does i have anything to do with the "BarsRequiredToTrade" value?

                (2) suppose I have an indicator that would only start calculating when (A) the 2nd NewTradingDay has started, and (B) I only want to trust the indicator values from the 3rd NewTradingDay onwards, what should I do with the "BarsRequiredToTrade", and "if (CurrentBar < 100) return" ?

                Sorry for asking this question but I get the same error as above. "5" and "4" every time, whether I change any of the properties.

                Would appreciate your advice.

                Comment


                  #9
                  Hello hana_maui,

                  Thanks for reaching out.

                  This thread is rather old. In the future, could you open a new thread instead of bumping the older thread? It helps us to make sure the thread gets proper attention and helps keep the forum organized. We're happy to help nonetheless.

                  (1) when running a strategy, when does the strategy start calculating the indicator values? Does i have anything to do with the "BarsRequiredToTrade" value?
                  For indicators added to the strategy, the strategy will start calculating indicator values for each bar iteration of the data series that the indicator uses in the strategy. Essentially, bar by bar, as each bar becomes available.

                  For indicator calculations that exist in OnBarUpdate() alone and are not "added" to the strategy, these will get calculated whenever they are called.

                  BarsRequiredToTrade will only tell the strategy when it is allowed to start placing trades. It does not control what gets calculated in the strategy.

                  (2) suppose I have an indicator that would only start calculating when (A) the 2nd NewTradingDay has started, and (B) I only want to trust the indicator values from the 3rd NewTradingDay onwards, what should I do with the "BarsRequiredToTrade", and "if (CurrentBar < 100) return" ?
                  I don't know if the indicator is using the primary data series or a secondary series. If it using a secondary series, you could calculate how many bars that data series would need before the indicator would have usable data. The same approach can be done for the primary series, but you would have to look at the BarsPeriod of the primary series so you can calculate the number of bars needed accurately.

                  I would instead set up the strategy logic so it waits for when your indicator would start giving usable data using a SessionIterator or by checking Bars.Session.GetNextBeginEnd before it starts calculating off that indicator.

                  I'll include some publicly available documentation on the items discussed and some tips for troubleshooting indexing errors like you are receiving.

                  Multi-Series NinjaScripts (Important read) (NT8) - https://ninjatrader.com/support/help...nstruments.htm
                  Multi-Series NinjaScripts (Important read) (NT7) - https://ninjatrader.com/support/help...nstruments.htm

                  BarsPeriod (NT8) - https://ninjatrader.com/support/help...barsperiod.htm
                  BarsPeriod (NT7) - https://ninjatrader.com/support/help...barsperiod.htm

                  SessionIterator (NT8) - https://ninjatrader.com/support/help...oniterator.htm
                  Bars.Session.GetNextBeginEnd (NT7) - https://ninjatrader.com/support/help...xtbeginend.htm

                  Forum tips for debugging and troubleshooting NinjaScipt Development - https://ninjatrader.com/support/foru...splay.php?f=31

                  Please let me know if I may be of further assistance.
                  JimNinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_Jesse View Post
                    Hello,

                    I agree that this does come up quite often. I will add this as a feature request for development to review.

                    I look forward to being of further assistance.
                    Hi Jessie,

                    I also agree, but your post is almost 1.5 years old. When is your development going to mind your request?

                    From the frequency of this issue being raised, it appears it would save NT hundreds of resource hours just responding to a silly issue that can be handled internally. As I recall, NT7 never had this issue. This error happens most often when a MAX() or MIN() statement is used. Something is not kosher there.

                    Keep requesting!

                    Comment


                      #11
                      Hello aligator,

                      I have added a vote to the feature request SFT-523 on your behalf.

                      Keep in mind that fulfilling this request would change NinjaTrader's behavior so that programming errors will not be easily observed and NinjaTrader would then hide these errors. This would make for a more confusing experience to the user who wouldn't know why their NinjaScript isn't working.

                      As with other feature requests, we cannot present an ETA as they are fulfilled based on the development team's schedule and priorities. Upon implementation the ticket ID can be found publicly on the Release Notes page of the help guide. I'll provide a link below.

                      Release Notes: https://ninjatrader.com/support/help...ease_notes.htm

                      Please let us know if we can be of further assistance.
                      JimNinjaTrader Customer Service

                      Comment


                        #12
                        Thanks, Jim

                        Originally posted by NinjaTrader_Jim View Post
                        Hello aligator,

                        I have added a vote to the feature request SFT-523 on your behalf.

                        I don't think you need a member vote. Just do a search for "You are accessing an index with a value that is invalid since its out of range" error, then count the number of returned posts. That should be enough.

                        Keep in mind that fulfilling this request would change NinjaTrader's behavior so that programming errors will not be easily observed and NinjaTrader would then hide these errors. This would make for a more confusing experience to the user who wouldn't know why their NinjaScript isn't working.

                        The idea is not to change programming to remove the "Errors" notifications, but to fix the code to simply correct the indexing logic to behave perhaps similar to NT7 that does not have this issue.

                        As with other feature requests, we cannot present an ETA as they are fulfilled based on the development team's schedule and priorities. Upon implementation the ticket ID can be found publicly on the Release Notes page of the help guide. I'll provide a link below.

                        Release Notes: https://ninjatrader.com/support/help...ease_notes.htm

                        Please let us know if we can be of further assistance.
                        Cheers!

                        Comment


                          #13
                          Hello aligator,

                          Indexing issues have been an issue in NinjaTrader 7 and NinjaTrader 8.

                          The behavior is intended to match NinjaTrader 7. Could you provide an example where NinjaTrader 8 encounters an issue but NinjaTrader 7 does not? We would definitely like to provide further input or address the issue appropriately.
                          JimNinjaTrader Customer Service

                          Comment


                            #14
                            Dear Jim,

                            Thanks for the advice.
                            I'll try using "SessionIterator or by checking Bars.Session.GetNextBeginEnd".

                            Best regards,
                            Hana

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by alifarahani, Today, 09:40 AM
                            3 responses
                            15 views
                            0 likes
                            Last Post NinjaTrader_Jesse  
                            Started by RookieTrader, Today, 09:37 AM
                            4 responses
                            18 views
                            0 likes
                            Last Post RookieTrader  
                            Started by PaulMohn, Today, 12:36 PM
                            0 responses
                            5 views
                            0 likes
                            Last Post PaulMohn  
                            Started by love2code2trade, 04-17-2024, 01:45 PM
                            4 responses
                            40 views
                            0 likes
                            Last Post love2code2trade  
                            Started by junkone, Today, 11:37 AM
                            3 responses
                            26 views
                            0 likes
                            Last Post NinjaTrader_ChelseaB  
                            Working...
                            X