Volume Buy Sell Indicator with Hot Percent for ThinkorSwim

mashume

Well-known member
VIP
I'm sure this is around already... but I was curious to see how it looked. For /ES I needed to add a moving average...
Code:
declare lower;

input MALength = 8;

def IBSdef = if (High - Low) != 0 then (Close-Low)/(High-Low) else IBSdef[1];
plot IBS = IBSdef;
plot MA = SimpleMovingAvg(IBS, MALength);
plot overBought = 0.8;
plot overSold = 0.2;
plot attention = if MA > overBought or MA < OverSold then MA else double.nan;

IBS.SetDefaultColor(Color.GRAY);
MA.SetDefaultColor(Color.Dark_red);
Attention.SetDefaultColor(Color.Dark_red);
Attention.SetPaintingStrategy(PaintingStrategy.POINTS);
Attention.SetLineWeight(3);

overBought.SetDefaultColor(Color.Blue);
overBought.SetStyle(CURve.MEDIUM_DASH);
overSold.SetDefaultColor(Color.Blue);
overSold.SetStyle(CURve.MEDIUM_DASH);

-mashume
 

Pelonsax

Active member
VIP
Here's a Watchlist Column Mod I just made.

ISgSxyr.png


Code:
# Original author: Unknown
# Watchlist Label
# Mod by Ramon DV aka Pelonsax

declare lower;


def O = open;
def H = high;
def C = close;
def L = low;
def Price = H + L + C / 3;
def V = volume;
def buying = V * (C - L) / (H - L);
def selling = V * (H - C) / (H - L);
def SellVolPercent = Round((Selling / Volume) * 100, 0);
def BuyVolPercent = 100 - SellVolPercent;

assignBackgroundColor(if buying >= selling then color.GREEN else if buying <= selling then color.RED else color.white);
AddLabel(buying <= selling, "Sell %: "+SellVolPercent, color.black);
AddLabel(buying >= selling, "Buy %: "+BuyVolPercent, color.black);
 

Pelonsax

Active member
VIP
Is there a way to modify the script so i can use it in a watch list so i can watch the current buy bar and sell bar over multiple timeframes.
Code:
# Original author: Unknown
# Watchlist Label
# Mod by Ramon DV aka Pelonsax

declare lower;


def O = open;
def H = high;
def C = close;
def L = low;
def Price = H + L + C / 3;
def V = volume;
def buying = V * (C - L) / (H - L);
def selling = V * (H - C) / (H - L);
def SellVolPercent = Round((Selling / Volume) * 100, 0);
def BuyVolPercent = 100 - SellVolPercent;

assignBackgroundColor(if buying >= selling then color.GREEN else if buying <= selling then color.RED else color.white);
AddLabel(buying <= selling, "Sell %: "+SellVolPercent, color.black);
AddLabel(buying >= selling, "Buy %: "+BuyVolPercent, color.black);
 

stone

Member
@zeek

Code:
#Advanced Volume Study
#[email protected]
#v5.22.2020
declare upper;
input ShowBuySellStrength = yes;
input TickLevel = 1000;
input ShowTickLabel = yes;


def NA = Double.NaN;
def PriceRange = high - low;

#Current Candle Buy and Sell Strength
def BuyStr = ((close - low) / PriceRange) * 100;
def SellStr = ((high - close) / PriceRange) * 100;


#$TICK Vertical Lines
def tickc = close("$TICK");
def tickh = high("$TICK");
def tickl = low("$TICK");

#$TICK Label
AddLabel(if ShowTickLabel then 1 else 0,"$TICK: " + tickc, if tickc > 0 then Color.GREEN else Color.RED);

def trinRatio = Round(close(symbol="$TRIN"),2);
def trinOverlyBearish = if trinRatio >= 2 then 1 else 0;
def trinOverlyBullish = if trinRatio <= 0.5 then 1 else 0;
AddLabel(yes, "$TRIN: "+trinRatio, if trinOverlyBearish then color.green else if trinOverlyBullish then color.red else color.gray);

def pcallRatio = Round(SimpleMovingAvg(close(symbol="$PCALL"),10),2);
def pcallOverlyBearish = if pcallRatio >= 1 then 1 else 0;
def pcallOverlyBullish = if pcallratio <= 0.85 then 1 else 0;
AddLabel(yes, "$PCALL: "+pcallRatio, if pcallOverlyBearish then color.green else if pcallOverlyBullish then color.red else color.gray);

#current candle Buy/Sell strength labels
#AddLabel(if ShowBuySellStrength then 1 else 0, " ", Color.black);
#AddLabel(if ShowBuySellStrength then 1 else 0, "1", Color.GRAY);
AddLabel(if ShowBuySellStrength then 1 else 0, "Sell " + Round(SellStr, 2) + "%", if SellStr > BuyStr then Color.RED else Color.DARK_RED);
AddLabel(if ShowBuySellStrength then 1 else 0, "Buy " + Round(BuyStr, 2) + "%", if BuyStr > SellStr then Color.GREEN else Color.DARK_GREEN);
 

