Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnMarketDepth

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

    OnMarketDepth

    Hi,

    I am trying to add a Print statement to the code below (other Print statements are ok) within the OnMarketDepth method but I am getting an error. Error on calling 'OnMarketDepth' method for indicator 'CumulativeDepth': 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.

    Code:
    if (bidbookfilled==1 && askbookfilled==1)
                {
                    //Print("OnMarketDepth()");
                    //Print("Time : " + DateTime.Now.ToLongTimeString());
                    //Print("Cummulative Depth ASK is  " + sum1 + " " + Time[0]);
                    //Print("Cummulative Depth BID is  " + sum2 + " " + Time[0]);
                    Print(Time[0] + " " + sum2 + " Bids " + bidRows1[0].Volume + " | " + bidRows1[1].Volume + " | " + bidRows1[2].Volume + " | " + bidRows1[3].Volume + " | " + bidRows1[4].Volume);
                    Print(Time[0] + " " + sum1 + " Asks " + askRows1[0].Volume + " | " + askRows1[1].Volume + " | " + askRows1[2].Volume + " | " + askRows1[3].Volume + " | " + askRows1[4].Volume);
                    bidbookfilled=0;
                    askbookfilled=0;
                    //Print(Environment.NewLine);
                }
    Regards,
    suprsnipes

    #2
    suprsnipes, what kind of current bars check do you run in the OnBarUpdate section of the code?
    BertrandNinjaTrader Customer Service

    Comment


      #3
      I am using the following;

      Code:
      if (Close[0] > Close[Math.Min(CurrentBar, 1)]);

      Comment


        #4
        Please try increasing that to 4, any change?
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Ok, that fixed it, thanks.

          Comment


            #6
            Hi,

            I am having the same problem again where I am seeing this error message for no apparent reason.

            Error on calling 'OnMarketDepth' method for indicator 'CumulativeDepth': 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.

            I am using the following code but it's not resolving the issue, what other options do I have to stop this error messga from occuring?

            Regards,
            suprsnipes

            Comment


              #7
              suprsnipes, you could also wrap the code in try/catch statements - http://www.ninjatrader.com/support/f...ead.php?t=9825

              This would let the code continue to execute and offer potentially finer debug aids.
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Thanks Bertrand for your response I have not used the try catch method before. I have added the try catch method to the code and this was what was displayed in the output window when the error occured...

                System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
                Paramter name: Index
                at System.Collections.CollectionBase.System.Collectio ns.IList.get_Item(Int32 index)
                at NinjaTrader.Data.MarketDepthRowCollection.get_Item (int32 index)
                at NinjaTrader.Indicator.CumulativeDepth.OnMarketDept h(MarketDepthEventArgs e)

                What do I do from here?
                suprsnipes

                Comment


                  #9
                  suprsnipes, it tells you you're accessing an invalid index in your OnMarketDepth() handler - you would need to debug out where this is the case and address.
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    I'll look into how I can better use the try and catch to find out where the problem is, thanks.

                    Comment


                      #11
                      That would be good, also try running parts of it then and see in which section exactly the error is generated - if you would like I can give it a run here as well for you.

                      Just send me an email then please to support directly.
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by suprsnipes View Post
                        Thanks Bertrand for your response I have not used the try catch method before. I have added the try catch method to the code and this was what was displayed in the output window when the error occured...

                        System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
                        Paramter name: Index
                        at System.Collections.CollectionBase.System.Collectio ns.IList.get_Item(Int32 index)
                        at NinjaTrader.Data.MarketDepthRowCollection.get_Item (int32 index)
                        at NinjaTrader.Indicator.CumulativeDepth.OnMarketDept h(MarketDepthEventArgs e)

                        What do I do from here?
                        suprsnipes
                        This is the error message I see and I would like to know how the following piece of code could be throwing this error??

                        Code:
                                    maxAValue=1;
                                    maxAskSizeLevel=-1;
                                    for(int i=1; i<5; i++)
                                    {
                                    if (e.MarketDepth.Ask[i].Volume >= maxAValue)
                                    {    
                                    maxAValue = e.MarketDepth.Ask[i].Volume;
                                    maxAPrice = e.MarketDepth.Ask[i].Price;
                                    maxAskSizeLevel = i;
                                    }
                        I am really confused as to what may be causing this problem and would appreciate any help.

                        Regards,
                        suprsnipes

                        Comment


                          #13
                          Originally posted by suprsnipes View Post
                          I am using the following;

                          Code:
                          if (Close[0] > Close[Math.Min(CurrentBar, 1)]);
                          Increase to 5 or 6 now.

                          Comment


                            #14
                            Originally posted by suprsnipes View Post
                            This is the error message I see and I would like to know how the following piece of code could be throwing this error??

                            Code:
                                        maxAValue=1;
                                        maxAskSizeLevel=-1;
                                        for(int i=1; i<5; i++)
                                        {
                                        if (e.MarketDepth.Ask[i].Volume >= maxAValue)
                                        {    
                                        maxAValue = e.MarketDepth.Ask[i].Volume;
                                        maxAPrice = e.MarketDepth.Ask[i].Price;
                                        maxAskSizeLevel = i;
                                        }
                            I am really confused as to what may be causing this problem and would appreciate any help.

                            Regards,
                            suprsnipes
                            Might I suggest that if you are trying to use the positions in the MarketDepth ladder, that you use instead the supported, documented, e.Position?

                            ref: http://www.ninjatrader.com/support/h...heventargs.htm

                            Comment


                              #15
                              Thanks for your response.

                              Could you please give us an example of how I could use e.Position in place of what I am using at the moment?

                              Regards,
                              suprsnipes

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by glivv, Today, 09:17 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post glivv
                              by glivv
                               
                              Started by cmv727, Today, 08:48 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post cmv727
                              by cmv727
                               
                              Started by Kaiviti57, Today, 04:13 AM
                              2 responses
                              8 views
                              0 likes
                              Last Post bltdavid  
                              Started by aslane, Today, 08:02 AM
                              0 responses
                              7 views
                              0 likes
                              Last Post aslane
                              by aslane
                               
                              Started by DTSSTS, Today, 07:03 AM
                              0 responses
                              15 views
                              0 likes
                              Last Post DTSSTS
                              by DTSSTS
                               
                              Working...
                              X