• 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

Confused by output of onMarketData

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

    Confused by output of onMarketData

    Hi

    I'm trying to understand some of the output of OnMarketData in which I think I see more traded volume at the Ask than available volume at the Ask. I ran the following code against YM 06-19 future:

    protected override void OnMarketData(MarketDataEventArgs e)
    {
    if (e.MarketDataType == MarketDataType.Last)
    {
    Print("Last: " + e.Volume + " @ " + e.Price);
    }
    else if (e.MarketDataType == MarketDataType.Ask) {
    var diff = e.Volume - lastVolAtAsk;
    Print("Ask: " + diff + " to " + e.Volume + " @ " + e.Price);
    lastVolAtAsk=e.Volume;
    }
    else if (e.MarketDataType == MarketDataType.Bid) {
    var diff = e.Volume - lastVolAtBid;
    Print("Bid: " + diff + " to " + e.Volume + " @ " + e.Price);
    lastVolAtBid=e.Volume;
    }
    }

    The output I don't understand:

    Ask: -1 to 15 @ 25989
    Bid: 1 to 5 @ 25988
    Bid: 1 to 6 @ 25988
    Bid: 1 to 7 @ 25988
    Ask: -1 to 14 @ 25989
    Bid: 1 to 8 @ 25988
    Bid: -1 to 7 @ 25988
    Ask: -1 to 13 @ 25989
    Bid: -1 to 6 @ 25988
    Last: 1 @ 25989
    Last: 1 @ 25989
    Last: 1 @ 25989
    Last: 14 @ 25989

    Ask: -7 to 6 @ 25990
    Bid: 1 to 7 @ 25988
    Bid: 1 to 8 @ 25988
    Ask: 1 to 7 @ 25990
    Bid: 1 to 9 @ 25988
    Bid: -1 to 8 @ 25988

    So, it looks to me like there were 17 contracts traded at the Ask (25989) when there was only an ask volume of 13 available.

    Please could someone help me make sense of this.

    #2
    Hello Cilla,

    Thank you for your post and welcome to the NinjaTrader forum!

    When you come across the Last MarketDataType that will be the volume and price the stock or commodity was actually traded at. Not all volume on either the bid or ask side of the market is guaranteed to be filled. This can be visualized with the T&S window. The current bid and ask volume can be seen at the top and there is a stream of trades that are occurring in real time where the volume "trickles" in.

    Please let me know if I can assist further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi Chris - thanks for your answer.

      I've looked at the T&S window and that appears to report the same stream of data that my code does, but with some timestamp information included. Are you saying that some trades can occur at e.g. the ask without affecting the ask volume, even though the ask price stays the same?

      Comment


        #4
        Hello Cilla,

        Thank you for your reply.

        Viewing the T&S window will show you that it's possible for multiple trades to occur at a given bid/ask price and not necessarily change the price instantly. This is why we offer the Calculate property of OnPriceChange in contrast to OnEachTick. A single tick of a market doesn't guarantee a price change, so that could improve the performance of your script because it calls OnBarUpdate less often.

        Please let me know if I can assist further.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Hi again Chris

          I can see that multiple trades can occur at a given bid/ask price without changing the price instantly, but my question is about volume at the ask, not price. Putting it another way, if there are 10 contracts (i.e. ask volume = 10) at the current ask price (say 25950) and a single trade of 3 contracts takes place at the ask, should we not expect to see last price = 25950, last volume = 3 and then ask price = 25950, ask volume = 7?

          Comment


            #6
            Hello Cilla,

            Thank you for your reply.

            That would be the expected results for volume. I am not getting any anomalies like the example that you posted though. What instrument are you looking at and what data feed are you connected to?

            I look forward to your reply.
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Hi Chris

              It's YM 06-19 from Kinetick.

              Comment


                #8
                Hello Cilla,

                Thank you for your reply.

                I was able to get the behavior you are seeing on the YM instrument, but not the ES. Could you see if you get this on the ES as well? I am also reaching out to my superior so he can have a look a well.

                I look forward to your reply.
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  Hello Chris

                  Thanks for sticking with this one!

                  I first tried to reproduce it today on YM, matching up with T&S data - eventually succeeded with this, but somehow T&S is able to determine things like "above ask" even though the "last" price is equal to the "ask" price - perhaps T&S has access to data not available to OnMarketData?

                  I'm now seeing if I can get the same behaviour on ES and will let you know what I find.

                  Thanks

                  Comment


                    #10
                    Hi Chris

                    I think I've managed to see similar behaviour on ES.

                    Today at 08:11:47, there was bid volume of 76, followed by a large number of trades at bid, total volume = 78, and then the bid volume only reduced by 69, all at the same bid price of 2835.75

                    Comment


                      #11
                      Hello Cilla,

                      Thank you for your reply.

                      I ran some tests on a slimmed down version of your OnMarketData. I never found an instance where the volume of a last filled more than the previously reported bid/ask price. I did find that if the price level runs out of volume, the ask/bid price will change to the next level, giving you the volume for that new price level.

                      See this screen shot I gathered:
                      https://clauber.tinytake.com/sf/MzQwMTE3NF8xMDE3Mjg3Ng

                      Could you run the attached indicator and observe the output window for the issue you are seeing? If you can see it in the output window, could you please post a screenshot here? Place the attached file within \Documents\NinjaTrader 8\bin\Custom\Indicators and compile.

                      I look forward to hearing of your results.
                      Attached Files
                      Chris L.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi Chris

                        The only difference I can see between your code and mine is that you don't print the change in volume at the bid or ask, so the original result I posted (and I thought you'd managed to replicate) is still valid. However, just in case, I've tried your indicator and eventually seen the "anomaly" - you just have to wait long enough.

                        Please see the uploaded screenshot. It looks like there's a trade of 21 contracts at the bid, but the bid volume actually increases by 1. What do you make of it?

                        Thanks

                        Comment


                          #13
                          Hello Cilla,

                          Thank you for your reply.

                          When I mentioned I saw the same thing as you, that wasn't quite accurate. I didn't realize I was looking at a case where the price changed to a different price level, like in my previous screenshot.

                          For now, I will let my supervisor look into this with me.

                          Thanks in advance for your patience.
                          Chris L.NinjaTrader Customer Service

                          Comment


                            #14
                            Thanks Chris - I look forward to hearing back from you.

                            Comment


                              #15
                              Hello Cilla,

                              Thank you for your patience.

                              After testing different data providers, I found a difference in the synchronicity of OnMarketData between all of them. The OnMarketData ask/bid stream is subject to the data feed you are using and should not be expected to perfectly sync with the last update events. The use case of OnMarketData should be looked at from a different perspective. For a useful approach to utilizing OnMarketData, we monitor changes on the Last event and primarily use the Bid and Ask Market Events to detect a new bid/ask price. Please refer to the default indicators BuySellPressure, VolumeProfile, and BuySellVolume. These three use the Last update event to gather actual market data on Bid/Ask fills. OnMarketDepth is a better tool that should be used for monitoring volume at price, which is what we are testing here. OnMarketDepth will update when a change is detected in volume at various price levels. See this reference sample that implements a Level 2 data book
                              like the SuperDOM within an indicator.

                              Please let me know if I can assist any further.
                              Chris L.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Johnny Santiago, Today, 04:50 AM
                              1 response
                              5 views
                              0 likes
                              Last Post NinjaTrader_ChrisSch  
                              Started by rickyblah12, Yesterday, 08:17 PM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_PaulH  
                              Started by jamarc, Today, 02:30 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post jamarc
                              by jamarc
                               
                              Started by mrlucky1x, Yesterday, 08:07 PM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_PaulH  
                              Started by uday12, Yesterday, 07:21 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post uday12
                              by uday12
                               
                              Working...
                              X