stone

Member
@zeek

Code:
#Advanced Volume Study
#[email protected]
#v5.22.2020
declare upper;
input ShowBuySellStrength = yes;
input TickLevel = 1000;
input ShowTickLabel = yes;


def NA = Double.NaN;
def PriceRange = high - low;

#Current Candle Buy and Sell Strength
def BuyStr = ((close - low) / PriceRange) * 100;
def SellStr = ((high - close) / PriceRange) * 100;


#$TICK Vertical Lines
def tickc = close("$TICK");
def tickh = high("$TICK");
def tickl = low("$TICK");

#$TICK Label
AddLabel(if ShowTickLabel then 1 else 0,"$TICK: " + tickc, if tickc > 0 then Color.GREEN else Color.RED);

def trinRatio = Round(close(symbol="$TRIN"),2);
def trinOverlyBearish = if trinRatio >= 2 then 1 else 0;
def trinOverlyBullish = if trinRatio <= 0.5 then 1 else 0;
AddLabel(yes, "$TRIN: "+trinRatio, if trinOverlyBearish then color.green else if trinOverlyBullish then color.red else color.gray);

def pcallRatio = Round(SimpleMovingAvg(close(symbol="$PCALL"),10),2);
def pcallOverlyBearish = if pcallRatio >= 1 then 1 else 0;
def pcallOverlyBullish = if pcallratio <= 0.85 then 1 else 0;
AddLabel(yes, "$PCALL: "+pcallRatio, if pcallOverlyBearish then color.green else if pcallOverlyBullish then color.red else color.gray);

#current candle Buy/Sell strength labels
#AddLabel(if ShowBuySellStrength then 1 else 0, " ", Color.black);
#AddLabel(if ShowBuySellStrength then 1 else 0, "1", Color.GRAY);
AddLabel(if ShowBuySellStrength then 1 else 0, "Sell " + Round(SellStr, 2) + "%", if SellStr > BuyStr then Color.RED else Color.DARK_RED);
AddLabel(if ShowBuySellStrength then 1 else 0, "Buy " + Round(BuyStr, 2) + "%", if BuyStr > SellStr then Color.GREEN else Color.DARK_GREEN);
Hi, I was wondering with the $TICK Label in this code how could it be motified to show the constant tick numbers? I noticed its a black label unless on Daily time frame. I would like the grey label to be showing $TICK numbers on all time frames. I do like red/grn variation if it meets the criteria. I appreciate your help & Thank you for all you guys/gals do!
 

stone

Member
Hi, I was wondering with the $TICK Label in this code how could it be motified to show the constant tick numbers? I noticed its a black label unless on Daily time frame. I would like the grey label to be showing $TICK numbers on all time frames. I do like red/grn variation if it meets the criteria. I appreciate your help & Thank you for all you guys/gals do!
This works great during market hours. my mistake, plz disregard.
 

mansor

Active member
is there a column "Avg 30 days volume" that I can add on my watch list & can see avg (N= number of days) volume? I see avg 30days volume on the label, but I need it in a column please. Thanks in advance
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.

2019-12-30-TOS-CHARTS.png


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);
@Pelonsax how can I have "Average 30 days volume" in a column please, just how it is in presented the label. Thanks
 
Last edited:

mansor

Active member
@mansor Are you looking for a true 30 days or 22 days which is a month of trading days...???
thanks for replying @rad14733. Good Q, I am not sure if horserider is using 30 days or true 22 days average. Would it be possible to have number of days set to a variable =N, that can be changed if needed? thanks in advance
 

stone

Member
Here's a Watchlist Column Mod I just made.

ISgSxyr.png


Code:
# Original author: Unknown
# Watchlist Label
# Mod by Ramon DV aka Pelonsax

declare lower;


def O = open;
def H = high;
def C = close;
def L = low;
def Price = H + L + C / 3;
def V = volume;
def buying = V * (C - L) / (H - L);
def selling = V * (H - C) / (H - L);
def SellVolPercent = Round((Selling / Volume) * 100, 0);
def BuyVolPercent = 100 - SellVolPercent;

assignBackgroundColor(if buying >= selling then color.GREEN else if buying <= selling then color.RED else color.white);
AddLabel(buying <= selling, "Sell %: "+SellVolPercent, color.black);
AddLabel(buying >= selling, "Buy %: "+BuyVolPercent, color.black);
This is so cool - Amazing
 

stone

Member
I've tried via studies, then did a scan and created custom. Says something about Ad Label, took that out but keeps saying the same think. I feel like I'm not entering in the right spot?
 

SoXoS

New member
@Pelonsax how would you write a scanner that looks at anything over a certain percentage on a particular timeframe? cant seem to scan anything other than the daily even when i change the code...
 

Similar threads

Top