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 out-of-range'

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

    Error 'You are accessing an index with a value that is invalid out-of-range'

    Hey guys -

    I need some help troubleshooting an error that keeps popping up while my strategy is running real-time.

    Error on calling 'OnBarUpdate' method on bar 634: 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.

    From searching on here, it seems like this error would occur at the start of session since there may not be enough bars. I've had my strategy running since last night and there are hundreds of bars on the chart before it hit the error.

    Where should I look?

    #2
    Hello PN720,

    This error will be displayed if you try to use a BarsAgo when it is not valid. A more simple example using one series would be on bar 5 you check for 6 BarsAgo. There are not yet 6 bars so the CurrentBar minus 6 would be a negative number or a non-existent bar.

    This is likely the same case with your script except for the point when the error occurs is different. The series you are using may also be set up differently than my example. If you are using more than 1 series the error may display a bar that does not seem relevant or is a large number from the other series.

    One item which may come up that you can test before doing anything else is to check for enough data for all series.

    Code:
    if(CurrentBar < 10) return; // for a single series
    or
    if(CurrentBars[0] < 10 || CurrentBars[1] < 10) return; // for multi series
    These checks ensure there are 10 bars of data. Assuming you used 10 BarsAgo in your syntax this would be what is needed. You would replace the 10 with the highest number BarsAgo you have used in your logic.

    Alternatively, you would need to locate where in the script this is failing to do more targeted debugging with Prints. Locating the logic that is causing the error would allow you to place a Print before it. This would help understand what CurrentBar is processing and the other variables you may be using.


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

    Comment


      #3
      Hi Jesse,

      Thanks for the prompt response and info.

      I'm using a single data series (2000 tick chart) and already have this right after OnBarUpdate:

      if (CurrentBars[0] < BarsRequiredToTrade)
      return;

      Also, I looked at my script more closely and it looks like the highest bars ago I look for is 1. So, I'm either looking at [0] or [1]. And since the script had been running for hours successfully taking trades, I'm not sure how this would be a problem. Is it possible that one of the indicators being used the strategy is causing the problem? I noticed that when it hit the error, one of the indicators that I have on the strategy, the Ultimate Oscillator, was blank.

      Comment


        #4
        Hello PN720,

        Yes, it is possible one of the indicators is causing the problem, for example, if you used 1 BarsAgo on an indicator that supplies a non-continuous plot where it may have non-valid datapoints, you may see this message.

        In this case, if you are not using multiple series and already have a check that is greater than the BarsAgo being used you would likely need to further debug to find what line of code throws the error.

        If you know the general time you started the script, and the time of the error you may be able to recreate this using the playback connection. It sounds like the error may not be easily found by just enabling the script so you may need to run the script and test for a situation that generates the error before you continue to debug this further.

        You may also want to review the log/trace files around the time of the error to see if anything regarding a specific indicator is also listed around that time. If the indicator in question had thrown an error that may be another reason for the hosting script to fail. Depending on what indicators are used and how they are programmed can certainly affect the errors you see.

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

        Comment


          #5
          Hello.

          I am new on NinjaTrader so it's being hard to go foward since I'm dealing with errors all time. So I have the same issue.

          I just want to print every daily bar data (open, close, ask, bid, volume...) but when I'm on Bar.GetAsk(CurrentBar) I got this error:

          Error on calling 'OnBarUpdate' method on bar 20: 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'm using Kinetick - End of day (free)

          This is my very simple code:
          Click image for larger version

Name:	barerror.PNG
Views:	2014
Size:	20.2 KB
ID:	1160184

          What am I doing wrong?

          Thanks!

          Comment


            #6
            Hi Arbelio, thanks for your post.

            Kinetick does not provide historical bid/ask data on daily or minute bars. See this grid here on data you can get per provider:
            https://ninjatrader.com/support/help...y_provider.htm

            Best regards,
            -ChrisL
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Thanks Chris!!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by PaulMohn, Today, 05:00 AM
              0 responses
              8 views
              0 likes
              Last Post PaulMohn  
              Started by ZenCortexAuCost, Today, 04:24 AM
              0 responses
              6 views
              0 likes
              Last Post ZenCortexAuCost  
              Started by ZenCortexAuCost, Today, 04:22 AM
              0 responses
              3 views
              0 likes
              Last Post ZenCortexAuCost  
              Started by SantoshXX, Today, 03:09 AM
              0 responses
              17 views
              0 likes
              Last Post SantoshXX  
              Started by DanielTynera, Today, 01:14 AM
              0 responses
              5 views
              0 likes
              Last Post DanielTynera  
              Working...
              X