Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

out of range

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

    out of range

    Hello,

    when there appears in the log tab the message "5/3/2016 11:22:54 AM Strategy Error on calling 'OnBarUpdate' method for strategy 'a1xWnew/271b9005ace94801b857c51c1ba907d5': 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.

    and I can´t locate the problem I want to ask if an issue as described in the message can be avoided with
    if (Historical) return;
    So, even when in the code I´m referring eg to High[3] that is not there when enabling there shouldnt be an error-message then with if(Historical9 retunr; Correct?

    Thank you
    Tony

    #2
    Hello,

    The error you are receiving is related to using an index that does not exist when you use it. As the error describes, an example is if you are trying to get a value of 5 bars ago when you only have 4 bars loaded.

    Setting if (Historical) return; may resolve it, it may not, it would depend on the context of what is causing the error to start with.

    I would not suggest adding if (Historical) return; to fix the error, instead I would suggest that you further debug the script to identify the actual problem.

    You likely would need to reduce the code to find the error, there would be nothing I could say to point you to what it is specifically causing the error. I can suggest refining what syntax is causing the error by commenting out code until the error goes away. Once you locate where the error is no longer present, you can un comment code and move forward until you locate the specific problem.

    Once you locate what specifically is causing the error, as an example if it was the use of High[3], you could simply check if you have 3 bars before starting instead of omitting all historical data unless that is what you want to do.

    if(CurrentBar < 3) return;


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

    Comment


      #3
      Hello Jesse,

      thank you for your reply.

      Please just let me know if - disregarding any other conditions - a High[3] would cause this message when enabling with if(BarsInProgess=0) return; (as High[3] is not there when enabling, no?)

      Or would this not cause this message with High[3] (as it is basic dataseries) and maybe a condition Highs[2][3] from added dataseries would cause the message.

      This understanding would help me already (and has nothing to do with any coding of mine)

      Thank you
      Tony

      Comment


        #4
        Hello,

        Any of what you listed could cause this.

        High[3] could:

        Bar 0: High[3] would equal -3 which is not an index.
        Bar 1: High[3] would equal -2 which is not an index.
        Bar 2: High[3] would equal -1 which is not an index.
        Bar 3: High[3] would equal 0 which is an index.

        When accessed from a secondary BarsInProgress, the same concept applies, mainly is there 3 bars in the DataSeries so you can subtract 3 bars or 3 barsAgo.

        This is amplified with secondary series values, if you are using a secondary series you would need to ensure that series also has enough bars:

        if(CurrentBars[0] > 3 && CurrentBars[1] > 3)

        This would say if the Primary Current bar is greater than 3 and also the Secondary bars CurrentBar is greater than 3.

        It would really depend on the context and logic used on what specifically is happening in your code, again the best solution is generally to reduce the code to find what specifically is the cause.

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

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by ScottWalsh, Today, 04:52 PM
        0 responses
        1 view
        0 likes
        Last Post ScottWalsh  
        Started by ScottWalsh, Today, 04:29 PM
        0 responses
        5 views
        0 likes
        Last Post ScottWalsh  
        Started by rtwave, 04-12-2024, 09:30 AM
        2 responses
        22 views
        0 likes
        Last Post rtwave
        by rtwave
         
        Started by tsantospinto, 04-12-2024, 07:04 PM
        5 responses
        70 views
        0 likes
        Last Post tsantospinto  
        Started by cre8able, Today, 03:20 PM
        0 responses
        7 views
        0 likes
        Last Post cre8able  
        Working...
        X