• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnMarketData error

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

    OnMarketData error

    I have an indicator which used OnMarketData which works fine most of the time, but sometimes when using the Market Replay data feed, I get the following error;

    Error on calling 'OnMarketData' method for indicator 'MyMarketDepth'. You are accessing an index with a value that is invalid since its out of range. IE accessing a series [barsago] with a value of 5 when there are only 4 bars on the chart.

    Apparently there are some gaps in some of the data. Once the error occurs, the indicator stops working until I open and close the indicator window. Is there a snipet of code I can add to tell the indicator to ignore the nonexistent data? I should add that this usually happens long after there are many bars in the chart.

    Here is the code I'm using;

    protectedoverridevoid OnMarketDepth(MarketDepthEventArgs e)
    {

    if (e.MarketDataType == MarketDataType.Ask)
    {
    Ask1 = e.MarketDepth.Ask[
    0].Volume;
    Ask2 = e.MarketDepth.Ask[
    1].Volume;
    Ask3 = e.MarketDepth.Ask[
    2].Volume;
    Ask4 = e.MarketDepth.Ask[
    3].Volume;
    Ask5 = e.MarketDepth.Ask[
    4].Volume;
    Ask6 = e.MarketDepth.Ask[
    5].Volume;
    }


    if (e.MarketDataType == MarketDataType.Bid)
    {
    Bid1 = e.MarketDepth.Bid[
    0].Volume;
    Bid2 = e.MarketDepth.Bid[
    1].Volume;
    Bid3 = e.MarketDepth.Bid[
    2].Volume;
    Bid4 = e.MarketDepth.Bid[
    3].Volume;
    Bid5 = e.MarketDepth.Bid[
    4].Volume;
    Bid6 = e.MarketDepth.Bid[
    5].Volume;
    }


    //Print(Close[0] + " " + "Bid3 = " + Bid3+ " Bid2 = " + Bid2 + " Bid1 = " + Bid1 + " Ask1 = " + Ask1 + " Ask2 = " + Ask2 + " Ask3 = " + Ask3);
    }
    protectedoverridevoid OnBarUpdate()
    {
    if(CurrentBar < BarsRequired)return;
    if (Historical)
    return;

    MyAsk.Set((Ask1 + Ask2 + Ask3 + Ask4 + Ask5 ) /
    5);
    MyBid.Set((Bid1 + Bid2 + Bid3 + Bid4 + Bid5) /
    5);
    }

    Safetrading

    #2
    Hello safetrading,

    Thank you for your post.

    So I may investigate this matter further please answer the following questions.

    Does this occur on all instruments in Market Replay? If not, what instrument or instrument(s) does this occur on?

    Was the data recorded from your real-time data or downloaded from the NinjaTrader servers?

    At what point in the replay does this occur? Any specific time in the session or day of month?

    I look forward to your response.
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      I only trade CL, so that is the only instrument I have used it with. My Replay data is recorded automatically when I'm streaming data from Zenfire. As to when this occurs, it is very spuratic, no visible patterns that I have noticed.

      Safetrading

      Comment


        #4
        Hello safetrading,

        Thank you for your response.

        Please run your test again on replay and determine a date that this occurs. Then download this date from the NinjaTrader servers by going to File > Utilities > Download Replay Data..

        Run the test again after downloading the data and advise if the same item occurs again for your code in Market Replay.
        Patrick H.NinjaTrader Customer Service

        Comment


          #5
          OK, will do after my trading day is over today

          Comment


            #6
            Originally posted by safetrading View Post
            I have an indicator which used OnMarketData which works fine most of the time, but sometimes when using the Market Replay data feed, I get the following error;

            Error on calling 'OnMarketData' method for indicator 'MyMarketDepth'. You are accessing an index with a value that is invalid since its out of range. IE accessing a series [barsago] with a value of 5 when there are only 4 bars on the chart.

            Apparently there are some gaps in some of the data. Once the error occurs, the indicator stops working until I open and close the indicator window. Is there a snipet of code I can add to tell the indicator to ignore the nonexistent data? I should add that this usually happens long after there are many bars in the chart.

            Here is the code I'm using;

            protectedoverridevoid OnMarketDepth(MarketDepthEventArgs e)
            {

            if (e.MarketDataType == MarketDataType.Ask)
            {
            Ask1 = e.MarketDepth.Ask[
            0].Volume;
            Ask2 = e.MarketDepth.Ask[
            1].Volume;
            Ask3 = e.MarketDepth.Ask[
            2].Volume;
            Ask4 = e.MarketDepth.Ask[
            3].Volume;
            Ask5 = e.MarketDepth.Ask[
            4].Volume;
            Ask6 = e.MarketDepth.Ask[
            5].Volume;
            }


            if (e.MarketDataType == MarketDataType.Bid)
            {
            Bid1 = e.MarketDepth.Bid[
            0].Volume;
            Bid2 = e.MarketDepth.Bid[
            1].Volume;
            Bid3 = e.MarketDepth.Bid[
            2].Volume;
            Bid4 = e.MarketDepth.Bid[
            3].Volume;
            Bid5 = e.MarketDepth.Bid[
            4].Volume;
            Bid6 = e.MarketDepth.Bid[
            5].Volume;
            }


            //Print(Close[0] + " " + "Bid3 = " + Bid3+ " Bid2 = " + Bid2 + " Bid1 = " + Bid1 + " Ask1 = " + Ask1 + " Ask2 = " + Ask2 + " Ask3 = " + Ask3);
            }
            protectedoverridevoid OnBarUpdate()
            {
            if(CurrentBar < BarsRequired)return;
            if (Historical)
            return;

            MyAsk.Set((Ask1 + Ask2 + Ask3 + Ask4 + Ask5 ) /
            5);
            MyBid.Set((Bid1 + Bid2 + Bid3 + Bid4 + Bid5) /
            5);
            }

            Safetrading
            Use try-catch blocks and trap the exception.

            ref: http://msdn.microsoft.com/en-us/libr...=vs.90%29.aspx

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by tonynt, Today, 12:39 PM
            0 responses
            8 views
            0 likes
            Last Post tonynt
            by tonynt
             
            Started by Martyb, 06-13-2019, 05:14 AM
            10 responses
            77 views
            0 likes
            Last Post iq200
            by iq200
             
            Started by Erwin Beckers, 11-04-2018, 02:39 AM
            4 responses
            71 views
            2 likes
            Last Post brucerobinson  
            Started by ntbone, Today, 01:25 AM
            0 responses
            6 views
            0 likes
            Last Post ntbone
            by ntbone
             
            Started by bomanpbm, Yesterday, 09:27 PM
            0 responses
            8 views
            0 likes
            Last Post bomanpbm  
            Working...
            X