Buy and Sell Volume Pressure Indicator for ThinkorSwim

Paul Bunion

Paul Bunion

New member
Here is a volume indicator that I like to use in everyday trading. it really helps with identifying who is in control.

Code:
# Original author: Unknown
# Modified by 7of9

declare lower;

#Inputs

input Show30DayAvg = yes;
input ShowTodayVolume = yes;
input ShowPercentOf30DayAvg = yes;
input UnusualVolumePercent = 200;
input Show30BarAvg = yes;
input ShowCurrentBar = yes;
input ShowPercentOf30BarAvg = yes;
input ShowSellVolumePercent = yes;

def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;
def buying = V*(C-L)/(H-L);
def selling = V*(H-C)/(H-L);

# Selling Volume

Plot SellVol = selling;
SellVol.setPaintingStrategy(PaintingStrategy.Histogram);
SellVol.SetDefaultColor(Color.Red);
SellVol.HideTitle();
SellVol.HideBubble();
SellVol.SetLineWeight(5);

# Total Volume

Plot BuyVol = volume;
BuyVol.setPaintingStrategy(PaintingStrategy.Histogram);
BuyVol.SetDefaultColor(Color.Dark_Green);
BuyVol.HideTitle();
BuyVol.HideBubble();
BuyVol.SetLineWeight(5);

#Volume Data

def volLast30DayAvg = (volume(period = "DAY")[1] + volume(period = "DAY")[2] + volume(period = "DAY")[3] + volume(period = "DAY")[4] + volume(period = "DAY")[5] + volume(period = "DAY")[6] + volume(period = "DAY")[7] + volume(period = "DAY")[8] + volume(period = "DAY")[9] + volume(period = "DAY")[10] + volume(period = "DAY")[11] + volume(period = "DAY")[12] + volume(period = "DAY")[13] + volume(period = "DAY")[14] + volume(period = "DAY")[15] + volume(period = "DAY")[16] + volume(period = "DAY")[17] + volume(period = "DAY")[18] + volume(period = "DAY")[19] + volume(period = "DAY")[20] + volume(period = "DAY")[21] + volume(period = "DAY")[22] + volume(period = "DAY")[23] + volume(period = "DAY")[24] + volume(period = "DAY")[25] + volume(period = "DAY")[26] + volume(period = "DAY")[27] + volume(period = "DAY")[28] + volume(period = "DAY")[29] + volume(period = "DAY")[30]) / 30;
def today = volume(period = "DAY");
def percentOf30Day = Round((today / volLast30DayAvg) * 100, 0);
def avg30Bars = (volume[1] + volume[2] + volume[3] + volume[4] + volume[5] + volume[6] + volume[7] + volume[8] + volume[9] + volume[10] + volume[11] + volume[12] + volume[13] + volume[14] + volume[15] + volume[16] + volume[17] + volume[18] + volume[19] + volume[20] + volume[21] + volume[22] + volume[23] + volume[24] + volume[25] + volume[26] + volume[27] + volume[28] + volume[29] + volume[30]) / 30;
def curVolume = volume;
def percentOf30Bar = Round((curVolume / avg30Bars) * 100, 0);
def SellVolPercent = Round((Selling / Volume) * 100, 0);

# Labels

AddLabel(Show30DayAvg, "Avg 30 Days: " + Round(volLast30DayAvg, 0), Color.LIGHT_GRAY);

AddLabel(ShowTodayVolume, "Today: " + today, (if percentOf30Day >= UnusualVolumePercent then Color.GREEN else if percentOf30Day >= 100 then Color.ORANGE else Color.LIGHT_GRAY));

AddLabel(ShowPercentOf30DayAvg, percentOf30Day + "%", (if percentOf30Day >= UnusualVolumePercent then Color.GREEN else if percentOf30Day >= 100 then Color.ORANGE else Color.WHITE) );

AddLabel(Show30BarAvg, "Avg 30 Bars: " + Round(avg30Bars, 0), Color.LIGHT_GRAY);

AddLabel(ShowCurrentBar, "Cur Bar: " + curVolume, (if percentOf30Bar >= UnusualVolumePercent then Color.GREEN else if PercentOf30Bar >= 100 then Color.ORANGE else Color.LIGHT_GRAY));

AddLabel(ShowPercentOf30BarAvg, PercentOf30Bar + "%", (if PercentOf30Bar >= UnusualVolumePercent then Color.GREEN else if PercentOf30Bar >= 100 then Color.ORANGE else Color.WHITE) );

AddLabel(ShowSellVolumePercent, "Cur Bar Sell %: " + SellVolPercent, (if SellVolPercent > 51 then Color.RED else if SellVolPercent < 49 then Color.GREEN else Color.ORANGE));

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));

