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 on calling 'OnMarketData' method on bar -1

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

    Error on calling 'OnMarketData' method on bar -1

    A google search for this phrase did not reveal any posts in relation to OnMarketData, so I'm adding this...

    Error on calling 'OnMarketData' method on bar -1: 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.,

    Make sure the indicator's property "Calculate" is set to "On Every Tick"
    Attached Files

    #2
    Hello balltrader,

    Thanks for the post.

    Could you kindly copy/paste your OnMarketData method here? Likely, you will need to ensure that you are not referencing a bar that does not exist yet. For instance, if you try to reference Close[2] when CurrentBar is = 1 you will get this error.

    EX:

    Code:
    ... 
    if(CurrentBar < 2)
    return;
    
    double val = Close[2];
    ...
    I look forward to being of further assistance.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      my OMD method was empty, everything commented out, and no reference to any previous bars, yet the error persisted.

      I'm pretty sure in this case it was bcuz the indicator was already on the chart with it's calculation mode set to "on bar update", then I added some code for the OnMarketData event, and when it was trying to process tick replay of the data series, the first bar had not finished processing, and the bar index pointer was probably -1, and this error was thrown.

      this post is just a helper in case someone else has this scenario and can't find anything from a google search of the forums

      Comment


        #4
        I am receiving this error: bar out of valid range 0 through -1, was 0.

        But only when I am attempting to plot a dot: DrawDot("MyDot", false, 0, e.Position, Color.Blue);

        If I take that line out the code will continue to print to the output window.

        Comment


          #5
          Hello brucelevy,

          Thanks for the post.

          Have you added a CurrentBars check to make sure you have at least one bar on the chart before you draw?

          Code:
          if(CurrentBar < 1)
          return;
          I look forward to being of further assistiance.
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            @bruce,

            your code appears to be NT7, this is an NT8 forum

            read this post to see if this is what is happening when you try to plot a dot in the past on a bar that doesn't exist:

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Aviram Y, Today, 05:29 AM
            0 responses
            2 views
            0 likes
            Last Post Aviram Y  
            Started by quantismo, 04-17-2024, 05:13 PM
            3 responses
            25 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by ScottWalsh, 04-16-2024, 04:29 PM
            7 responses
            34 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by cls71, Today, 04:45 AM
            0 responses
            6 views
            0 likes
            Last Post cls71
            by cls71
             
            Started by mjairg, 07-20-2023, 11:57 PM
            3 responses
            217 views
            1 like
            Last Post PaulMohn  
            Working...
            X