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

Updates in OnMarketData vs OnMarketDepth

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

    Updates in OnMarketData vs OnMarketDepth

    Hi,

    I'm trying to sort out updates to the inside Bid and Ask in OnMarketData vs OnMarketDepth.

    Using your SampleMarketDepth as a basis, I added a Print statement whenever the Position 0 Ask row is updated.
    I also added the OnMarketData method, with a Print statement whenever the Ask is updated.

    Generally the updates appear in strict sequence, first OnMarketDepth and then OnMarketData.

    Quite often, however, some updates are processed by OnMarketDepth but are skipped by OnMarketData (see image 1).

    On the other hand, when the price is updated, the update appears to be first processed by OnMarketData and then by OnMarketDepth (see image 2), before reverting to the 'normal' sequence.

    Could you clarify what is going on?

    Thanks
    Attached Files

    #2
    Hello,

    Thanks for the note.

    NinjaTrader runs asynchronously with these events. Therefor you can never count on an exact sequence of events on these depending on race conditions.

    -Brett

    Comment


      #3
      OK, thanks for the reply, that clarifies part of it.

      Why does OnMarketData skip some of the volume updates processed by OnMarketDepth?

      Comment


        #4
        Hello,

        OnMarketDepth is called for any change in MarketDepthData. Does not mean a trade data actually came through which would be called for in OnMarketData.

        I would not expect the two events to be tied to each other but would most likely be very similar.

        -Brett

        Comment


          #5
          I'm confused by this.

          OnMarketData is triggered by a trade event, when MarketDataType = Last, but when MarketDataType = Bid or Ask, isn't it being triggered by an update to the inside Bid or Ask?

          Comment


            #6
            It could be triggered by any of event args shown here - http://www.ninjatrader.com/support/h...aeventargs.htm

            Are you sure Level 1 and 2 data from the exact same source is being run here in comparison?

            As Brett noted, it might be difficult to compare exactly due to the asyncronous nature of the events.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Hi Bertrand,
              Thanks for the response. Yes, that's what I had thought.

              But in that case, my original question remains: why are some updates being skipped in OnMarketData, as in the first image I posted? The MarketDepth event updates the volume 4 times, while OnMarketData skips the intermediary steps. I don't see them appearing at all, so I don't think it's just out of sequence. And it happens very often.

              I was connected to only one datasource, ZenFire.

              Comment


                #8
                palinuro, unfortunately you could not compare the sequencing of events across the two methods, you could be very well seeing race conditions happen then here.

                From the perspective of the individual method / datastream the events will appear in the correct sequence though.
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  But it's not the sequence I'm concerned about. They're definitely in the correct sequence, but OnMarketData is missing some updates.

                  Comment


                    #10
                    Originally posted by palinuro View Post
                    But it's not the sequence I'm concerned about. They're definitely in the correct sequence, but OnMarketData is missing some updates.
                    MarketData and MarketDepth are quasi-independent sources for events. MarketData is measuring and updating on trades: MarketDepth is measuring and updating on order changes. So, for example:
                    1. A limit short order is placed above the ask, but no order is yet filled. MarketDepth changes; MarketData does not.
                    2. The order is pulled, but no orders are filled. Again MarketDepth changes; MarketData does not.
                    3. An order is filled. That means that market depth must change (the number of orders outstanding has been reduced), so both MarketDepth and MarketData will change.
                    Last edited by koganam; 01-21-2012, 02:09 PM. Reason: Corrected spacing

                    Comment


                      #11
                      Thanks very much koganam, that clarified it for me.

                      Does this also apply to changes in the inside bid or ask price? That is, the offer price may tick up or down, but if no trade occurs OnMarketData doesn't report it?

                      Comment


                        #12
                        Originally posted by palinuro View Post
                        Thanks very much koganam, that clarified it for me.

                        Does this also apply to changes in the inside bid or ask price? That is, the offer price may tick up or down, but if no trade occurs OnMarketData doesn't report it?
                        Pretty much. I just used the short above the ask as an illustrative example, but the behavior is just due to the juxtaposition of orders and trades. Remember though, that a change in price is almost always a result of an actual trade, so if the price ticks up or down, that will usually be a MarketData event.
                        Last edited by koganam; 01-21-2012, 02:11 PM.

                        Comment


                          #13
                          Hi, I am a bit late to this thread but in researching an issue I have come across, this seems like an appropriate place to ask my questions.

                          In OnMarketData I am printing out the volume from e.Price (Last) which in most cases will match what I get in OnBarUpdate (COBC = true) for volume since the last bar. Occasionally the sum of the volume for e.Price = Last since the last bar update will be slightly off. Is this possibly due to the sequence of events such that a particular trade may come in out of sequence with the bar it belongs in?

                          Also, I tried using the basic technique of :

                          Print(e.Price + " " + GetCurrentBid() + " " + GetCurrentAsk() + " " + e.Volume);

                          to classify the trade as at the bid or at the ask but it does not work in all cases. I ran this in market replay in the early morning hours when volume was low and trades were relatively slow.

                          There are cases where the volume of the last trade is clearly at the ask price on the DOM but the print out shows a higher ask The trade is at 1355.25 (ask) but the above print statement shows 1355.50 as the ask.

                          Is there a better technique to resolve this?

                          Best Regards,
                          Scott

                          Comment


                            #14
                            Originally posted by ScottB View Post
                            Hi, I am a bit late to this thread but in researching an issue I have come across, this seems like an appropriate place to ask my questions.

                            In OnMarketData I am printing out the volume from e.Price (Last) which in most cases will match what I get in OnBarUpdate (COBC = true) for volume since the last bar. Occasionally the sum of the volume for e.Price = Last since the last bar update will be slightly off. Is this possibly due to the sequence of events such that a particular trade may come in out of sequence with the bar it belongs in?

                            Also, I tried using the basic technique of :

                            Print(e.Price + " " + GetCurrentBid() + " " + GetCurrentAsk() + " " + e.Volume);

                            to classify the trade as at the bid or at the ask but it does not work in all cases. I ran this in market replay in the early morning hours when volume was low and trades were relatively slow.

                            There are cases where the volume of the last trade is clearly at the ask price on the DOM but the print out shows a higher ask The trade is at 1355.25 (ask) but the above print statement shows 1355.50 as the ask.

                            Is there a better technique to resolve this?

                            Best Regards,
                            Scott
                            On any Windows system, there is too much bloat going on under the operating-system drawing-context hood for the DOM or chart to be accurate to the degree that you seek. It just simply takes time to draw all those fancy pictures that we call a GUI. The most accurate sync to trade data will be the T&S, and given the multitasking nature of windows, and possible feed aggregation or network data choke, I would expect even that to be off occasionally.

                            Comment


                              #15
                              koganam, thanks for the reply. I definitely understand your thoughts on the overhead which is why I was testing in market replay in the early morning hours. There was virtually no movement to draw and the prices were definitely off the bid/ask designation you would expect.

                              I am trying to determine how pervasive this issue is. If it only happens occassionally, that is not an issue or if there is a known relationship among the various events (like there is with OnOrderUpdate vs. OnExecution, etc.) that will work for me as well.

                              This is a trading system controlled from an external form (standalone exe so it is on a completely different thread) and only uses a single NinjaTrader DOM to verify order placements (no charts open, etc.).

                              So when you say T&S is the most accurate are you referring to OnMarketData using e.Price (last) or OnBarUpdate using Close[0]?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by PaulMohn, Today, 03:49 AM
                              0 responses
                              7 views
                              0 likes
                              Last Post PaulMohn  
                              Started by inanazsocial, Today, 01:15 AM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_Jason  
                              Started by rocketman7, Today, 02:12 AM
                              0 responses
                              10 views
                              0 likes
                              Last Post rocketman7  
                              Started by dustydbayer, Today, 01:59 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post dustydbayer  
                              Started by trilliantrader, 04-18-2024, 08:16 AM
                              5 responses
                              23 views
                              0 likes
                              Last Post trilliantrader  
                              Working...
                              X