Video Tutorial

 
Last edited by a moderator:
D

devnoir

New member
2019 Donor
Can we take this down? Or at least modify the comment up top so it doesn't credit 7of9. This is just a slightly modified study thats been available on the web for a while. 7of9 is a known code thief.

The original author is unknown.
 
Last edited by a moderator:
BenTen

BenTen

Administrative
Staff
VIP
@devnoir Thank you. I made some adjustments to the script above.
 
G

GeneHo

New member
2019 Donor
Hi,
Anyone to share a script or command line to read current bar volume, thanks.
 
B

bsizzle101

New member
Can anyone help me with this Volume Stat Indicator I found? I would like it to show me the percentage of the current bar against the 30 bar avg.
ie: if the avg 30 bar is 6000 and the current bar is 1500 it would show 25% ect..ect..

Code:
declare lower;

#Inputs
input Show30DayAvg = yes;
input ShowTodayVolume = yes;
input ShowPercentOf30DayAvg = yes;
input UnusualVolumePercent = 200;
input Show30BarAvg = yes;
input ShowCurrentBar = yes;


#Volume Data
def volLast30DayAvg = (volume(period = "DAY")[1] + volume(period = "DAY")[2] + volume(period = "DAY")[3] + volume(period = "DAY")[4] + volume(period = "DAY")[5] + volume(period = "DAY")[6] + volume(period = "DAY")[7] + volume(period = "DAY")[8] + volume(period = "DAY")[9] + volume(period = "DAY")[10] + volume(period = "DAY")[11] + volume(period = "DAY")[12] + volume(period = "DAY")[13] + volume(period = "DAY")[14] + volume(period = "DAY")[15] + volume(period = "DAY")[16] + volume(period = "DAY")[17] + volume(period = "DAY")[18] + volume(period = "DAY")[19] + volume(period = "DAY")[20] + volume(period = "DAY")[21] + volume(period = "DAY")[22] + volume(period = "DAY")[23] + volume(period = "DAY")[24] + volume(period = "DAY")[25] + volume(period = "DAY")[26] + volume(period = "DAY")[27] + volume(period = "DAY")[28] + volume(period = "DAY")[29] + volume(period = "DAY")[30]) / 30;
def today = volume(period = "DAY");
def percentOf30Day = Round((today / volLast30DayAvg) * 100, 0);
#def avg30Bars = VolumeAvg(30).VolAvg;
def avg30Bars = (volume[1] + volume[2] + volume[3] + volume[4] + volume[5] + volume[6] + volume[7] + volume[8] + volume[9] + volume[10] + volume[11] + volume[12] + volume[13] + volume[14] + volume[15] + volume[16] + volume[17] + volume[18] + volume[19] + volume[20] + volume[21] + volume[22] + volume[23] + volume[24] + volume[25] + volume[26] + volume[27] + volume[28] + volume[29] + volume[30]) / 30;
def curVolume = volume;


# Labels
AddLabel(Show30DayAvg, "Daily Avg: " + Round(volLast30DayAvg, 0), Color.LIGHT_GRAY);
AddLabel(ShowTodayVolume, "Today: " + today, (if percentOf30Day >= UnusualVolumePercent then Color.GREEN else if percentOf30Day >= 100 then Color.ORANGE else Color.LIGHT_GRAY));
AddLabel(ShowPercentOf30DayAvg, percentOf30Day + "%", (if percentOf30Day >= UnusualVolumePercent then Color.GREEN else if percentOf30Day >= 100 then Color.ORANGE else Color.WHITE) );
AddLabel(Show30BarAvg, "Avg 30 Bars: " + Round(avg30Bars, 0), Color.LIGHT_GRAY);
AddLabel(ShowCurrentBar, "Cur Bar: " + curVolume, (if curVolume >= avg30Bars then Color.GREEN else Color.ORANGE));
 
P

Poc

New member
Can we take this down? Or at least modify the comment up top so it doesn't credit 7of9. This is just a slightly modified study thats been available on the web for a while. 7of9 is a known code thief.

The original author is unknown.
This link goes to the TOS how to page. Is it supposed to link the indicator that BenTen modified? Thanks.
 
A

alphabeta

Member
hi paul thanks for sharing
is it possible to make alert when current bat volume is for example above 200 %
 
horserider

horserider

Well-known member
VIP
@alphabeta Make sure you understand the output of this study. The bars are total volume. The red is selling volume.
 
A

astrokjackk1

New member
VIP
Hi everyone, I am no coder and I don’t really know how to set up a decent scan on tos so I want to ask the community to see if I can get some help.
the scan needs to include the following:
AVG daily volume (preferably of the past 180 days)
- this will let us know how much volume is traded on an average basis.
Volume % (how much volume has been traded in the premarket)
- this will let us know how much volume has been accumulated in the premarket in % correlation to average daily volume
Gap % (this will allow us to determine if we should expect volatility intraday)
- high percentage gaps usually coincide with high volatility intraday

