Announcement

Collapse
No announcement yet.

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.

    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.

          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 Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            566 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            330 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            547 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            548 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X