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

OnMarketData() e.MarketDataType.Last execution side

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

    #16
    Hello mballagan,

    It is possible to see bids and asks change along with their volume in OnMarketData if you are not filtering for the Last price (price at which the last trade occurred.) I would recommend monitoring for the Last MarketDataType, observing if that was a bid or an ask, and then check for accumulated volume.

    Please let us know if we can be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #17
      Originally posted by NinjaTrader_Jim View Post
      Hello mballagan,

      It is possible to see bids and asks change along with their volume in OnMarketData if you are not filtering for the Last price (price at which the last trade occurred.) I would recommend monitoring for the Last MarketDataType, observing if that was a bid or an ask, and then check for accumulated volume.

      Please let us know if we can be of further assistance.
      So to store ask volume trades I would use something like the following?


      protected override void OnMarketData(MarketDataEventArgs e)
      {


      if (e.MarketDataType == MarketDataType.Ask && e.MarketDataType == MarketDataType.Last)
      {

      // store ask trades (similar logic for trades executed at bid)

      }

      }

      Comment


        #18
        Hello mballagan,

        For NinjaTrader 7, the bid and ask prices should be set with MarketDataType.Bid and MarketDataType.Ask. Please see lines 97 - 106 of the NinjaTrader 7 Volume Profile Indicator for reference.

        Code:
        if (e.MarketDataType == MarketDataType.Ask)
        {
            askPrice = e.Price;
            return;
        }
        if (e.MarketDataType == MarketDataType.Bid)
        {
            bidPrice = e.Price;
            return;
        }
        The volume can then be accumulated from MarketDataType.Last:

        Code:
        if(e.MarketDataType == MarketDataType.Last)
        {
        	if(e.Price >= askPrice)
        	{
        		buys += e.Volume;
        	}
        	else if (e.Price <= bidPrice)
        	{
        		sells += e.Volume;
        	}
        }
        Please let us know if you have any questions.
        JimNinjaTrader Customer Service

        Comment


          #19
          Last price is provided independent of Bid & Ask price, on purpose, because it
          actually is an independent piece of information.

          The Last price comes from a standalone and independent event, and is very
          useful all by itself without caring about or even knowing how it may be related
          to the events for the Bid price or Ask price.

          The market is an auction, and all three prices are really events happening
          inside the auction. The Bid, Ask, and Last prices change and adjust completely
          independent of one another based upon actual auction events, such as a
          transaction between a buyer and seller, or an offer to buy at a certain price, etc.

          Granted, they are somewhat related, for ex, Last price is typically (but not always)
          constrained by the Bid price and Ask price, but the timestamp of one OnMarketData
          price event is completely independent of the timestamps of the other price events,
          they all happen at their own speed based upon the activities of those participating
          in the auction.

          You need Last price events because, without them, how would you ever know the
          transaction price of the most recent buy/sell transaction?

          Neither Bid nor Ask events represent actual buy/sell transactions.

          It is only the Last price event that tells us a transaction (aka, an ownership change) has
          actually taken place between a buyer and a seller.(*)

          Another way to say it is this:

          Bid price events are generated only by buyers, these events do not include sellers.
          Ask price events are generated only by sellers, these events do not include buyers.

          See that? Both Bid and Ask events are solo events involving no coupling of buyer and seller.

          If you want to know when a buyer and seller have come together, the price at which
          this event (aka, a buy-sell transaction) happens is known as the Last price.

          Fun fact: Did you know the numbers shown by the standard Volume indicator are just an
          accumulation of the volume that changed hands during the transactions recorded by all
          the Last price events?

          Ah-hah! That's another reason we need the Last price event! Because, by definition, the
          only way NinjaTrader.exe can reliably record the "volume" for its public Volume data series
          (which is displayed by the standard Volume indicator) is by watching for Last price events.

          Thankfully, NinjaTrader.exe goes one step further and passes these Bid, Ask, and Last price
          events to the NinjaScript programmer through the OnMarketData method, giving the programmer
          the freedom to do all sorts of additional recording and processing of these 3 auction events.

          (*) EDIT: Technically, the exchange doesn't tell us how many different buyers bought the 100
          contracts you just sold, or how many sellers were needed to fulfill the 100 contracts you just
          purchased. This kind of detail can be important, since large block buyers and sellers would
          probably be institutions, capable of moving the market. And wouldn't you just love to know
          on which side of the market all the large block transactions are happening?
          Last edited by bltdavid; 05-11-2019, 04:41 PM.

          Comment


            #20
            bltdavid I know this is an old topic, but here I explain why you might be missing an important detail - https://ninjatrader.com/support/foru...ided-tick-data

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Kaledus, Today, 01:29 PM
            5 responses
            12 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by Waxavi, Today, 02:00 AM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by alifarahani, Today, 09:40 AM
            5 responses
            23 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by gentlebenthebear, Today, 01:30 AM
            3 responses
            16 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by PhillT, Today, 02:16 PM
            2 responses
            7 views
            0 likes
            Last Post PhillT
            by PhillT
             
            Working...
            X