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

Level 2 Market replay bug

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

    Level 2 Market replay bug

    Hello

    I use two different methods to populate Level 2 data.

    1st one is based on MarketDepthEventArgs.Operation processing.
    It works good and shows correct Level 2 ladder.

    2nd method is based on MarketDepthEventArgs.Instrument.MarketDepth.Asks/Bids. It works very bad sometimes. As you can see built-in NT Level II window also displays wrong data.

    Those both related to Market replay. Did not test enought this on live data.
    Attached Files

    #2
    Hello ren37,

    Below is a link to an example of working with level 2 data in OnMarketDepth().


    Currently, I am modifying this script to resolve an error when updating. I will update this thread once I have corrected this.

    Are you wanting to report a bug with the Level II window?
    How are you determining the the values in the Level II window are incorrect?
    Are you comparing this with NinjaTrader 7?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello

      Yes, the script by the link is not correct and throws errors when Position >= rows.Count on Insert or Update operations.

      My Insert operation handle:

      PHP Code:
                      
      ...
                      if (
      e.Operation == OrderBookOperation.Insert)
                      {
                          
      // Add a new row at the end if the designated position is greater than our current ladder size
                          
      if (e.Position >= __rows.Count)
                              
      __rows.Add(new OrderBookPosition(e.Pricee.Volumee.MarketMaker));

                          
      // Insert a new row into our ladder at the designated position
                          
      else
                              
      __rows.Insert(e.Position, new OrderBookPosition(e.Pricee.Volumee.MarketMaker));

                          
      __price2volume[e.Price] = GetVolumeFromList(e.Pricee.Side);
                          
      r.Price e.Price;
                      } 

      Yes, this is a bug.
      I use my algo based on your example but fixed. My Level II updates all desired levels (14 on the screen) while NT Level 2 shows only 1-3 levels at bid side.
      Last edited by ren37; 04-02-2017, 02:48 PM.

      Comment


        #4
        Hello ren37,

        I've corrected the SampleLevel2Book reference sample indicator.



        Please re-download and re-import this and test for the behavior.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello ren37,

          I've corrected the SampleLevel2Book reference sample indicator.



          Please re-download and re-import this and test for the behavior.
          Still contains bugs

          PHP Code:
                      else if (e.Operation == Operation.Update)
                          {
                              if (
          rows[e.Position] == null// is always false or throws out of range exception if e.Position == rows.Count
                              
          {
                                  
          rows[e.Position] = row;
                              }
                              else
                              {
                                  
          rows[e.Position].MarketMaker    e.MarketMaker;
                                  
          rows[e.Position].Price            e.Price;
                                  
          rows[e.Position].Volume            e.Volume;
                              }
                          } 
          I use this safe algo on Update

          PHP Code:
                  public MarketDepthResult OnMarketDepth(OrderBookEventArgs e)
                  {
                      
          MarketDepthResult r = new MarketDepthResult() { Result falsePrice e.Price };

                          ...
                          
          // Update
                          
          if (e.Operation == OrderBookOperation.Update)
                          {
                              
          long vol;
                              if (
          e.Position __rows.Count)
                              {
                                  
          __rows[e.Position].MarketMaker e.MarketMaker;
                                  
          __rows[e.Position].Price e.Price;
                                  
          __rows[e.Position].Volume e.Volume;
                                  
          vol GetVolumeFromList(e.Pricee.Side);
                              }
                              else
                              if (
          e.Position == __rows.Count)
                              {
                                  
          __rows.Add(new OrderBookPosition(e.Pricee.Volumee.MarketMaker));
                                  
          vol GetVolumeFromList(e.Pricee.Side);
                              }
                              else
                              {
                                  
          vol e.Volume GetVolumeFromList(e.Pricee.Side);
                              }

                              
          __price2volume[e.Price] = vol;
                          } 
          Here I also collect volume for the market depth event price for using in the indicator
          OrderBookEventArgs and OrderBookOperation is my platform independent types.
          r is function returned value.
          Last edited by ren37; 04-05-2017, 02:31 PM.

          Comment


            #6
            But what about bugs with MarketDepthEventArgs.Instrument.MarketDepth.Asks/Bids?
            My initial question related with that issue.

            Do you confirm the bug?
            Have you translated this to platform developers? What they said?

            Comment


              #7
              Hello ren37,

              Can you supply the error message you received while testing the updated version of the SampleLevel2Book reference sample?

              Further, I have not experienced a bug with MarketDepthEventArgs.Instrument.MarketDepth.Asks or Bid.

              To report an issue I will a reduced script that is able to produce the error.
              (This would not contain any logic but would just be a demonstration script with only the bare minimum code to reproduce the error)
              Do you have a simple reduced script without complicated logic that can produce the error?

              Are you wanting to report a bug with the Level II window?
              How are you determining the the values in the Level II window are incorrect?
              Are you comparing this with NinjaTrader 7?
              Last edited by NinjaTrader_ChelseaB; 04-05-2017, 02:47 PM.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                I have 20+ years of experiance and don't need to run code to found if it has a bug. And with some data feeds like iqfeed for stock market you will see it. But I really dont care on reference samples. But unfixed known bugs in API are noncence.
                Answers on most of your questions are in my prior posts.
                I think it's not my duty to proof a bug presence. Have a lot of work, sorry. I'v just reported it.
                If you not interesred in bug fixing what can I do? It's not my job.

                Comment


                  #9
                  Thank you for your report ren37. To make sure we are on the same page, am I correct in that what you are reporting is

                  • MarketDepthEventArgs.MarketDataType, MarketDepthEventArgs.Operation, and MarketDepthEventArgs.Price are displaying correct information we can compare against
                  • MarketDepthEventArgs.Instrument contains incorrect Ask/Bid price values
                  • The information in the level 2 window is similarly incorrect
                  • What makes this information incorrect is that it is displaying 1-3 levels on e.g. the Ask side when e.g. 14 are expected

                  If the above is correct, MarketDepthEventArgs.Instrument does not contain a documented MarketDepth member. MarketDepthEventArgs.Instrument.MarketDepth.Asks/Bids either do not exist, or are not documented. While your report is appreciated, without complete information that correlates with the documentation, we will not be able to investigate this part of your report. The operation of undocumented functionality can not be guaranteed or supported by us.


                  For reference, the documentation for MarketDepthEventArgs is here,





                  And the documentation for Instrument is here,






                  I will be testing the level 2 window against the information inside MarketDepthEventArgs and will return with my findings.
                  Last edited by NinjaTrader_JessicaP; 04-07-2017, 07:39 AM.
                  Jessica P.NinjaTrader Customer Service

                  Comment


                    #10
                    I have some more information.

                    The attached script has a self-check unit test suite for correctness. This is the canonical representation from OnMarketDepth that will be tested against. If you see any problems with the correctness of this script they will need to be demonstrated with a test inside the TestCRUD method that does not access askRows or bidRows except through the CRUD I/O methods. Otherwise, this script is to be considered correct, so that we can have a falsifiable test to compare to. This is being provided for your information only.

                    I am currently writing a similar script which captures the output of the Level 2 window in an add-on and will return shortly.
                    Attached Files
                    Last edited by NinjaTrader_JessicaP; 04-07-2017, 11:38 AM.
                    Jessica P.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello

                      Originally posted by NinjaTrader_JessicaP View Post
                      Thank you for your report ren37. To make sure we are on the same page, am I correct in that what you are reporting is

                      [LIST][*]MarketDepthEventArgs.MarketDataType, MarketDepthEventArgs.Operation, and MarketDepthEventArgs.Price are displaying correct information we can compare against[*]MarketDepthEventArgs.Instrument contains incorrect Ask/Bid price values[*]The information in the level 2 window is similarly incorrect[*]What makes this information incorrect is that it is displaying 1-3 levels on e.g. the Ask side when e.g. 14 are expected
                      Yes, this is correct.There is some bug inside
                      MarketDepthEventArgs.Instrument.MarketDepth.Asks/Bids collections. Of course we can avoid this (especially if those collections are not documented) by using MarketDepthEventArgs.Operation and etc. data. So forget about this if you want.
                      BUT. Level II in NT UI is not correct! Look again at screen shot in my first post.
                      What I think is that platfor developers should check this but not support personel. Agree?
                      Had you told?
                      Still not get "bug confirmed" message. What are you waiting for?

                      Comment


                        #12
                        Originally posted by NinjaTrader_JessicaP View Post
                        I have some more information.

                        The attached script has a self-check unit test suite for correctness. .
                        Not sure you should add items with Position < 0 at the end of the book. I think better to ignore those.

                        Comment


                          #13
                          Originally posted by ren37 View Post
                          Not sure you should add items with Position < 0 at the end of the book. I think better to ignore those.
                          The tests are designed to be comprehensive and can not make assumptions about users being careful when programming. If you are able to write a failing test please let us know.

                          Originally posted by ren37 View Post
                          Still not get "bug confirmed" message. What are you waiting for?
                          I appreciate your patience. Writing a tool which accesses the level 2 window through an add-on programmatically takes time and is necessary to present a clear case to our developers, should there be a bug, that will let them know exactly where the bug is and how to repair it. We will likely not need more information from you for the time being, and we appreciate your monitoring this thread. I will report back when I have more information. We are investigating this as a bug.
                          Jessica P.NinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by NinjaTrader_JessicaP View Post
                            The tests are designed to be comprehensive and can not make assumptions about users being careful when programming. If you are able to write a failing test please let us know.
                            Your synthetic test is just perfect.
                            But in real life it's a mistake to add a value with position < 0 at the end of order book. On the other hand position is always >= 0 on real data. So your sample is good to a certain extent.
                            Last edited by ren37; 04-10-2017, 08:10 AM.

                            Comment


                              #15
                              Thank you for pointing this out. You are correct that this would be a code mistake. Users visiting this forum are cautioned against using the test code in their own code samples.

                              I should have some more information regarding this shortly. Thank you again for your patience and assistance improving NinjaTrader.
                              Jessica P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by RideMe, 04-07-2024, 04:54 PM
                              5 responses
                              28 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by f.saeidi, Today, 08:13 AM
                              1 response
                              4 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by DavidHP, Today, 07:56 AM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by kujista, Today, 06:23 AM
                              3 responses
                              9 views
                              0 likes
                              Last Post kujista
                              by kujista
                               
                              Started by Mindset, Yesterday, 02:04 AM
                              2 responses
                              18 views
                              0 likes
                              Last Post NinjaTrader_RyanS  
                              Working...
                              X