Volume Buy Sell Indicator with Hot Percent for ThinkorSwim

J007RMC

J007RMC

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

alphabeta

New member
Warehouse
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 http://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

New member
Warehouse
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?
 
horserider

horserider

Well-known member
VIP
Why would you not want to know total volume for a candle?
 
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?
 

Top