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

Accessing MarketDepth

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

    Accessing MarketDepth

    Hi

    Is it possible to access the Market Depth outside of the onMarketDepth event?

    For example - could I access the levels of market depth from onBarUpdate?

    Thanks

    Pete

    #2
    Hello,

    Thanks for the note.

    Unfortunately this information is not available in OnBarUpdate().

    You would need to pass the data over manually from OnMarketData() into OnBarUpdate() with some sort of public variables., data pass over method.

    -Brett

    Comment


      #3
      Brett

      Thanks for the reply. I'm trying to get to the bottom of an issue here. Let me explain.

      I am trying to keep track of the depth in my code. I have based it on the sample code on this forum.

      I am using the onMarketDepth. When I use real time data, the deletes and inserts events are synched. So, when depth moves, I'll get a delete, then an insert. Very good.

      In replay mode, it doesn't work that way, I may get 3 deletes followed by 3 inserts. This is causing errors on the inserts.

      So - I thought I could get round this by using e.MarketDepth.Ask[idx].xxx but when I page through this & display it, I notice that it is out of synch with what is on the Static DOM.

      So - if I use the events in real time, it all works fine and synchs with the DOM BUT it doesn't work in replay mode.

      On the other hand, it does seem there is somewhat of a lag in updating e.MarketDepth.Ask[idx].xxx

      Any thoughts on this?

      Thanks

      Pete

      Comment


        #4
        Hello,

        Does the sample we have on how to do this do the same on this market replay data on your side?

        If so is this reply data downloaded off our server? If so what day? I will give it a quick test.

        I look forward to assisting you further.

        Comment


          #5
          Hi Brett

          I tried running the sample on V7 - on the ES but it didn't display anything.

          I would like to do just that - run the sample & put in some debug messages. Still - I can't see how the sample would work in replay.

          What happens in the live market, when the price ticks up or down is that you get a delete followed by an insert. As such - the method in that sample would be fine. So when it starts ticking down you get:
          delete
          insert
          delete
          insert
          delete
          insert

          On the other hand, when you run in replay (downloaded data, not recorded data), these messages seem to be grouped. So at times you get:
          delete
          delete
          delete
          insert
          insert
          insert

          Now - the deletes work but the inserts end up failing, this is with code that uses the same approach as the sample. You end up with successively less depth on the bid side when you tick down and the ask side when you tick up. Or - that's my theory 'cause I can't run your sample on r7.

          So - I'm thinking "screw the events". I've tried a lot of ways to keep a list based on replay data and I'm just not getting to anything that works. So I though of just using "e.MarketDepth.Ask" and "e.MarketDepth.Bid" - that will give me a list, so I could basically get rid of inserts and deletes (replaced with a loop through the properties) but still process the events.

          Still - one thing I don't know is how often "e.MarketDepth.Ask" is updated - will it always be in synch with the events or like GetCurrentBid() and GetCurrentAsk() does it lag somewhat?

          Cheers

          Pete

          Comment


            #6
            Hello,

            Thanks for your patience.

            I'm setting up a test here soon with the sample.

            Comment


              #7
              Much appreciated Brett....

              Comment


                #8
                Hello,

                Thanks for your patience.

                I ran a test on my side with the sample it seems to insert and delete in the same sequence as live with no errors.

                Make sure when you run the sample you use different logic other then the only Print with the CrossOver occurs as this will give you inconsistant results.

                Let me know if I can be of further assistance.

                Comment


                  #9
                  Brett

                  Can you show me what this sample market depth is supposed to look like?

                  All I see is this:



                  This is with the SampleMarketDepth indicator downloaded from this forum.

                  If I could at least get this working my end, I may be able to sort out the issue.

                  Any thoughts?

                  Pete
                  Attached Files

                  Comment


                    #10
                    Hello,

                    It prints to the Output window. There is no display in the chart.

                    Let me know if I can be of further assistance.

                    Comment


                      #11
                      OK - understood.

                      I guess the issue with that as a test of the output is that it outputs so infrequently.

                      It's only in certain circumstances this problem occurs. Let me put some debug messages in a version of this code & we'll see where we get.

                      Also - can you answer my question..

                      One thing I don't know is how often "e.MarketDepth.Ask" is updated - will it always be in synch with the events or like GetCurrentBid() and GetCurrentAsk() does it lag somewhat?

                      I can get the depth by looping through this as opposed to using the events, but I'm not sure if that's a sensible thing to do or not.

                      Can you answer?

                      Thanks

                      Pete

                      Comment


                        #12
                        Hello,

                        MarketDepth.Ask

                        is always leading and always updates, In fact it is what updates GetCurrentAsk().

                        You can do this however may be more processor intensive.depending on what logic you are running.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by funk10101, Today, 09:43 PM
                        0 responses
                        6 views
                        0 likes
                        Last Post funk10101  
                        Started by pkefal, 04-11-2024, 07:39 AM
                        11 responses
                        37 views
                        0 likes
                        Last Post jeronymite  
                        Started by bill2023, Yesterday, 08:51 AM
                        8 responses
                        44 views
                        0 likes
                        Last Post bill2023  
                        Started by yertle, Today, 08:38 AM
                        6 responses
                        26 views
                        0 likes
                        Last Post ryjoga
                        by ryjoga
                         
                        Started by algospoke, Yesterday, 06:40 PM
                        2 responses
                        24 views
                        0 likes
                        Last Post algospoke  
                        Working...
                        X