thank you to anyone in advance who helps out.
 
Last edited:
R

Regalo

New member
@BenTen (or whoever can help me ) , can you help me by making a small modification to the script?

I'm trying to get it to show me the histogram as follows: https://ibb.co/qyBLsHb
(i cant insert images, i got this: "Something went grong. Please try again or contact the administrator.")


The logic would be:

If the current candle is larger than the previous one and "Buying" volume (according to the code published in this post) is greater than 60% of the total volume, then paint the candle green, otherwise it's gray.

The same for the Red candle.
If the current candle is Larger than the previous one and "Selling" volume (according to the code published in this post) is greater than 60% of the total volume, then paint the candle red, otherwise it's grey.

Thanks you!
 
horserider

horserider

Well-known member
VIP
@Regalo First understand in the study posted at top of the thread what is being defined as "Buying" volume. It is also plotting volume twice.
 
Y

yusef

New member
@BenTen (or whoever can help me ) , can you help me by making a small modification to the script?

I'm trying to get it to show me the histogram as follows: https://ibb.co/qyBLsHb
(i cant insert images, i got this: "Something went grong. Please try again or contact the administrator.")


The logic would be:

If the current candle is larger than the previous one and "Buying" volume (according to the code published in this post) is greater than 60% of the total volume, then paint the candle green, otherwise it's gray.

The same for the Red candle.
If the current candle is Larger than the previous one and "Selling" volume (according to the code published in this post) is greater than 60% of the total volume, then paint the candle red, otherwise it's grey.

Thanks you!
Did you found anything, i am looking for exctaly that you?...thanks
 
S

spm009

Member
I have a slight issue with this indicator, which is otherwise great. Basically this indicator overlaps the standard volume indicator. For some reason it seems to have an offset where the custom indicator starts at 25 instead of zero, so you see a little bit of the standard volume indicator below/behind it. How can I fix this?


host image
 
BenTen

BenTen

Administrative
Staff
VIP
@spm009 Drag the custom indicator to the lower study section. Don’t overlap them. If you need to remove the default volume section, then go to Settings > Equities > Disable Volume.
 
H

HighBredCloud

Active member
VIP
@spm009 You can use what @BenTen OR you IF you are still running the the default background color just change the color of the standard volume bars to 1B1B1B...that will paint over them making them invisible. I would also check this volume study as well...works better IMO.

 
S

solaris

New member
I use a Volume Label on my chart that tells me how much Volume is on the Buy versus the sell side. For instance in order for me see how much volume the equity has i have to add up the buy and sell side to get a running total. I was wondering if there's a better way to use this code. Any help you could provide would be greatly appreciated.

Thanks


Code:
#declare lower;
input overBought = 400;
input OverSold = 200;
input period = AggregationPeriod.Day;

def O = open(period = period);
def H = high(period = period);
def C = close(period = period);
def L = low(period = period);
def V = volume(period = period);



# Selling Volume
def SV = -V * (H - C) / (H - L);



def O1 = open(period = period);
def H1 = high(period = period);
def C1 = close(period = period);
def L1 = low(period = period);
def V1 = volume(period = period);

# Buying Volume
def BV = V1 * (C1 - L1) / (H1 - L1);

plot VolAvg = Average(volume(period = period));


VolAvg.SetPaintingStrategy(PaintingStrategy.LINE);
VolAvg.SetLineWeight(2);
VolAvg.DefineColor("Up", Color.UPTICK);
VolAvg.DefineColor("Down", Color.DOWNTICK);
VolAvg.AssignValueColor(if close > close[1] then VolAvg.Color("Up") else if close < close[1] then VolAvg.Color("Down") else GetColor(1));
VolAvg.SetDefaultColor(GetColor(8));
plot OB = overBought;
plot OS = OverSold;
AddLabel(yes, "DailyBuyVolume " + BV, color.green);
AddLabel(yes, "DailySellVolume " + SV, Color.white);


#AddLabel(yes, "DailyVolume " + BV, if BV > SV then #Color.green else
#Color.GRAY);
#AddLabel(yes, "DailySellVolume " + SV, if SV < BV #then Color.White else
#Color.GRAY);


#lash
 
Last edited by a moderator:
mckenzieatix

mckenzieatix

New member
VIP
@Paul Bunion Cool I use a different version of this. I actually found it from a guy called Enigma from Enhanced Investors Discord Community. I see it updated from mine however and going to look through the new code. WATCH ME

If anyone ever gets a hold of him let me know.
 
Top