Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help calculating whether last trade was at bid or ask.

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

    Help calculating whether last trade was at bid or ask.

    I am trying to build an indicator that tracks trades between a certain minimum size X and a maximum size Y, and builds a cumulative indicator of delta volume for that trade size range. So when a trade comes in at the bid, the volume of that trade is subtracted from the total, and if it's at the ask it's added to the total.

    I am using the OnMarketData() function as follows:

    protected override void OnMarketData(MarketDataEventArgs e)
    {
    if (e.MarketDataType == MarketDataType.Last)
    {
    int volume = e.Volume;

    if (GetCurrentBid() == e.Price)
    {
    // trade was at the bid

    volume *= -1;
    }

    if ((e.Volume >= smallSize) &&
    (e.Volume <= largeSize))
    {
    volumeDelta += volume;
    }
    }
    }

    This seems to work OK, except for one time when I saw a positive trade go through and got booked as a negative trade. What I am wondering is if the GetCurrentBid() function is really the best way to be determining if the trade was executed at the bid or the ask. Is there a better/more reliable way to do this? Thanks!

    #2
    JS999, I would then suggest working directly in OnMarketData() for the bid price also and check if that makes a difference in your scenario - http://www.ninjatrader-support.com/H...arketData.html
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      JS999, I would then suggest working directly in OnMarketData() for the bid price also and check if that makes a difference in your scenario - http://www.ninjatrader-support.com/H...arketData.html
      As you can see from my post, I am working with OnMarketData()... what I want to know is if I am doing it correctly by calling GetCurrentBid() in that function to find out if the trade was at the bid or the ask. Is this the proper way to do it, or is there a better/more reliable way? Please look at the code I pasted in and comment. Thanks.

      Comment


        #4
        JS999, yes that's why I suggested 'getting' the current bid also from the OnMarketData() to compare - your check for the current trade with GetCurrentBid() is ok, just keep in mind historically this will be the close price.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          JS999, yes that's why I suggested 'getting' the current bid also from the OnMarketData() to compare - your check for the current trade with GetCurrentBid() is ok, just keep in mind historically this will be the close price.
          What I am wondering is if there could be a discrepancy between the time that the OnMarketData() fires off and the time the GetCurrentBid() call returns the price. For example, the OnMarketData event fires off from a trade that occurs at the bid, but that trade happens to take out the bid in the process, thereby making the CURRENT bid actually one tick lower. So the comparison doesn't actually work, because GetCurrentBid() returns the NEW current bid, and that does not compare to the last TRADED price. Do you see what I mean? You can lose information that way.

          Does it work like that, or can I guarantee that GetCurrentBid() is actually going to be equivalent to the last price that traded, even if it traded at the bid and took it out? If it does work like I described in the above paragraph, is there some way around that issue?

          Comment


            #6
            JS999,

            I have already build Indicators that do what you are looking to develop.

            They are available here for a nominal donation that supports the website.

            This is the primary Elite content section, if content doesn't fit in another category or if you want to only share the content with Elite Members to help support our community



            Look for my posting concerning volume splitters.

            See you there,

            RJay

            P.S.

            If you just want to see what they look like click here. Images are in post #2 in the following link.

            Hi All, Phase 2 of my Volume Watch Project is complete. New, to me at least, introducing VolumeBidAskChurn and TickBidAskChurn indicators. These churn indicators measure the opposing sides in the market that tend to cancel each other out. One suite contains trader Total, Delta and Churn Volume indicators. The other suite contains trader Total, Delta and Churn Tick indicators. The tick indicators measure the number of transactions at ask or bid for the current bar. The volume indicators measure &#8230;
            Last edited by RJay; 09-10-2009, 08:23 AM.
            RJay
            NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

            Comment


              #7
              Originally posted by JS999 View Post
              What I am wondering is if there could be a discrepancy between the time that the OnMarketData() fires off and the time the GetCurrentBid() call returns the price. For example, the OnMarketData event fires off from a trade that occurs at the bid, but that trade happens to take out the bid in the process, thereby making the CURRENT bid actually one tick lower. So the comparison doesn't actually work, because GetCurrentBid() returns the NEW current bid, and that does not compare to the last TRADED price. Do you see what I mean? You can lose information that way.

              Does it work like that, or can I guarantee that GetCurrentBid() is actually going to be equivalent to the last price that traded, even if it traded at the bid and took it out? If it does work like I described in the above paragraph, is there some way around that issue?
              GetCurrentBid() would give you the latest bid price at call time and was meant for the OnBarUpdate(), so if you're working in OnMarketData() it's best to work directly with the bid price in this method then. Most important, there's no data 'lost', every change in price will trigger OnMarketData() or OnMarketDepth() for Level2 data.
              BertrandNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by adeelshahzad, Today, 03:54 AM
              5 responses
              32 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by stafe, 04-15-2024, 08:34 PM
              7 responses
              32 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by merzo, 06-25-2023, 02:19 AM
              10 responses
              823 views
              1 like
              Last Post NinjaTrader_ChristopherJ  
              Started by frankthearm, Today, 09:08 AM
              5 responses
              22 views
              0 likes
              Last Post NinjaTrader_Clayton  
              Started by jeronymite, 04-12-2024, 04:26 PM
              3 responses
              43 views
              0 likes
              Last Post jeronymite  
              Working...
              X