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

More question about OnMarketData(MarketDataEventArgs e)

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

    More question about OnMarketData(MarketDataEventArgs e)

    it still is difficult for me to understand the parameter of method OnMarketData. let's use a sample to discuss it
    There is a market only PersonA and PersonB, goods name is G, currently price is 100

    PersonA try to sale G, so already put a limited order at price 100, volume is 20. So right now price still is 100
    and no any transaction. Then PersonB buy G, volume is 5, price is 100. So it casue method OnMarketData
    receive a event, would you like tell me the value of every property of MarketDataEventArgs?

    BTW how many events could OnMarketData receive? I guess should be 2, right?

    Thanks
    Last edited by UMLer; 02-15-2022, 07:55 AM.

    #2
    Hello UMLer,

    Thanks for your post.

    OnMarketData will provide events from the Level 1 data feed. These include streams of best bids/best offers (not completed trades) and Last qualified trades/ticks (completed trades.) We can also see other MarketDataTypes for data points offered by your data provider. (See MarketDataEventArgs)

    You could see a MarketDataType.Bid iteration for PersonA if they were the best bid. Volume 20, Price 100

    You would see a MarketDataType.Last iteration for PersonB since that would be a completed transition. Volume 5, Price 100.



    JimNinjaTrader Customer Service

    Comment


      #3

      Thanks.
      I believe this a very good way that can help me to understand method OnMarketData and
      the mechanism behind it. so i want to follow this way to discuss more details.

      Let me describe a context to help us to discuss this topic easier and deeper.
      Only 2 people on market: A and B
      Goods is G
      I will show time that every trade was done by people. right now market is opened.

      Scenario 1:
      Background:
      since the moment market opened until now nobody did any thing.

      09:00:00.000 AM
      Ask: $101
      Bid: $100
      What A did:
      Open limited order at price $101.5 to sell G, position is 100

      What are values of every element of parameter marketDataUpdate of method OnMarketData?

      Scenario 2:
      Background:
      since the moment market opened until now nobody did any thing.

      09:00:00.000 AM
      Ask: $101
      Bid: $100
      What A did:
      Open limited order at price $100.5 to sell G, position is 100
      What B did:
      Open limited order at price $100.5 to buy G, position is 100

      A and B did it perfectly at same time, and these 2 orders arrived at market exactly at same moment. What are values of every element of parameter marketDataUpdate of method OnMarketData?

      Scenario 3:
      Background:
      since the moment market opened until now nobody did any thing.

      step 1
      09:00:00.000 AM
      Ask: $101
      Bid: $100
      What A did:
      Open limited order at price $101.51 to sell G, position is 100

      step 2
      09:05:00.000 AM
      Ask: $101
      Bid: $100
      What A did:
      Open limited order at price $101.62 to sell G, position is 100
      What are values of every element of parameter marketDataUpdate of method OnMarketData?

      step 3
      09:10:00.000 AM
      Ask: $101.51
      Bid: $100
      Let's just do not consider why Ask can change, becasue only 2 people on market and
      no transaction happended, so price should be same. let's just ingore this point.

      What B did:
      Open market order at price $101.51 to buy G, position is 150
      What are values of every element of parameter marketDataUpdate of method OnMarketData?

      Thanks very much


      Comment


        #4
        Hello UMLer,

        OnMarketData is the Level 1 feed, where you see completed Last trades, Best Bid's, Best Ask's, and other data point items that can be found in MarketDataEventArgs.

        To keep it simple, just focus on:
        • Best Bid: marketDataType.Bid updates
        • Best Ask: marketDataType.Ask updates
        • and Last: marketDataType.Last updates (completed trades.)
        When MarketDataType.Bid updates, Price is the price of that Best Bid update, Volume represents the number of contracts at the bid.

        When MarketDataType.Askupdates, Price is the price of that Best Ask update, Volume represents the number of contracts at the asl.

        When MarketDataType.Last updates, Price is the price where the transition occurred, and Volume represents the number of contracts sold. Bis and Ask represent the best bid and best ask prices at the time the trade was made. (We can compare Bid/Ask and Last prices to see if a MarketDataType.Last update was a buy/sell/

        ^ Other MarketDataEventArgs would not be relevant for your current questions.

        Scenario 1:

        If you submit a Sell Limit order above the Ask, this would not be at the best Ask price, the order would be resting and would not be visible in a Level 1 feed.

        Scenario 2:

        A and B are submitted with a chance to fill, so you could see 2 Last MarketDataType updates for each buy/sell with a Volume of 100. Buy/Sell can be identified by comparing the Bid/Ask Price with the Last Price when there is a MarketDataType.Last update.

        I mention could because if there are other orders in the order book, those may fill, and price may change by the time the second order is processed.

        Scenario 3:

        Step 1 and 2 submit Sell Limit orders above the ask, so those would not be at the Best Ask, and I would not expect to see Level 1 updates.

        After step 3, you would get at least 1 MarketDataType.Last event for the completed trade to note the volume/quantity bought at each price level. (If there is not enough volume to fill 150 contracts at 101.51, the price would move, and we would seen multiple MarketDataType.Last events for each partial fill on that order.
        JimNinjaTrader Customer Service

        Comment


          #5
          Thanks very much. There are some details I want to confirm.

          You mentioned:
          ***
          When MarketDataType.Bid updates, Price is the price of that Best Bid update, Volume represents the number of contracts at the bid.

          When MarketDataType.Askupdates, Price is the price of that Best Ask update, Volume represents the number of contracts at the asl.
          ***
          This is what i understand:
          Let's say the best ask is 100, the best bid is 99, then i put a limit long order at 99.5. So I receive a OnMarketData event, and the ask property is same, bid property is 99.5. is it correct?

          besides me, everyone should receive this event, right?

          Scenario 2:
          I mentioned there are 2 orders (opened by A and B) arrived at market at same moment. But I do believe program must operate order book exclusively synchornically. So the first OnMarketData event notice the best ask price changed. Then the server process the second order that immediately filled the previous order at price 100.5. So second OnMarketData event is coming that notice a deal was made. then vlaues of these properties is:
          bid = 100
          ask = 100.5
          price = 100.5
          volume = 100
          right? and everyone should receive these 2 OnMarketData events?

          Scenario 3:
          So far I think there are 2 OnMarketData events should happen.
          This first event notice us there is a trade at price 101.51. values of properties are:
          Ask = 101.51
          Bid = 100
          Volume = 100
          Price = 101.51

          Then second event notice us there is a trade at price 101.62. values of properties are:
          Ask = 101.62
          Bid = 100
          Volume = 50
          Price = 101.62

          right?
          Everyone should receive these 2 events?
          Sorry english is not my first language and financial field is not my major. So I just want to make sure i understand everthing correctly 100%. Thanks again.

          BTW
          Q1: Is there a document to describe and define these rules to do trade? in Chinese we say micro-structure of market.​

          Comment


            #6
            Hello UMLer,

            Thanks for your notes.

            MarketDatatype.Ask and MarketDataType.Bid event updates will represent the best Ask updates and the best Bid updates. Note that these are not completed trades. If the best Ask update is 100, this value would be considered the recent best Ask price. If the best Bid price is 99.5, this means that the current best Bid price is 99.5.

            The OnMarketData() events are called and guaranteed to be in the correct sequence for every change in level one market data for the underlying instrument. This is stated in the OnMarketData() help guide page linked below.

            OnMarketData(): https://ninjatrader.com/support/help...marketdata.htm

            For scenario 2, if you submitted two orders at the same time with a possibility for them to fill then you could see two Last MarketDataType updates for each buy/sell order filled. Note that completed trades would be seen in MarketDataType.Last updates.

            For scenario 3, if two Sell Limit orders are placed above the Ask price, I would not expect to see Level 1 updates for those orders since they would not be at the best Ask. MarketDataType.Ask will only show the best ask price.

            If one of those orders is filled then you would see at least 1 MarketDataType.Last event update for the completed trade that notes the volume and quantity that was bought at each price level.

            All of our documentation for these MarketDataType events could be found in our help guide. See the help guide documentation linked below for more information.

            MarketDataEventArgs: https://ninjatrader.com/support/help...aeventargs.htm

            Let me know if I may assist further.




            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              Thanks

              you mentioned
              ***
              MarketDatatype.Ask and MarketDataType.Bid event updates will represent the best Ask updates and the best Bid updates. Note that these are not completed trades. If the best Ask update is 100, this value would be considered the recent best Ask price. If the best Bid price is 99.5, this means that the current best Bid price is 99.5.
              ***
              So my question is if i put a limited long order and the price is better(higher, 99.5) than best bid(99) currently, then the does it change best bid to 99.5?


              you mentioned:
              ***
              For scenario 2, if you submitted two orders at the same time with a possibility for them to fill then you could see two Last MarketDataType updates for each buy/sell order filled. Note that completed trades would be seen in MarketDataType.Last updates.
              ***
              ​So the problem is how to calculate volume? because i receive 2 OnMarketData events that present a same order, i should not simply add volumes. So is there any property or something to identify these 2 events present same order?

              Comment


                #8
                Hello UMLer,

                Thanks for your note.

                If you enter an order at a price higher than the best bid, then the higher price could become the new best bid price.

                You could get the Volume of OnMarketData events similar to how it is done in the sample code on the MarketDataEventArgs help guide page. This sample code show how to get the Volume of MarketDataType.Ask, MarketDataType.Bid, and MarketDataType.Last.

                MarketDataEventArgs: https://ninjatrader.com/support/help...aeventargs.htm

                The BuySellVolume indicator script could be viewed which demonstrates a concept for getting ask volume or bid volume from MarketDataType.Last events. To view the script, open a New > NinjaScript Editor window, open the Indicators folder, and double-click on the BuySellVolume file.

                Let me know if I may assist further.
                Brandon H.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks for very helpful response

                  Consider the context of our this communication, i do not create a new post, still ask question here.
                  So if I open a market order (Order A) and try to do trade then must need another order (Order B) to meet my requirement. Let's say I open a market order and it is filled so method OnMarketData is called. Then is it possible to know Order B is a market order too or a limit order? and how?

                  Thanks

                  Comment


                    #10
                    Hello UMLer,

                    Thanks for your note.

                    In OnMarketData() there are no methods or properties available for determining what the order type of an order is (Market or Limit).

                    The available OnMarketData() properties could be seen on the MarketDataEventArgs help guide page linked below.

                    MarketDataEventArgs: https://ninjatrader.com/support/help...aeventargs.htm

                    Please let me know if you have further questions.

                    Brandon H.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks.
                      I read the document and find these values of MarketDataType

                      MarketDataType.Ask
                      MarketDataType.Bid
                      MarketDataType.DailyHigh
                      MarketDataType.DailyLow
                      MarketDataType.DailyVolume
                      MarketDataType.Last
                      MarketDataType.LastClose (prior session close)
                      MarketDataType.Opening
                      MarketDataType.OpenInterest (supported by IQFeed, Kinetick)
                      MarketDataType.Settlement

                      So far I know three values that are Bid, Ask and Last. Would you like give me a introduction about all other values? When could I receive them?
                      Thanks.​

                      Comment


                        #12
                        Hello UMLer,

                        Thanks for your note.

                        That would be all of the possible MarketDataType values accessible in OnMarketData(). Note that some providers do not offer each level of information.

                        See this help guide page for information about each MarketData available: https://ninjatrader.com/support/help...marketdata.htm

                        When the values are updated will be determined by the instrument that you are running the script on. You could test each MarketDataType in a script similar to the sample code seen in the OnMarketData() help guide page to see exactly when these values are updated.

                        Please let me know if I may assist further.
                        Last edited by NinjaTrader_BrandonH; 01-10-2023, 11:05 AM.
                        Brandon H.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Mizzouman1, Today, 07:35 AM
                        3 responses
                        17 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Started by RubenCazorla, Today, 09:07 AM
                        2 responses
                        13 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by i019945nj, 12-14-2023, 06:41 AM
                        7 responses
                        82 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by timmbbo, 07-05-2023, 10:21 PM
                        4 responses
                        158 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Started by tkaboris, Today, 08:01 AM
                        1 response
                        8 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Working...
                        X