NexusFi: Find Your Edge


Home Menu

 





Possible issue with Buy, sell, and net volume


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one ratfink with 8 posts (4 thanks)
    2. looks_two Cheech with 7 posts (4 thanks)
    3. looks_3 Cilla with 3 posts (2 thanks)
    4. looks_4 memonic with 3 posts (0 thanks)
    1. trending_up 4,784 views
    2. thumb_up 10 thanks given
    3. group 4 followers
    1. forum 22 posts
    2. attach_file 2 attachments




 
Search this Thread

Possible issue with Buy, sell, and net volume

  #1 (permalink)
 Cheech 
Mesa, AZ/USA
 
Experience: Intermediate
Platform: NinjaTrader, ThinkorSwim
Broker: AMP Futures/CQG, TDA
Trading: Currency Futures, my Harley Davidson
Posts: 107 since Jun 2012
Thanks Given: 43
Thanks Received: 133

I am really perplexed on the condition stated here and request some input.

I recently wrote and posted an indicator to plot buy, sell, net, and total volumes which was based on NT’s BuySellVolume (BSV) indicator. No issues with the indicator as is however, as I was writing another indicator to do more analysis on the buy and sell volume I realized there was something that I completely missed because I did not bother investigating why the BSV indicator categorized the trade volume as either a Buy or Sell. The basis for that decision can be seen in the code below (directly from the BSV indicator in a truncated form) which is in the OnMarketData section:
if(e.Price >= e.Ask)
buys += (Instrument.MasterInstrument.InstrumentType == … (truncated here)
else if (e.Price <= e.Bid)
sells += (Instrument.MasterInstrument.InstrumentType == … (truncated here)
While it looks pretty straight forward notice that both “if” statements test for the “=” condition. This would mean that when the condition is such that the Price = Ask = Bid the volume for that trade is put into the Buy Volume. If the order of condition test were reversed, then that volume under the same conditions would be Sell Volume.

Is this an arbitrary condition or is there a legitimate reason for testing in this order, a question I have raised with NT support (and have not heard back yet other than it is being investigated)? It seems to me that if there isn’t a legitimate reason for testing in this order that the volume, under the mentioned condition, would be skewed to the buy volume.
To see how prevalent this condition might occur, I modified the inprogress of Version 2 of my indicator with the code below (again truncated for clarity and in the same section):
if(e.Price > e.Ask)
buys += (Instrument.MasterInstrument.InstrumentType == … (truncated here)
else if (e.Price < e.Bid)
sells += (Instrument.MasterInstrument.InstrumentType == … (truncated here)
else if ( counter == 0 )
{
buys += (Instrument.MasterInstrument.InstrumentType == … (truncated here)
counter++;
buyCounter++;
}
else
{
sells += (Instrument.MasterInstrument.InstrumentType == … (truncated here)
counter--;
sellCounter++;
}
This code handles the Price=Ask=Sell condition differently by splitting the matches equally between the Buys and Sells, arbitrarily putting the even trades as buys and the odd trades as sells. It also counts the number of times each section of the code was entered for each bar which get printed when the bar is closed. The results surprised me.

Using a 300 tick bar (with tick replay) on over 5000 bars all but 3 or 4 matched the condition. This count included both historical and real time data with the historical making up a major part of the count. The screen shot shows how different the results are with only the code change above.

Unless I am missing something (entirely possible), the issue is that unless there is a justifiable reason for categorizing the trades that meets the condition as Buy volume then it must be arbitrary therefore is not justified. Does this or does it not call into question the value of even using buy/sell volume under these circumstances?

Thoughts!

Attached Thumbnails
Click image for larger version

Name:	Buy-Sell_issue.png
Views:	234
Size:	299.6 KB
ID:	264734  
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
REcommedations for programming help
Sierra Chart
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
How to apply profiles
Traders Hideout
Better Renko Gaps
The Elite Circle
 
  #2 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,426


Cheech View Post

While it looks pretty straight forward notice that both “if” statements test for the “=” condition.

Not so, one condition is testing for >= and the other is testing for <=.

i.e. the code caters for prices equal to or worse than the ask, and equal to or worse than the bid.

There are many ways to code this area but the original is an ok one.

Travel Well
Visit my NexusFi Trade Journal Reply With Quote
  #3 (permalink)
 Cheech 
Mesa, AZ/USA
 
Experience: Intermediate
Platform: NinjaTrader, ThinkorSwim
Broker: AMP Futures/CQG, TDA
Trading: Currency Futures, my Harley Davidson
Posts: 107 since Jun 2012
Thanks Given: 43
Thanks Received: 133



ratfink View Post
Not so, one condition is testing for >= and the other is testing for <=.

i.e. the code caters for prices equal to or worse than the ask, and equal to or worse than the bid.

There are many ways to code this area but the original is an ok one.

Well, but what about the condition that I mentioned when Bid and Ask are both equal to Price?? It seems to me that the first "if" would detect the equal condition therefore put the volume in the Buy category.

Started this thread Reply With Quote
  #4 (permalink)
 Cheech 
Mesa, AZ/USA
 
Experience: Intermediate
Platform: NinjaTrader, ThinkorSwim
Broker: AMP Futures/CQG, TDA
Trading: Currency Futures, my Harley Davidson
Posts: 107 since Jun 2012
Thanks Given: 43
Thanks Received: 133


ratfink View Post
Not so, one condition is testing for >= and the other is testing for <=.

i.e. the code caters for prices equal to or worse than the ask, and equal to or worse than the bid.

There are many ways to code this area but the original is an ok one.

Also, maybe you missed the part where the equal tests were removed from the NT tests and fell through to the added code. This would mean the neither the Price was > Ask nor the Price was < Bid, therefore both Bid and Ask were equal to Price.

That is the condition that I'm questioning.

I suppose one could question why the other possible conditions (Price < Ask or Price > Bid) weren't included in any test but neither of those would make sense to me in a completed trade.

Am I still missing something here?

Started this thread Reply With Quote
  #5 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,426

Here's my NT7 code (non=PC 'returns' because it's c30% faster)

 
Code
protected override void OnMarketData(MarketDataEventArgs e)
{
    if (e.Price == 0)
        return;
			
    if (e.MarketDataType == MarketDataType.Ask)
    {
        askPrice = e.Price;
        return;
    }
			
    if (e.MarketDataType == MarketDataType.Bid)
    {
         bidPrice = e.Price;
         return;
    }
			
    if (e.MarketDataType != MarketDataType.Last)
	 return;
					
    if (e.Price >= askPrice)
    {
        upVol += e.Volume;
        buying = true;
        return;
    }
			
    if (e.Price <= bidPrice)
    {
        downVol += e.Volume;
        buying = false;
        return;
    }

    if (buying)
    {
        upVol += e.Volume;
        return;
    }

    downVol += e.Volume;
}
As an aside I've stopped using OMD in more recent stuff and use separate Ask and Bid series in OBU where needed.

Travel Well
Visit my NexusFi Trade Journal Reply With Quote
  #6 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,426


Cheech View Post
Am I still missing something here?

Just that Price can be in between a widened spread Ask and Bid (i.e. neutral and therefore not registered in some code variants), or equal to Bid or equal to Ask (and be valid Buys or Sells but therefore forced into your modified code arbitrary second version allocation scheme counters), or less than Bid or greater than Ask and be rightly classed as desperate Sells or Buys. Furthermore Bid/Ask should never meet or cross or the exchange screwed up. Notwithstanding OMD also gets hit with lots of other stuff as well as what you want to see, including zero prices (meaning unchanged Bid/Ask) from some datafeeds.

Hope that and the code helps, TGIF + beer or wine also does, Cheers @Cheech.

Travel Well
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #7 (permalink)
 Cheech 
Mesa, AZ/USA
 
Experience: Intermediate
Platform: NinjaTrader, ThinkorSwim
Broker: AMP Futures/CQG, TDA
Trading: Currency Futures, my Harley Davidson
Posts: 107 since Jun 2012
Thanks Given: 43
Thanks Received: 133


ratfink View Post
Here's my NT7 code (non=PC 'returns' because it's c30% faster)

 
Code
protected override void OnMarketData(MarketDataEventArgs e)
{
    if (e.Price == 0)
        return;
			
    if (e.MarketDataType == MarketDataType.Ask)
    {
        askPrice = e.Price;
        return;
    }
			
    if (e.MarketDataType == MarketDataType.Bid)
    {
         bidPrice = e.Price;
         return;
    }
			
    if (e.MarketDataType != MarketDataType.Last)
	 return;
					
    if (e.Price >= askPrice)
    {
        upVol += e.Volume;
        buying = true;
        return;
    }
			
    if (e.Price <= bidPrice)
    {
        downVol += e.Volume;
        buying = false;
        return;
    }

    if (buying)
    {
        upVol += e.Volume;
        return;
    }

    downVol += e.Volume;
}
As an aside I've stopped using OMD in more recent stuff and use separate Ask and Bid series in OBU where needed.

Sorry, maybe I'm being dense here but I would like to see those rules in English as I still don't understand what it is you are doing and under what premise. I'm not saying they are wrong or anything but it still isn't clear to me that when a trade is completed when Bid=Ask=Price as per the NT code under what rules can be it classified as either a buy or sell trade

Started this thread Reply With Quote
  #8 (permalink)
Cilla
Oxford UK
 
Posts: 10 since Apr 2019
Thanks Given: 4
Thanks Received: 5


Cheech View Post
Also, maybe you missed the part where the equal tests were removed from the NT tests and fell through to the added code. This would mean the neither the Price was > Ask nor the Price was < Bid, therefore both Bid and Ask were equal to Price.

That is the condition that I'm questioning.

I suppose one could question why the other possible conditions (Price < Ask or Price > Bid) weren't included in any test but neither of those would make sense to me in a completed trade.

Am I still missing something here?

I think it would mean that the Price was somewhere between the Bid and the Ask, not that the Bid and Ask were the same.

Reply With Quote
Thanked by:
  #9 (permalink)
Cilla
Oxford UK
 
Posts: 10 since Apr 2019
Thanks Given: 4
Thanks Received: 5


ratfink View Post
Just that Price can be in between a widened spread Ask and Bid (i.e. neutral and therefore not registered in some code variants), or equal to Bid or equal to Ask (and be valid Buys or Sells but therefore forced into your modified code arbitrary second version allocation scheme counters), or less than Bid or greater than Ask and be rightly classed as desperate Sells or Buys. Furthermore Bid/Ask should never meet or cross or the exchange screwed up. Notwithstanding OMD also gets hit with lots of other stuff as well as what you want to see, including zero prices (meaning unchanged Bid/Ask) from some datafeeds.

Hope that and the code helps, TGIF + beer or wine also does, Cheers @Cheech.

Sorry - newbie error - missed Ratfink's post!

Reply With Quote
Thanked by:
  #10 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,426



Cilla View Post
Sorry - newbie error - missed Ratfink's post!

No problem, you clarified a point I only covered indirectly anyway.

Travel Well
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:




Last Updated on July 12, 2019


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts