Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Understanding Volume, its calculation, the related indicators, and the market

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

    Understanding Volume, its calculation, the related indicators, and the market

    Hi everybody,

    during the attempt to make sense of Volume and understand its calculation, I found that there are 3 different ways to get Ask/Bid Volume in NT8.

    - The GetCurrentAsk/BidVolume function seems to show only a fraction of the actual volume. I guess it might be the temporary offered limit orders, not the actually traded volume.
    - The BuySellVolume Indicator (which seems to be coded and calculated differently than the BuySellVolume function) shows all volume expect the Volume in-between bid and ask (https://ninjatrader.com/support/help...sellvolume.htm), which is on some days for each bar exactly the same over a long period (even days), and on some days non-existent (I got the 'neutral' volume from adding the following to the BuySellVolume indicator's OnMarketData
    Code:
    else{
    neutralV += (Instrument.MasterInstrument.InstrumentType == Cbi.InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume(e.Volume) : e.Volume);}
    )
    - Lastly you can get the ask/bid volume by calling BuySellVolume().Buys/Sells. The outcome is an almost identical volume to the BuySellVolume indicator value. Only at some bars the volume diverges by being a few percent less.

    I see that the volume shown by the BuySellVolume matches the volume of the VOL indicator exactly. Therefore I assume it's the most appropriate one.
    I wonder if there can be any volume in-between bid and ask at all? I mean if there is a gap nobody trades there, and if somebody trades there, the gap automatically disappears for this second of the trade. Nevertheless I saw the indicator show some 'neutral' volume. Any idea why or how?
    This brings me to my next question: is the volume that is traded at the bid or the ask the entire traded Volume in any case (expect for the trades apart from the normal broker network)? I mean in general with orderflow analysis, is the bid/ask volume the absolute volume? Can't find an answer somewhere.

    Further I wonder why the volume from the BuySellVolume() function is slightly smaller than the output of the BuySellVolume Indicator, since it gets the value from the BuySellVolume Indicator how I understand it. This happens also during times when the 'neutral' volume is zero.
    I don't have the BuySellVolume.() function coded with if(BarsInProgress == 0) / == 1). Might this be the reason?


    Regards,
    Sebastian

    #2
    Hello Sebastian,

    The Volume[0] series is the volume of the bar series and will represent the volume received while that bar is open for both historical and real-time data. This will use the data type of the series, either ask, bid, or last.
    https://ninjatrader.com/support/help...ies_volume.htm

    GetCurrentAskVolume() is a method that returns a snapshot of the volume of the most recently received ask update in real-time only. This is not the volume of the bar, but just the volume of the last update.
    https://ninjatrader.com/support/help...taskvolume.htm

    OnMarketData() is a override method that updates for every real-time market data update. This where you can receive a stream of updates and get the volume of each update. The argument allows you to access the Volume: marketDataUpdate.Volume.
    https://ninjatrader.com/support/help...marketdata.htm

    BuySellVolume() is an indicator. This indicator uses OnMarketData() to get volume. The buy plot is added to the sell plot so that you can actually see it on a chart.

    BuySellVolume() is not a function standard to NinjaScript, this is an only an indicator. Where you have mentioned "why the volume from the BuySellVolume() function is slightly smaller than the output of the BuySellVolume Indicator" you would be comparing the indicator to itself. There is no BuySellVolume() function.. there is only the indicator.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hey Chelsea,

      thank you for the input with the Volume and MarketData, the confirmation about GetCurrentAsk/BidVolume, and clarification about the BuySellVolume indicator and not function.

      The question remains why plotting BuySellVolume like
      Code:
      Value[0] = BuySellVolume().Buys[0];
      Value[1] = BuySellVolume().Sells[0];
      generates slightly different values than by using the indicator directly.
      Is there a way to code it that it shows exactly the same values?

      And do you have an answer for my other questions concerning rather the market than the indicators, although these questions may appear silly.
      Just if you know it. Would appreciate it!

      Greetings,
      Sebastian

      Comment


        #4
        Hello Sebastian,

        This would likely be due to when the indicators begin collecting data. As they start collecting the moment they are initialized, if they initialize even 1 tick apart, they are going to have different values. Its the same script being called.

        If a script were processing using bar series information, instead of collecting real-time ticks, it would have the same value. Take a look at the VOL indicator to get an idea of what I mean.

        I'm not certain what your exact remaining questions are.

        Are you asking if the Volume[0] series contains bid and ask? The Volume[0] will reflect the data type of the series. If the series is ask, it will have ask volume. If the series is last, it will have last volume.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello Chelsea,

          alright, that makes sense, and since it calls the exact same script, the deviation can't be too big.

          The questions were why and how there can be a volume in-between bid and ask, and whether the order flow volume of the bid and ask is 100% all traded volume?

          Comment


            #6
            Hello seykool,

            This is Jim, responding on behalf of Chelsea who is out of the office at this time.

            Could you clarify on where you are seeing volume in between bid/ask? Order Flow tools will track last qualified trades, and the buys/sells are actual trades.

            We look forward to assisting.

            Comment


              #7
              Hi Jim,

              I am getting the "neutral" volume from this code:
              Code:
              protected override void OnMarketData(MarketDataEventArgs e)
              {
              if(e.MarketDataType == MarketDataType.Last)
              {
              if(e.Price >= e.Ask)
              buys += (Instrument.MasterInstrument.InstrumentType == Cbi.InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume(e.Volume) : e.Volume);
              else if (e.Price <= e.Bid)
              sells += (Instrument.MasterInstrument.InstrumentType == Cbi.InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume(e.Volume) : e.Volume);
              else
              neutralV += (Instrument.MasterInstrument.InstrumentType == Cbi.InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume(e.Volume) : e.Volume);
              }
              }
              Greetings

              Comment


                #8
                Hello seykool,

                Apologies, could you also let me know the data provider and instrument you are using when you see this? Logically, I do not see how we can ever increment neutralV unless there was something about the Bid/Ask prices given from the data provider and the symbol/asset used.

                If you are trying to do this with FOREX, we could see issues since FOREX does not have a Last price and Last is substituted with Bid prices.

                We look forward to hearing back.

                Comment


                  #9
                  Hi Jim,

                  I see the neutral Volume on GC12-20 with a Continuum trial connection.

                  Comment


                    #10
                    Hello seykool,

                    I've made a simple test script but I am not seeing neutral volume with the GC 12-20.

                    Below is a link to a video of the test.


                    Attached is the test script.

                    Using the test script, is the behavior different than what is shown in the video?
                    Attached Files
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello Chelsea,

                      thanks for doing the test. I believe having the values printed out brought light into that there isn't any neutral volume. I have used your script and run it through the last 20 days of GC on tick replay and it didn't print a single neutral volume line.
                      Strange enough, I see with a very similar script neutral volume that differs by time, date, and instrument interval. Just in the case you are curious, I attached two screenshots. One showing neutral volume color coded as gray on 60min and the other doesn't show neutral volume at 1 min.
                      I used the following code:
                      Code:
                      protected override void OnMarketData(MarketDataEventArgs e)
                      {
                      if(e.MarketDataType == MarketDataType.Last)
                      {
                      if(e.Price >= e.Ask)
                      buys += (Instrument.MasterInstrument.InstrumentType == Cbi.InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume(e.Volume) : e.Volume);
                      else if (e.Price <= e.Bid)
                      sells += (Instrument.MasterInstrument.InstrumentType == Cbi.InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume(e.Volume) : e.Volume);
                      else
                      neutralV += (Instrument.MasterInstrument.InstrumentType == Cbi.InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume(e.Volume) : e.Volume);
                      }
                      }
                      
                      protected override void OnBarUpdate()
                      {
                      if (CurrentBar < activeBar || CurrentBar <= BarsRequiredToPlot)
                      return;
                      
                      // New Bar has been formed
                      // - Assign last volume counted to the prior bar
                      // - Reset volume count for new bar
                      if (CurrentBar != activeBar)
                      {
                      /* Just a test:
                      Print(String.Format("Bar: {0} Delta: {1}",CurrentBar-1, buys - sells));
                      Print(String.Format("CurrentBar: {0} activeBar: {1}", CurrentBar, activeBar)); */
                      Sells[1] = sells + (neutralV/2);
                      Buys[1] = buys + sells + (neutralV/2);
                      Neutrals[1] = neutralV;
                      buys = 0;
                      sells = 0;
                      activeBar = CurrentBar;
                      }
                      
                      Sells[0] = sells + (neutralV/2);
                      Buys[0] = buys + sells + (neutralV/2);
                      Neutrals[0] = neutralV;
                      }
                      This made me curious (especially because it differs by time). Thanks for the investigation!
                      Since the print debug proved that there isn't any neutral volume, I assume it's just some sort of a bug or so. It doesn't matter, since there isn't real neutral volume.

                      Greetings,
                      Sebastian

                      Attached Files

                      Comment


                        #12
                        Hello Sebastian,

                        Starting with the test script I provided, add to this one object or line line at at time, and print things after every line to see where the unexpected values are coming from.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Good morning Chelsea,

                          I am not really interested in it anymore, since it doesn't seem to have any relevance to trading. Nevertheless, in the case you was interested I did a test more or less like you described.
                          I found out that 99% of the neutral volume came from having missed the reset of the neutralV field at each new bar:
                          ( buys = 0;
                          sells = 0;
                          neutralV = 0; <-- this one was missing )

                          But then, there came nonetheless some neutral volume through. During 20 days three bars. 2 bars with 1 vol and 1 bar with 2 vol.
                          I've made some screenshots (one is from before adding neutralV=0) and attached you the indicator I used.
                          Consider that I am GMT time.

                          Regards,
                          Sebastian
                          Attached Files
                          Last edited by seykool; 11-13-2020, 04:06 AM.

                          Comment


                            #14
                            Hello seykool,

                            I've been able to reproduce. I consoled with my colleagues here and this comes down to how the data gets packaged from the data provider. In regards to CME, Bid/Ask are separate exchange feeds than the Last feed. Since they are offered as separate feeds there can be occurrences where a best bid/best ask is not properly synced with a Last tick at the data provider level.

                            You shouldn't be alarmed with these small occurrences since they would be expected data provider level discrepancies. However, if you are seeing constant neutral volume, this could constitute a deeper data provider related issue where the last ticks are not getting packages with the best ask/best bid outside of synchronization discrepancies.

                            We look forward to assisting.

                            Comment


                              #15
                              Hi Jim,

                              alright. I guess with 2 datafeeds it's almosz impossible to have it always perfectly synced when it comes down to milliseconds.
                              Yes sure, it's a trivial amount.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              581 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              338 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              103 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              554 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              552 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X