ThinkorSwim Bid Ask Volume (BAVOL) Indicator

mashume

Well-known member
VIP
I've been hacking together thinkscript studies for a while and have come across the idea of trying to see the buy/sell pressure with the difference in bid and ask volumes.

Code:
declare lower;
def askVol = Volume(priceType = PriceType.ASK);
def bidVol = Volume(priceType = PriceType.BID);
plot pressure = askVol - bidVol;

but while it is legal code according to thinkorswim, it doesn't seem to produce any results. At all.

I'm trying to run this against tick charts, not time aggregated.

I found a study that uses this (mobius' perhaps):

Code:
def TradeCountASK = tick_count(priceType = PriceType.ASK);
def TradeCountBID = tick_count(priceType = PriceType.BID);

And does something on time-based charts, but doesn't do anything (seemingly) on tick-based charts. Any help would be sincerely appreciated.
 
Solution
Does this come close to what you're interested in? You can remove the first label if you want as it's really there as a sanity check for me.

Code:
####################
#
# Ticks Per Minute for Time Charts
#
# Mashume via UseThinkScript
# 2020-08-17
#
####################
declare lower;
declare zerobase;

def timeframe = getAggregationPeriod() / 60000;

addLabel(yes, concat("Min / Bar: ", timeframe));

def T = Tick_count;

plot TicksPerMinute =  T / Timeframe;

addLabel(yes, concat("Ticks / Min: ", TicksPerMinute), color.gray);

-mashume

Also, potentially of interest is this one, which plots a histogram of the average size of trades in a candle. It can be interesting to see when large orders come in...

Code:
####################
#
#...

zeek

Active member
2019 Donor
I am very interested in this too, I found this thread where @mashume tried something for tick charts but i havn`t seen anything working for time based charts. If anyone has a working BAVOL script for time charts, please share.
 

cesarword

New member
I think you have to declare a period of time other wise doesn't work try this:

You can change the agregation period to any time frame just do it in this format AggregationPeriod.MIN, AggregationPeriod.TWO_MIN, AggregationPeriod.THREE_MIN.

Code:
def ASK = tick_count(priceType = PriceType.ASK , period =AggregationPeriod.FIFTEEN_MIN);
def BID = tick_count(priceType = PriceType.BID , period =AggregationPeriod.FIFTEEN_MIN);
plot ba= ASK-BID;
 
Last edited:

YungTraderFromMontana

Well-known member
Nope. I would be very interested in this if you could find the solution, I've been trading M and NIO on tick charts and want any edge I can get.
Also @mashume is there a way to get a plot of ticks per minute as a lower indicator? I feel like I could find that useful also as a way to gauge increased activity. A formula for that could be something along the lines of (last 10 min/ total ticks in last 10 min) or any choice of time. Hopefully it is possible.
 

mashume

Well-known member
VIP
Does this come close to what you're interested in? You can remove the first label if you want as it's really there as a sanity check for me.

Code:
####################
#
# Ticks Per Minute for Time Charts
#
# Mashume via UseThinkScript
# 2020-08-17
#
####################
declare lower;
declare zerobase;

def timeframe = getAggregationPeriod() / 60000;

addLabel(yes, concat("Min / Bar: ", timeframe));

def T = Tick_count;

plot TicksPerMinute =  T / Timeframe;

addLabel(yes, concat("Ticks / Min: ", TicksPerMinute), color.gray);

-mashume

Also, potentially of interest is this one, which plots a histogram of the average size of trades in a candle. It can be interesting to see when large orders come in...

Code:
####################
#
# Volume By Tick
#
# Mashume via UseThinkScript
# 2020-08-17
#
####################
declare lower;

def V = volume;
def T = Tick_count;

def tvb = (close - low) + (close - open) - (high - close);

def sign = if HL2 + tvb > HL2 then 1 else -1;

plot VolumePerTick = sign * V / T;
VolumePerTick.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
VolumePerTick.AssignValueColor(if VolumePerTick > 0 then Color.DARK_GREEN else Color.DARK_RED);
 
Solution

YungTraderFromMontana

Well-known member
@mashume Very great stuff, looks good. Thanks as usual. I didn't check them yet but I'll report back to see if they work or are useful.

The ticks per minute one doesn't work, I think it could be a great combo indicator though if you find out how. (Ticks per minute * Trade size per tick) = Idea of when the big boys are buying.

Correction, first one doesn't work on tick charts
 

Tony Stark

New member
@mashume this worked for me but I have an issue, how could the bars have a greater width? the bars with this code are tiny.

Good evening, why is the Level 2 Delay for 8 hours when programmed to be access with a Live Realtime data account.

Here is the code:

Code:
def ASK = tick_count(priceType = PriceType.ASK , period = AggregationPeriod.FIFTEEN_MIN);
def BID = tick_count(priceType = PriceType.BID , period = AggregationPeriod.FIFTEEN_MIN);
#plot ba= ASK-BID;
plot a = ASK;
a.SetLineWeight(1);
plot b = BID;
b.SetLineWeight(1);
 

mashume

Well-known member
VIP
@mashume this worked for me but I have an issue, how could the bars have a greater width? the bars with this code are tiny.

Good evening, why is the Level 2 Delay for 8 hours when programmed to be access with a Live Realtime data account.

Here is the code:

Code:
def ASK = tick_count(priceType = PriceType.ASK , period = AggregationPeriod.FIFTEEN_MIN);
def BID = tick_count(priceType = PriceType.BID , period = AggregationPeriod.FIFTEEN_MIN);
#plot ba= ASK-BID;
plot a = ASK;
a.SetLineWeight(1);
plot b = BID;
b.SetLineWeight(1);
If you haven't figured this out yet, you can try setting the LineWeight to 5. It takes an integer in the range of 1 to 5 with 5 being the widest.

-mashume
 

adamsj1267

New member
Ruby:
declare lower;
declare zerobase;

def A = A[1] + close;
def B = B[1] + close;


input length = 50;
plot Vol = volume;
plot VolAvg = Average(volume, length);

Vol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Vol.SetLineWeight(3);
Vol.DefineColor("Up", Color.UPTICK);
Vol.DefineColor("Down", Color.DOWNTICK);

Vol.AssignValueColor(if close > close[1] then Vol.color("Up") else if close < close[1] then Vol.color("Down") else GetColor(1));
VolAvg.SetDefaultColor(GetColor(8));

############
def countUP = if !IsNaN(A)
then 1
else if CLOSE > CLOSE[1]
then countUP[1] + 1
else if !IsNaN(B)
then 0
else countUP[1];

#TRYING TO ADD UP THE VOLUME FOR BUYERS AND SELLERS USING UPTICK OR DOWNTICK NEED HELP THANKS !!!
###############################

ADDLABEL(YES,"BUYERS "+ COUNTUP);

#ADDLABEL(YES,"BUYERS "+ COUNTUP,COLOR.GREEN);
#ADDLABEL(YES,"SELLERS "+ COUNTDN,COLOR.RED);
AddLabel(yes, "SELLERS:" + Vol[1]);
AddLabel(yes, "BUYERS:" + Vol);
 
Last edited by a moderator:

cos251

Well-known member
Ruby:
declare lower;
declare zerobase;

def A = A[1] + close;
def B = B[1] + close;


input length = 50;
plot Vol = volume;
plot VolAvg = Average(volume, length);

Vol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Vol.SetLineWeight(3);
Vol.DefineColor("Up", Color.UPTICK);
Vol.DefineColor("Down", Color.DOWNTICK);

Vol.AssignValueColor(if close > close[1] then Vol.color("Up") else if close < close[1] then Vol.color("Down") else GetColor(1));
VolAvg.SetDefaultColor(GetColor(8));

############
def countUP = if !IsNaN(A)
then 1
else if CLOSE > CLOSE[1]
then countUP[1] + 1
else if !IsNaN(B)
then 0
else countUP[1];

#TRYING TO ADD UP THE VOLUME FOR BUYERS AND SELLERS USING UPTICK OR DOWNTICK NEED HELP THANKS !!!
###############################

ADDLABEL(YES,"BUYERS "+ COUNTUP);

#ADDLABEL(YES,"BUYERS "+ COUNTUP,COLOR.GREEN);
#ADDLABEL(YES,"SELLERS "+ COUNTDN,COLOR.RED);
AddLabel(yes, "SELLERS:" + Vol[1]);
AddLabel(yes, "BUYERS:" + Vol);
This thread should have what you are looking for. Should be tick_count.

https://usethinkscript.com/threads/thinkorswim-bid-ask-volume-bavol-indicator.1542/

Another example of tick_count against alternate symbol.
https://tosindicators.com/indicators/cumulative-tick
 

Similar threads

Top