Volume Buy Sell Indicator with Hot Percent for ThinkorSwim

J007RMC

J007RMC

Active member
2019 Donor
VIP
I apologize for having to delete this chart will reshare
comparison volume. Forgot I had proprietary stuff on the original share
https://tos.mx/yEzhgNN
 
Last edited:
A

alphabeta

Member
Volume indicator showing total, buy, and sell volumes as a histogram. Also average volume as a line plot. Bars with a specified percent over the average volume are marked on the bar. Additional Volume information provided by labels.
Rework of the previous study to show better representation of what volume is doing. Please consider replacing the old study if you are using it.



Code:
# Show total volume in gray.  Buying volume in green.  Sell Volume in red.
# Volume average is gray line.
# Specified percent over average volume is cyan triangles.
# Horserider 12/30/2019 derived from some already existing studies.


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

# Total Volume

# Note that Selling + Buying Volume = Volume.
plot TV =  volume;

TV.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
TV.SetDefaultColor(Color.GRAY);
#TV.HideTitle();
#TV.HideBubble();
TV.SetLineWeight(1);

Plot BuyVol = buying;
BuyVol.setPaintingStrategy(PaintingStrategy.Histogram);
BuyVol.SetDefaultColor(Color.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 = 20;
plot VolAvg = Average(volume, length);

VolAvg.SetDefaultColor(GetColor(7));


# hiVolume indicator
# source: http://tinboot.blogspot.com
# author: allen everhart


input type = { default SMP, EXP } ;
input length1 = 20 ;
input hotPct = 100.0 ;

def ma =
if type == type.SMP then
SimpleMovingAvg(volume, length)
else
MovAvgExponential(volume, length);

plot hv =
if 100 * ((volume / ma) - 1) >= hotPct then
ma
else
Double.NaN;

hv.SetDefaultColor( Color.CYAN);
hv.SetLineWeight(1) ;
hv.SetPaintingStrategy( PaintingStrategy.TRIANGLES);
@tomsk hi, is it possible for this script to show alert when todays volume is for example above 300% then average volume thank you so much in advance
 
T

tomsk

Well-known member
VIP
@tomsk hi, is it possible for this script to show alert when todays volume is for example above 300% then average volume thank you so much in advance

Sure thing, it's all math. All you need to do is to add the following statement to the end of that study. It will generate an alert when today's volume goes above 300% of average volume

Code:
Alert(today/volLast30DayAvg > 3, "Volume above 300% threshold", Alert.BAR, Sound.Ring);
 
S

San

Member
2019 Donor
@San Sorry No idea what you are saying. Sorry I do not know how to "truncate" the volume spikes.
For your your reference and understanding purpose. Please load this https://tos.mx/OHye53  indicator , Found in "onedrive.live.com" So this one length of this bar never change if you move left or right.

If you have time please apply same on our indicator."Volume Buy Sell Indicator with Hot Percent "
 
horserider

horserider

Well-known member
VIP
@San The study you refer to is plotted on a 0 to 1 scale. Do you really want a volume plot from 0 to 1 ?
 
A

alphabeta

Member
Sure thing, it's all math. All you need to do is to add the following statement to the end of that study. It will generate an alert when today's volume goes above 300% of average volume

Code:
Alert(today/volLast30DayAvg > 3, "Volume above 300% threshold", Alert.BAR, Sound.Ring);
thank you so much! appreciate it!
 
S

San

Member
2019 Donor
@San The study you refer to is plotted on a 0 to 1 scale. Do you really want a volume plot from 0 to 1 ?
Hey I don't know the script knowledge and I am not techie, I am looking same kind of view :)
 
U

UT2Pro1689

New member
Thanks all for sharing and extending the interesting volume buy sell scripts.

Can someone shed some lights on how to use the buying volume and selling volume as part of entrance and exit signals? A reference link would be greatly appreciated as well.

When looking at the buying/selling volume formula, I don't feel really comfortable that a gap-up day may be treated as a selling predominantly if there is a big distance from high to close. Similar concern exists for a gap-down day.

So, I tried to replace the following two lines in the script with 4 new lines as shown below.

#Replace the two lines below to accommodate unfilled gaps
#def buying = V*(C-L)/(H-L);
#def selling = V*(H-C)/(H-L);

# Unfilled Gap down: Use prior close as high
def equivHi = if H < C[1] then C[1] else H;
# Unfilled Gap up: Use prior close as low
def equivLo = if L > C[1] then C[1] else L;

def buying = V*(C-equivLo)/(equivHi-equivLo);
def selling = V*(equivHi-C)/(equivHi-equivLo);

I got slightly different plots. My goal is to include the gaps from prior day close in the calculation using the following logic's. Does this modification make any sense for your folks? Comments are appreciated.

Buy Volume = Rise x Volume / Price Range
Sell Volume = Drop x Volume/ Price Range
Buy Volume + Sell Volume = Total Volume
Rise + Drop = Price Range = High - Low
Rise = Close – Low
Drop = High – close


In case of Gap down

Price Range = eqHigh - Low
= Equivalent High – Low,

Equi High = if high < close[1] then close[1] else high

Drop = eqHigh – Close
Rise = Close – Low

In case of Gap up

Price Range = High - eqLow
= High - Equivalent Low

Equi Low = if Low > close[1] then close[1] else Low

Drop = High – Close
Rise = Close – eqLow
 
D

Derrick

New member
Great indicator. But what I don't like is that gray bar as the total volume for each bar. It is a bit confusing. Why is that necessary? Why not using only a red and green bar?
 
C

Corpus

New member
Hi horserider, I tried out this volume indicator and I like it. I'm new to ToS with no programming background and I'm trying to understand how this study is approximating Sell vs. Buy volume.

Looking at the pertinent thinkscript in the study:

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

It appears buying and selling volume is being approximated by taking the true candle volume and applying a ratio so that a close far removed from the low would equate to "strong buying" and conversely a close far removed from the high would equate to "strong selling".

The thing I don't understand is how the volume bar updates in real time as I'm using the study since a "C=close" is required in the formula? As trades keep coming in during say a 2 minute candle interval, does ToS keep dynamically updating the "C=close" value so that's why I see the volume bar updating the green and red portions in real time?

Also, I like to try to see as much information in the smallest amount of space so I swapped the "declare lower;" with "declare on_volume;" so that I could get this study showing in the chart window via the "Overlap volume" chart setting.

With "overlap volume", the normal/native ToS volume bars show behind the chart. However, with this study added, the volume bars are displaying in front of the chart. I tried to tinker with "input opacity = 50; " to see if I could get the volume bars to fade but that did not do anything. Would you happen to know if there is a way to enforce an opacity on the volume bars and/or make the volume bars display behind the candlestick chart?

I am thinking that if I apply a factor to the buying and selling plots (ie. Plot BuyVol = 0.4*buying; ), and have the ability to put the volume behind the candlestick chart or use an opacity, I could use this study quite well in the chart window via overlap volume. Thanks so Much --- Corpus.
 
D

Derrick

New member
I want to create a sound alert for a scanner, for any of the stocks the scan finds reaching a certain condition: 1-min vol bar higher than 30K for stocks between 1 and 5$.

I always see volume alerts related to percentage change. But how would you create an alert sound for a 1-min bar higher than 30K?
 
zeek

zeek

Active member
2019 Donor
I have been thinking about an idea for a script that uses the methodology from the study in this thread, namely the analysis of buying vs. selling volume but instead analyzing each bar, i am interested to know if there is a way to analyze the whole trading day (intraday) and display this buying vs selling ratio in % as a chart label?

Basically, i want to know how much was bought vs sold of the total intraday volume and if the buying was above 50%, the label should be colored green and vice versa, if the selling volume was above 50%, then color the label red.

I would also be very interested to have a label showing this volume data for the last hour.

Do you think this would be possible to build? @horserider
 
C

Craighaber71

Active member
2019 Donor
VIP
Is there a script for the chart cloud
 
horserider

horserider

Well-known member
VIP
@zeek It already shows volume for the day and what % that is of the 30 day average. It shows volume for last 30 bars so use a 2 min chart and that should be volume for last hour. Maybe that helps with some of what you want. Not sure.
What you want is most likely possible. I have no interest in it, sorry.
 
horserider

horserider

Well-known member
VIP
@Craighaber71 That is EHMA and price cloud. Was playing with it, not sure I have it any longer.
 
zeek

zeek

Active member
2019 Donor
@zeek It already shows volume for the day and what % that is of the 30 day average. It shows volume for last 30 bars so use a 2 min chart and that should be volume for last hour. Maybe that helps with some of what you want. Not sure.
What you want is most likely possible. I have no interest in it, sorry.
Ok, was just wondering if it’s possible and i hope someone else here could give it a try.

To clarify what i am looking for is not a comparison of todays volume vs 30day average but instead, i am interested to know how much of the intraday buying volume is bought on the offers vs bids and vice versa, how much of the sell volume is sold on the bids vs offers. Having a label that shows me this ratio between buying vs selling i think can be very useful to see who is in control when a stock is moving up or down fast.

I have very little knowledge in thinkscript coding but i am thinking that because there is obviously already a way to analyze this ratio for each bar so there should be a way to summarize all this into a total buying vs selling ratio for the whole day. But i am just speculating here so if anyone here could give this a try, i would appreciate it very much.
 
Pinkicle

Pinkicle

New member

Hi guys. Is there any code to show the indicator behind the candlestick?
Reason for this is because I have only 2 small monitors to display few charts together.
Trying to google thinkscript but cant find any related solution.
 
M

mansor

Member
@zeek That would be very very interesting, esp if that can be sorted out on hourly or 30m. How many shares were sold & bought & what % were offers/bids.

green label with white fonts: 51% vol 826392 1h -if offers executed 51% out of x amount of offers in 30m or 60m, # of shares, time range.
red label red white fonts: 51% vol 857331 1h - if bids executed 51% out of x amount of bids in 30m or 60m, # of shares. time range.

Something along these lines, I guess..I'm no coder..but I think I like the thought process behind it..
 
zeek

zeek

Active member
2019 Donor
Yeah, i think it can be useful in several ways but the main interest for me is to see when there is a switch between supply/demand on intraday trending stocks, let’s say stock ABC is trending upwards in the morning and the buy ratio is 70/30 so 70% of the total buying volume since the open were bought on the offers and the sell ratio is 40/60 so 40% of the selling volume were sold on the bids.

But then there is a change in the ratios and the buy volume goes 50/50 so now we have equal amount of buying volume on bids vs offers and this can be a good indicator for a trend reversal when buyers dry up on the offers & sellers gets more aggresive and starts hitting the bids. So basically, one label for buying volume and one label for selling volume.

And i agree that it would also be very useful to have this data for the last hour or 30min.
 
Top