Volume Stats Format, Watchlist, Scan, Label for ThinkOrSwim

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

@SuryaKiranC

Code:
## Volume Labels
# Version 1.5.3
# Created: 06/23/20 # Modified on 08/26/20

# Modified by: Surya Kiran C ## Included rVolume label and Changed length as input. ## Additionally Pre-Market, 1Hr Volume, AfterHour, 5 Day Volume labels are added.

# Version 1.5 Changes
# Change 1) Higher Time Frame Buying Vs Selling, Please make sure to configure VolPeriod higher than typical chart frame used.
# Change 2) Added 30Day Average White Line to VolumeBar, for 1Y 1D, and a 30BarAvg line for lower timeframes, Just to indicate if the current bar is above or below Average line.
# Version 1.5.1 Changes.
# Minor, Higher timeframe has labels indicating the timeframe.
# Version 1.5.2 Changes.
# Change 1) Minor, Daily and Previous day volumes converted to Millions with round(2), easier to read than counting the digits on running volume during trading hours.
# Change 2) Fixed color code issue with previous DayVolume, now we code Day/previousDay volumes to lime if they are less then corrospondant previous day and higher than 30DAvg.
#Version 1.5.3 Changes
# Added Avg % of Buying selling for 30Bar
# Added New 6 Bar stats for comaprision against 30Bar


declare on_volume; # Declared on_volume, if you need to use only labels as a top study comment # Selling Volume # & # Buying Volume # along with this line.

#Inputs

input length = 30;
input Barlength = 6;


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 VolStatsPeriod = (if GetAggregationPeriod() == AggregationPeriod.DAY then AggregationPeriod.WEEK else AggregationPeriod.DAY);

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

def AvgBars = Average(volume[1], length);
def AvgBars2 = Average(volume[1], Barlength);

##################
# Selling Volume #
##################
plot SVol = Selling;
SVol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
SVol.SetDefaultColor(Color.dARK_ORANGE);
SVol.HideTitle();
SVol.HideBubble();
SVol.SetLineWeight(5);

#################
# Buying Volume #
#################
plot BVol = Buying;
BVol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
BVol.SetDefaultColor(Color.light_GREEN);
BVol.HideTitle();
BVol.HideBubble();
BVol.SetLineWeight(5);

################################
#         6BAR                 #
################################
def HH6 = Average(high[1], Barlength);
def HC6 = Average(close[1], Barlength);
def HL6 = Average(low[1], Barlength);
def HV6 = Average(volume[1], Barlength);

def  Buy6 = HV6 * (HC6 - HL6) / (HH6 - HL6);
def Sell6 = HV6 * (HH6 - HC6) / (HH6 - HL6);

################################
#         30BAR                #
################################
#def HH30 = (fold B30H = 1 to length + 1 with i30H = 0 do (i30H + high[B30H]));
#def HC30 = (fold B30C = 1 to length + 1 with i30C = 0 do (i30C + close[B30C]));
#def HL30 = (fold B30L = 1 to length + 1 with i30L = 0 do (i30L + low[B30L]));
#def HV30 = (fold B30V = 1 to length + 1 with i30V = 0 do (i30V + volume[B30V]));

def HH30 = Average(high[1], length);
def HC30 = Average(close[1], length);
def HL30 = Average(low[1], length);
def HV30 = Average(volume[1], length);

def Buy30 = HV30 * (HC30 - HL30) / (HH30 - HL30);
def Sell30 = HV30 * (HH30 - HC30) / (HH30 - HL30);

###############################################
# For Higher Frame UPTICK / DOWNTICK CRITERIA #
###############################################
def HH = high (period = VolStatsPeriod);
def HC = close (period = VolStatsPeriod);
def HL = low (period = VolStatsPeriod);
def HV = volume (period = VolStatsPeriod);
def HBuying = HV * (HC - HL) / (HH - HL);
def HSelling = HV * (HH - HC) / (HH - HL);


#####################
# Higher Volume %   #
#####################
def HtotVol = Round(HBuying, 0) + Round(HSelling, 0) ;
def HbuyPercent  = ( Round(HBuying, 0)  / HtotVol ) * 100;
def HsellPercent = ( Round(HSelling, 0) / HtotVol ) * 100;

#####################
# 6Bar Volume %   #
#####################
def H6Vol = Round(Buy6, 0) + Round(Sell6, 0) ;
def H6buyPercent  = ( Round(Buy6, 0)  / H6Vol ) * 100;
def H6sellPercent = ( Round(Sell6, 0) / H6Vol ) * 100;

#####################
# 30Bar Volume %   #
#####################
def H30Vol = Round(Buy30, 0) + Round(Sell30, 0) ;
def H30buyPercent  = (Round(Buy30, 0)  / H30Vol) * 100;
def H30sellPercent = (Round(Sell30, 0) / H30Vol) * 100;


#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, "30D: " + Round(volLast30DayAvg * .000001, 1) + " M", Color.LIGHT_GRAY);

AddLabel(ShowTodayVolume, "D: " + Round(today * .000001, 1) + " M", (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, "30Bar: " + Round(avg30Bars * .001, 1) + " K", Color.LIGHT_GRAY);

AddLabel(ShowCurrentBar, "CurBar: " + Round(curVolume * .001, 1) + " K", (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) );


############################################ 30 Bar Stats ############################################
input Show30Bar = yes;

AddLabel(Show30Bar, length + "BarSell: " + Round(H30sellPercent, 0) + "% ", (if H30sellPercent > 55 then Color.RED else if H30sellPercent < 45 then Color.GREEN else Color.ORANGE));


############################################ 6 Bar Stats ############################################
input Show6Bar = yes;

AddLabel(Show6Bar, Barlength +"BarSell: " + Round(H6sellPercent, 0) + "% ", (if H6sellPercent > 55 then Color.RED else if H6sellPercent < 45 then Color.GREEN else Color.ORANGE));
############################################ Current Bar Stats ############################################

AddLabel(ShowSellVolumePercent, "CurSell: " + Round(SellVolPercent, 0) + "% ", (if SellVolPercent > 51 then Color.RED else if SellVolPercent < 49 then Color.GREEN else Color.ORANGE));

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));
 
@mac1782 A bit more Cleanup of unused variables and calculations. Also changed the formula for Average calculations, since the native Average formula is faster and better for performance, also it allows the ability to change the Day length and BarLength as an input, without having to modify the code.

Code:
# Volume Labels Lite
# Based on  https://usethinkscript.com/threads/custom-thinkscript-volume-stats-for-thinkorswim.970/post-47658 and requested by @mac1782
# Version 1.5.3
# Modified on 01/08/21
# Modified by: Surya Kiran C ## Included rVolume label and Changed length as input.

declare on_volume; #Declared on_volume, if you need to use only labels as a top study comment "Selling Volume" & "Buying Volume", along with this line with a "#" in-front of the line

input Length = 30;
input Barlength = 6;

######################### Current BAR ########################
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);

######################## 6BAR ################################
def HH6 = Average(high[1], Barlength);
def HC6 = Average(close[1], Barlength);
def HL6 = Average(low[1], Barlength);
def HV6 = Average(volume[1], Barlength);
def  Buy6 = HV6 * (HC6 - HL6) / (HH6 - HL6);
def Sell6 = HV6 * (HH6 - HC6) / (HH6 - HL6);

###################### 30BAR #################################
def HH30 = Average(high[1], Length);
def HC30 = Average(close[1], Length);
def HL30 = Average(low[1], Length);
def HV30 = Average(volume[1], Length);
def Buy30 = HV30 * (HC30 - HL30) / (HH30 - HL30);
def Sell30 = HV30 * (HH30 - HC30) / (HH30 - HL30);

###################### 6Bar Volume % #########################
def H6Vol = Round(Buy6, 0) + Round(Sell6, 0) ;
def H6buyPercent  = ( Round(Buy6, 0)  / H6Vol ) * 100;
def H6sellPercent = ( Round(Sell6, 0) / H6Vol ) * 100;

###################### 30Bar Volume %   ######################
def H30Vol = Round(Buy30, 0) + Round(Sell30, 0) ;
def H30buyPercent  = (Round(Buy30, 0)  / H30Vol) * 100;
def H30sellPercent = (Round(Sell30, 0) / H30Vol) * 100;

####################### Volume Stats #########################
def volLast30DayAvg = Average(volume (Period = "DAY")[1],Length);
def today = volume(period = "DAY");
def percentOf30Day = Round((today / volLast30DayAvg) * 100, 0);
def avg30Bars = Average(volume[1],Length);
def curVolume = volume;
def percentOf30Bar = Round((curVolume / avg30Bars) * 100, 0);
def SellVolPercent = Round((Selling / Volume) * 100, 0);

######################### Labels ##############################
input ShowDayAvg = yes;
input ShowTodayVolume = yes;
input ShowPercentOf30DayAvg = yes;
input UnusualVolumePercent = 200;
input ShowBarAvg = yes;
input ShowCurrentBar = yes;
input ShowPercentOf30BarAvg = yes;

AddLabel(ShowDayAvg, "30D: " + Round(volLast30DayAvg * .000001, 1) + " M", Color.LIGHT_GRAY);
AddLabel(ShowTodayVolume, "D: " + Round(today * .000001, 1) + " M", (if percentOf30Day >= UnusualVolumePercent then Color.GREEN else if percentOf30Day >= 100 then Color.ORANGE else Color.LIGHT_GRAY));
AddLabel(ShowPercentOf30DayAvg,"rVol: " + percentOf30Day + "%", (if percentOf30Day >= UnusualVolumePercent then Color.GREEN else if percentOf30Day >= 100 then Color.ORANGE else Color.WHITE) );
AddLabel(ShowBarAvg, "30Bar: " + Round(avg30Bars * .001, 1) + " K", Color.LIGHT_GRAY);
AddLabel(ShowCurrentBar, "CurBar: " + Round(curVolume * .001, 1) + " K", (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) );

############################################ 30 Bar Stats ############################################
input Show30Bar = yes;
AddLabel(Show30Bar, length + "BarSell: " + Round(H30sellPercent, 0) + "% ", (if H30sellPercent > 55 then Color.RED else if H30sellPercent < 45 then Color.GREEN else Color.ORANGE));
############################################ 6 Bar Stats #############################################
input Show6Bar = yes;
AddLabel(Show6Bar, Barlength +"BarSell: " + Round(H6sellPercent, 0) + "% ", (if H6sellPercent > 55 then Color.RED else if H6sellPercent < 45 then Color.GREEN else Color.ORANGE));
############################################ Current Bar Stats ########################################
input ShowSellVolumePercent = yes;
AddLabel(ShowSellVolumePercent, "CurSell: " + Round(SellVolPercent, 0) + "% ", (if SellVolPercent > 51 then Color.RED else if SellVolPercent < 49 then Color.GREEN else Color.ORANGE));

##################### Selling Volume #####################
plot SVol = Selling;
SVol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
SVol.SetDefaultColor(Color.DARK_ORANGE);
SVol.HideTitle();
SVol.HideBubble();
SVol.SetLineWeight(5);

##################### Buying Volume ######################
plot BVol = Buying;
BVol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
BVol.SetDefaultColor(Color.LIGHT_GREEN);
BVol.HideTitle();
BVol.HideBubble();
BVol.SetLineWeight(5);

##################### Plots and Style ###################
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));

######################### END #######################
 
Ive been looking for something that plots the rVol like Boiler Rooms script, but I came up with something that works almost as well. Needs to be cleaned up but I will share it and see if we cant finally get a Vertical Line on a volume chart that works

Code:
#### DYLDAUB JANUARY 2021 #######

# length and type of the same bar price difference MA.
input avgLength = 5;
input avgType = {SMA, EMA, WLD, INE, default AMA};

# overbought and oversold are visual aids.
# overbought with be drawn when OHLC are the same,
# and oversold will be drawn when they are not the same.
input overbought = 1.0;
input oversold = -1.0;

# weighting of flat bars to close, meaning if current bar is
# ...not flat then adjust price histogram by the weighted close.
# Set to zero to force previous flat bar value
# ...to be used, and not weight by close.

input weight = 2;

## VROC
def day = GetDay();
def isNewDay = day != day[1];

# volume displacement length, and std. dev. average length.
input vrocLength = 14;

# increment spike counters by this amount.
input vrocInc = 0.4;

# num. of std. deviations for signaling larger spikes.
input NumDevUp = 3.5;

# use a line for the VROC spike signal instead of plot.
input useLinesForVROC = No;

# increase or decrease (make negative) to adjust VROC signal location.
input vrocSigOffset = 1.0;

def tVROC = if volume[vrocLength] <> 0 then (volume / volume[vrocLength] - 1) else 0;
def isSpike = tVROC < tVROC[1] and tVROC[1] > tVROC[2];

# store the previous tVROC value because that's the peak.
def spikes = if isSpike then tVROC[1] else spikes[1];

def rHSpikes = if isNewDay then vrocInc else if isSpike and tVROC[1] > spikes[1] then rHSpikes[1] + vrocInc else rHSpikes[1];

def rLSpikes = if isNewDay then vrocInc else if isSpike and tVROC[1] < spikes[1] then rLSpikes[1] + vrocInc else rLSpikes[1];

plot SpikeDiff = rHSpikes - rLSpikes;
SpikeDiff.AssignValueColor(if SpikeDiff > 0 then Color.CYAN else Color.MAGENTA);

# Standard deviation of VROC spike.
def sDev = StDev(tVROC, vrocLength);
def upperVROC = Average(tVROC, vrocLength) + NumDevUp * sDev;

plot VROCSpike = if !useLinesForVROC and tVROC > upperVROC then overbought + vrocSigOffset else Double.NaN;
VROCSpike.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
VROCSpike.HideBubble();
VROCSpike.HideTitle();
VROCSpike.AssignValueColor(SpikeDiff.TakeValueColor());

AddVerticalLine(useLinesForVROC and tVROC > upperVROC, "", SpikeDiff.TakeValueColor(), 3);

## VOLUME SPIKES
# determines type of volume spike signals.
# Off is no display, StdDev is using std. deviations,
# HighVol is using spikes above highest average.
input volumeSignals = {Off, default StdDev, HighVol};

# use a line for the volume spike signal instead of plot.
input useLinesForVolume = No;

# increase or decrease (make negative) to adjust VROC signal location.
input volumeSigOffset = 0.5;

# spectrum color displacement and std. dev. average length for volume.
input volumeLength = 10;

def isUU = close > close[volumeLength] and volume > volume[volumeLength];
def isUD = close > close[volumeLength] and volume < volume[volumeLength];
def isDU = close < close[volumeLength] and volume < volume[volumeLength];
def isDD = close < close[volumeLength] and volume > volume[volumeLength];

# num. of std. deviations for volume spikes.
input volNumDevUp = 2.75;

def sDevVol = StDev(volume, volumeLength);
def volUpper = if volumeSignals == volumeSignals.StdDev then Average(volume, volumeLength) + volNumDevUp * sDevVol else Highest(volume[1], volumeLength);

def isVolumeSpike = volumeSignals != volumeSignals.Off and volume > volUpper;

plot VolumeSpike = if !useLinesForVolume and isVolumeSpike then overbought + volumeSigOffset else Double.NaN;
VolumeSpike.SetPaintingStrategy(PaintingStrategy.SQUARES);
VolumeSpike.SetLineWeight(3);
VolumeSpike.HideBubble();
VolumeSpike.HideTitle();
VolumeSpike.AssignValueColor(if isUU then Color.GREEN else if isUD then Color.BLUE else if isDU then Color.ORANGE else if isDD then Color.RED else Color.GRAY);

AddVerticalLine(useLinesForVolume and isVolumeSpike, "SPIKE", if isUU then Color.GREEN else if isUD then Color.BLUE else if isDU then Color.ORANGE else if isDD then Color.RED else Color.GRAY, 2);

A1-GB-BUYSELLVOLUME-no-no-no-200-no.jpg
 
Here on AMC, that I have circled, they have reached 1 million volume, how would I change the color of that bar to see it better?

x2IlziS.png
 
@Stoynks
Code:
declare lower;
plot vol = volume;
Vol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Vol.SetLineWeight(3);
vol.AssignValueColor(if Vol >= 1000000 then color.orange else Color.grAY);
 
I found an indicator that gives labels for the average volume of a stock in the last 30 days. I am now wondering if there is a thinkScript that will display, in labels, what the average volume for the first 30 minutes of trading, perhaps from the last 30 days, has been (either of these values may be changed, for example, average volume from 12PM to 1PM over the last 60 days, for example). My goal is to use this to identify whether stock has more volume than usual at a time to get ahead of runs or drops before they happen. I personally have very little experience coding, and 100% insufficient knowledge to start this from scratch; if anyone has thinkScript code at least similar to what I'm requesting, please reply with it. Thanks.
 
Hello ,

I was wondering if theirs any Realtive Volume indicators that are similar to this indicator I was using in trading view?

  • edited by moderator. media content blocked. Contained commercial content prohibited by Forum's terms & guidelines

When volume rises above any one of the three given thresholds, the volume bar changes color. You can also set alerts with this script so that you get notified whenever this occurs.
 
Last edited by a moderator:
I have a Volume Strategy that I would like to trade using simple 5 min volume bars. I need to be able to monitor multiple stocks at once. Can anyone help me with an alert script for simple colored volume bars (Red/Green). I need a way to set an alert if two bars in a row are the same color and the second bar is larger (has greater volume) than the first?
 
I have a Volume Strategy that I would like to trade using simple 5 min volume bars. I need to be able to monitor multiple stocks at once. Can anyone help me with an alert script for simple colored volume bars (Red/Green). I need a way to set an alert if two bars in a row are the same color and the second bar is larger (has greater volume) than the first?

@ebobbyj Welcome to the usethinkscript forums... This will get you started...

Ruby:
# test that the current and last bars are in an uptrend
def upTrend =  close > close[1] and close[1] > close[2];
 
Last edited by a moderator:
@mac1782

try this code, the 30BarAvg is Gray color and the 6Bar goes Green or Red depends on if it is higher than 30Bar, works for all timeframes.

Code:
## Volume Labels
# Version 1.5.3
# Created: 06/23/20 # Modified on 08/26/20

# Modified by: Surya Kiran C ## Included rVolume label and Changed length as input. ## Additionally Pre-Market, 1Hr Volume, AfterHour, 5 Day Volume labels are added.

# Version 1.5 Changes
# Change 1) Higher Time Frame Buying Vs Selling, Please make sure to configure VolPeriod higher than typical chart frame used.
# Change 2) Added 30Day Average White Line to VolumeBar, for 1Y 1D, and a 30BarAvg line for lower timeframes, Just to indicate if the current bar is above or below Average line.
# Version 1.5.1 Changes.
# Minor, Higher timeframe has labels indicating the timeframe.
# Version 1.5.2 Changes.
# Change 1) Minor, Daily and Previous day volumes converted to Millions with round(2), easier to read than counting the digits on running volume during trading hours.
# Change 2) Fixed color code issue with previous DayVolume, now we code Day/previousDay volumes to lime if they are less then corrospondant previous day and higher than 30DAvg.
#Version 1.5.3 Changes
# Added Avg % of Buying selling for 30Bar
# Added New 6 Bar stats for comaprision against 30Bar

declare on_volume; # Declared on_volume, if you need to use only labels as a top study comment # Selling Volume # & # Buying Volume # along with this line.

input length = 30;
input Barlength = 6;

input ShowTodayVolume = yes;
input PreviousDayVolume = yes;
input ShowPercentOfDayAvg = yes;
input UnusualVolumePercent = 200;
input ShowBarAvg = yes;
input ShowVol = yes;

def VolStatsPeriod = (if GetAggregationPeriod() == AggregationPeriod.DAY then AggregationPeriod.WEEK else AggregationPeriod.DAY);

def VolDayAvg = Average(volume(period = "Day")[1], length);
def AvgBars = Average(volume[1], length);
def AvgBars2 = Average(volume[1], Barlength);

def Vol1 = volume(period = "DAY")[1];
def Vol2 = volume(period = "DAY")[2];
def Vol3 = volume(period = "DAY")[3];
def Vol4 = volume(period = "DAY")[4];
def Vol5 = volume(period = "DAY")[5];

def VolDayAvg1 = VolDayAvg[1];
def VolDayAvg2 = VolDayAvg[2];
def VolDayAvg3 = VolDayAvg[3];
def VolDayAvg4 = VolDayAvg[4];
def VolDayAvg5 = VolDayAvg[5];

def Vol = volume(period = "DAY");

def DollarVolume = hl2 * Vol;
def AvgHL2 = Average(hl2 * Vol , length);
def DaysDollarVol = VolDayAvg * AvgHL2;

def rVol = Vol / VolDayAvg;
def PercentOfDayAvg = Round((rVol * 100), 2);

############### Buying and Selling Volume Study
#DPL CRITERIA #
###############
input Audible_Alert = yes;
def Deviation_Length = 60;
def Deviate = 2;
def volumestdev = RelativeVolumeStDev(length = Deviation_Length);
def abovedev = volumestdev >= Deviate;
def belowdev = volumestdev <= Deviate;

############
# DPL BARS #
############
def increase = volume > volume[1];
def devincrease = increase and abovedev;
def decrease = volume < volume[1];
def devdecrease = decrease and abovedev;

##############################
# UPTICK / DOWNTICK CRITERIA #
##############################
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);

################################
#         6BAR                 #
################################
def HH6 = Average(high[1], Barlength);
def HC6 = Average(close[1], Barlength);
def HL6 = Average(low[1], Barlength);
def HV6 = Average(volume[1], Barlength);

def  Buy6 = HV6 * (HC6 - HL6) / (HH6 - HL6);
def Sell6 = HV6 * (HH6 - HC6) / (HH6 - HL6);

################################
#         30BAR                #
################################
#def HH30 = (fold B30H = 1 to length + 1 with i30H = 0 do (i30H + high[B30H]));
#def HC30 = (fold B30C = 1 to length + 1 with i30C = 0 do (i30C + close[B30C]));
#def HL30 = (fold B30L = 1 to length + 1 with i30L = 0 do (i30L + low[B30L]));
#def HV30 = (fold B30V = 1 to length + 1 with i30V = 0 do (i30V + volume[B30V]));

def HH30 = Average(high[1], length);
def HC30 = Average(close[1], length);
def HL30 = Average(low[1], length);
def HV30 = Average(volume[1], length);

def Buy30 = HV30 * (HC30 - HL30) / (HH30 - HL30);
def Sell30 = HV30 * (HH30 - HC30) / (HH30 - HL30);

###############################################
# For Higher Frame UPTICK / DOWNTICK CRITERIA #
###############################################
def HH = high (period = VolStatsPeriod);
def HC = close (period = VolStatsPeriod);
def HL = low (period = VolStatsPeriod);
def HV = volume (period = VolStatsPeriod);
def HBuying = HV * (HC - HL) / (HH - HL);
def HSelling = HV * (HH - HC) / (HH - HL);

##################
# Selling Volume #
##################
plot SVol = Selling;
SVol.DefineColor("Decrease", Color.DARK_RED);
SVol.DefineColor("DevDecrease", Color.LIGHT_RED);
SVol.AssignValueColor(if devdecrease then SVol.Color("DevDecrease") else SVol.Color("Decrease"));
SVol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
SVol.HideTitle();
SVol.HideBubble();
SVol.SetLineWeight(5);

#################
# Buying Volume #
#################
plot BVol = Buying;
BVol.DefineColor("Increase", Color.DARK_GREEN);
BVol.DefineColor("DevIncrease", Color.GREEN);
BVol.AssignValueColor(if devincrease then BVol.Color("DevIncrease") else BVol.Color("Increase"));
BVol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
BVol.HideTitle();
BVol.HideBubble();
BVol.SetLineWeight(5);

#################
#  Volume %     #
#################
def totVol = Round(Buying, 0) + Round(Selling, 0) ;
def buyPercent  = ( Round(Buying, 0)  / totVol ) * 100;
def sellPercent = ( Round(Selling, 0) / totVol ) * 100;

#####################
# Higher Volume %   #
#####################
def HtotVol = Round(HBuying, 0) + Round(HSelling, 0) ;
def HbuyPercent  = ( Round(HBuying, 0)  / HtotVol ) * 100;
def HsellPercent = ( Round(HSelling, 0) / HtotVol ) * 100;

#####################
# 6Bar Volume %   #
#####################
def H6Vol = Round(Buy6, 0) + Round(Sell6, 0) ;
def H6buyPercent  = ( Round(Buy6, 0)  / H6Vol ) * 100;
def H6sellPercent = ( Round(Sell6, 0) / H6Vol ) * 100;

#####################
# 30Bar Volume %   #
#####################
def H30Vol = Round(Buy30, 0) + Round(Sell30, 0) ;
def H30buyPercent  = (Round(Buy30, 0)  / H30Vol) * 100;
def H30sellPercent = (Round(Sell30, 0) / H30Vol) * 100;

########################
# Adding Volume Labels #
########################

#Higher Time Frame Buying & Selling Volumes#

input ShowHigherVolStats = yes;

AddLabel(if GetAggregationPeriod() >= VolStatsPeriod and !ShowHigherVolStats then 0 else 1, (if VolStatsPeriod == AggregationPeriod.MONTH then "M" else if VolStatsPeriod == AggregationPeriod.WEEK then "W" else if VolStatsPeriod == AggregationPeriod.FOUR_DAYS then "4D" else if VolStatsPeriod == AggregationPeriod.THREE_DAYS then "3D" else if VolStatsPeriod == AggregationPeriod.TWO_DAYS then "2D" else if VolStatsPeriod  == AggregationPeriod.DAY then "D" else if VolStatsPeriod == AggregationPeriod.FOUR_HOURS then "4H" else if VolStatsPeriod == AggregationPeriod.TWO_HOURS then "2H" else if VolStatsPeriod == AggregationPeriod.HOUR then "60m" else if VolStatsPeriod == AggregationPeriod.THIRTY_MIN then "30m" else if VolStatsPeriod == AggregationPeriod.TWENTY_MIN then "20m" else if VolStatsPeriod  == AggregationPeriod.FIFTEEN_MIN then "15m" else if VolStatsPeriod == AggregationPeriod.TEN_MIN then "10m" else if VolStatsPeriod == AggregationPeriod.FIVE_MIN then "5m" else if VolStatsPeriod == AggregationPeriod.FOUR_MIN then "4m" else if VolStatsPeriod  == AggregationPeriod.THREE_MIN then "3m" else if VolStatsPeriod == AggregationPeriod.TWO_MIN then "2m" else if VolStatsPeriod  == AggregationPeriod.MIN then "1m" else "") + " Buy: " + Round(HBuying * .000001, 2) + "M  " + Round(HbuyPercent, 2) + "% ", (if HBuying > HSelling then Color.GREEN else Color.RED)) ;
AddLabel(if GetAggregationPeriod() >= VolStatsPeriod and !ShowHigherVolStats then 0 else 1, (if VolStatsPeriod == AggregationPeriod.MONTH then "M" else if VolStatsPeriod == AggregationPeriod.WEEK then "W" else if VolStatsPeriod == AggregationPeriod.FOUR_DAYS then "4D" else if VolStatsPeriod == AggregationPeriod.THREE_DAYS then "3D" else if VolStatsPeriod == AggregationPeriod.TWO_DAYS then "2D" else if VolStatsPeriod  == AggregationPeriod.DAY then "D" else if VolStatsPeriod == AggregationPeriod.FOUR_HOURS then "4H" else if VolStatsPeriod == AggregationPeriod.TWO_HOURS then "2H" else if VolStatsPeriod == AggregationPeriod.HOUR then "60m" else if VolStatsPeriod == AggregationPeriod.THIRTY_MIN then "30m" else if VolStatsPeriod == AggregationPeriod.TWENTY_MIN then "20m" else if VolStatsPeriod  == AggregationPeriod.FIFTEEN_MIN then "15m" else if VolStatsPeriod == AggregationPeriod.TEN_MIN then "10m" else if VolStatsPeriod == AggregationPeriod.FIVE_MIN then "5m" else if VolStatsPeriod == AggregationPeriod.FOUR_MIN then "4m" else if VolStatsPeriod  == AggregationPeriod.THREE_MIN then "3m" else if VolStatsPeriod == AggregationPeriod.TWO_MIN then "2m" else if VolStatsPeriod  == AggregationPeriod.MIN then "1m" else "") + " Sell: " + Round(HSelling * .000001, 2) + "M " + Round(HsellPercent, 2) + "% ", (if HSelling > HBuying then Color.GREEN else Color.RED)) ;


#AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 0 else 1, "WBuy: " + Round(HBuying * .000001, 2) + "M  " + Round(HbuyPercent, 2) + "% ", (if HBuying > HSelling then Color.GREEN else Color.RED));
#AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 0 else 1, "WSell: " + Round(HSelling * .000001, 2) + "M " + Round(HsellPercent, 2) + "% ", (if HSelling > HBuying then Color.GREEN else Color.RED));

#######################################Chart Time Frame Buying & Selling Volumes#######################################
input Show_Labels = yes;

AddLabel(Show_Labels, "Buy: " + Round(Buying, 2) + " " + Round(buyPercent, 2) + "% ", if Buying > Selling then Color.GREEN else Color.RED);
AddLabel(Show_Labels, "Sell: " + Round(Selling, 2) + " " + Round(sellPercent, 2) + "% ", if Selling > Buying then Color.GREEN else Color.RED);

############################################ End of Buying & Selling Labels Study ####################################
input ShowDayAvg = yes;

AddLabel(ShowDayAvg, length + "DAvg: " + Round(VolDayAvg * .000001, 2) + " M ", Color.LIGHT_GRAY);
AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 1 else if PreviousDayVolume then 1 else 0, "D4: " + Round(Vol4 * .000001, 2) + " M ", (if Vol4 >= VolDayAvg4 and Vol4 >= Vol5 then Color.GREEN else if Vol4 <= Vol5 and Vol4 >= VolDayAvg4 then Color.LIME else Color.RED));
AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 1 else if PreviousDayVolume then 1 else 0, "D3: " + Round(Vol3 * .000001, 2) + " M ", (if Vol3 >= VolDayAvg3 and Vol3 >= Vol4 then Color.GREEN else if Vol3 <= Vol4 and Vol3 >= VolDayAvg3 then Color.LIME else Color.RED));
AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 1 else if PreviousDayVolume then 1 else 0, "D2: " + Round(Vol2 * .000001, 2) + " M ", (if Vol2 >= VolDayAvg2 and Vol2 >= Vol3 then Color.GREEN else if Vol2 <= Vol3 and Vol2 >= VolDayAvg2 then Color.LIME else Color.RED));
AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 1 else if PreviousDayVolume then 1 else 0, "D1: " + Round(Vol1 * .000001, 2) + " M ", (if Vol1 >= VolDayAvg1 and Vol1 >= Vol2 then Color.GREEN else if Vol1 <= Vol2 and Vol1 >= VolDayAvg1 then Color.LIME else Color.RED));
AddLabel(ShowTodayVolume,  "D: " + Round(Vol * .000001, 2) + " M ", (if PercentOfDayAvg >= UnusualVolumePercent then Color.GREEN else if PercentOfDayAvg >= 100 then Color.LIME else Color.RED));

AddLabel(ShowPercentOfDayAvg, PercentOfDayAvg + "%", (if PercentOfDayAvg >= UnusualVolumePercent then Color.GREEN else if PercentOfDayAvg >= 100 then Color.LIME else Color.WHITE) );

############################################ 30 Bar Stats ############################################
input Show30Bar = yes;

AddLabel(Show30Bar, "A" + length + "Bars: "+ Round(AvgBars, 0) + " ", Color.LIGHT_GRAY);
AddLabel(Show30Bar, "B" + length + ":" + Round(Buy30, 0) + " " + Round(H30buyPercent, 2) + "% ", if Buy30 > Sell30 then Color.GREEN else Color.RED);
AddLabel(Show30Bar, "S" + length + ":" + Round(Sell30, 0) + " " + Round(H30sellPercent, 2) + "% ", if Sell30 > Buy30 then Color.GREEN else Color.RED);

############################################ 6 Bar Stats ############################################
input Show6Bar = yes;

AddLabel(Show6Bar, "A" + Barlength  + "Bars: "+ Round(AvgBars2, 0) + " ",Color.LIGHT_GRAY);
AddLabel(Show6Bar, "B" + Barlength + ":" + Round(Buy6, 0) + " " + Round(H6buyPercent, 2) + "% ", if Buy6 > Sell6 then Color.GREEN else Color.RED);
AddLabel(Show6Bar, "S" + Barlength + ":" + Round(Sell6, 0) + " " + Round(H6sellPercent, 2) + "% ", if Sell6 > Buy6 then Color.GREEN else Color.RED);
###############################Current Bar, rVol, DollerTraded, 30D Traded ################################
input ShowRvol = no;
input ShowDollarTraded = yes;
input ShowDaysDollarTraded = yes;

AddLabel(ShowRvol, "rVol :" + Round(rVol, 2), (if rVol >= 2 then Color.GREEN else if rVol > 1 then Color.LIME else Color.WHITE));
AddLabel(ShowDollarTraded, "Traded : " + AsDollars(Round(DollarVolume * .000001, 2)) + "M ", Color.WHITE);
AddLabel(ShowDaysDollarTraded, length + "DayTraded : " + AsDollars(Round(DaysDollarVol * .0000000001, 2)) + "B ", Color.WHITE);

########################## Add Horizantal Line at 30DAvgVolume level or 30BarAvgVolume level on intraday #######################

def AvgLine = VolDayAvg[0];
plot line = (if GetAggregationPeriod() >= AggregationPeriod.DAY then AvgLine else AvgBars);
line.SetDefaultColor(Color.WHITE);
line.SetLineWeight(2);

############################## Pre, 1Hr RTH, AfterHours Volumes ###########################################
input ShowPreMktVol = yes;
input ShowRTH1HrVol = yes;
input ShowPostMktVol = yes;

def PreMkt = RegularTradingStart (GetYYYYMMDD()) > GetTime();
def PreVol = if PreMkt and !PreMkt[1] then volume else if PreMkt then PreVol[1] + volume else PreVol[1];
AddLabel(if GetAggregationPeriod() > AggregationPeriod.THIRTY_MIN or !ShowPreMktVol then 0 else 1, "PreMktVol = " + Round(PreVol * .000001, 2) + "M ", Color.YELLOW);
# End Volume PreMarket

def RTH1HrstartTime = 0930;
input RTH1HrendTime = 1030;

def RTH1Hr = SecondsFromTime(RTH1HrstartTime) >= 0 and SecondsTillTime(RTH1HrendTime) > 0;
def RTH1HrVol = if RTH1Hr and !RTH1Hr[1] then volume else if RTH1Hr then RTH1HrVol[1] + volume else RTH1HrVol[1];
AddLabel(if GetAggregationPeriod() > AggregationPeriod.THIRTY_MIN or !ShowRTH1HrVol then 0 else 1, "RTH1HrVol = " + Round(RTH1HrVol * .000001, 2) + "M ", Color.YELLOW);

AddVerticalLine(if GetDay() == GetLastDay() and RTH1Hr == 0 and RTH1Hr[1] == 1 then yes else no, "First Hour Mark", color = Color.WHITE);
#End Volume RTH First 60 Mins

def PostMkt = RegularTradingEnd (GetYYYYMMDD()) < GetTime();
def PostVol = if PostMkt and !PostMkt[1] then volume else if PostMkt then PostVol[1] + volume else PostVol[1];
AddLabel(if GetAggregationPeriod() > AggregationPeriod.THIRTY_MIN or !ShowPostMktVol then 0 else 1, "PostMktVol = " + Round(PostVol * .000001, 2) + "M ", Color.YELLOW);
# End Volume PostMarket
can you make the "D Buy" and "D Sell" label hideable?
 
can you make the "D Buy" and "D Sell" label hideable?
if you are referring to D Buy/Sell in lower frames such as, 5m, 15m, Just set "Show Higher Vol Stats" to no in your indicator properties and you are all set. Honestly, there are a on load of settings, just set them to "no" and see what you like and what you don't.

-S
 
I want to create a volume label that shows in % current 15 min volume compared to avg of last 5 days for same time frame (9:30am to 9:45am)
I know how to build label and create calc, but dont know how to get volume for specific timeframe

Any help would be appreciated
 
I want to create a volume label that shows in % current 15 min volume compared to avg of last 5 days for same time frame (9:30am to 9:45am)
I know how to build label and create calc, but dont know how to get volume for specific timeframe

Any help would be appreciated
Just adjust the length to 5, and be in 15m timeframe. Go back few pages and see, there is a detailed indicator parameter description posted by me. I think you have all you need built in, you need to play with parameters. any further help required, I can dig up my old posts on this thread, and point to you, when I have access to a system not mobile. :)
 
Hi All,

Been here and checking out some scripts for few months. Though about time I start contributing.

My first ever post ever. I am trying to improve this script and include, rVolume as well in the labels. Intended changes are listed.
  • Change the number of days for average calculation to be an input, instead of fixed 30 days.
  • Include rVolume Label.
I think I got the calculations right, however when I give 30 Days as an input for the modified script, it's slightly off in 30DayAvg Calculations.

Was wondering, if somebody here can take a look at this and see what am I missing. Please see the attached screenshot, the one on the left is using original code and the one on the right is using the modified code.

gGUYCGO.png


Code:
# Box Volume Stats
# Version 1.0
# Created by: Enigma
# Created: 05/18/17
# Modified by: Surya Kiran C ## Included rVolume label and Changed length as input.

declare on_volume;

input length = 30;
input ShowDayAvg = yes;
input ShowTodayVolume = yes;
input ShowPercentOfDayAvg = yes;
input UnusualVolumePercent = 200;
input ShowBarAvg = yes;
input ShowCurrentBar = yes;

def VolDayAvg = (fold index = 1 to length with Avg do Avg + (volume(period = "DAY")[index])) / length ;
def Today = volume(period =  "DAY");
def PercentOfDayAvg = Round((Today / VolDayAvg) * 100, 0);
def AvgBars = (fold index2 = 1 to length with Bar do Bar + (volume[index2])) / length;
def CurVol = volume;

def offset = 1;
def ADV = Average(volume, length)[offset];
def rVol = volume / ADV;

# Labels
AddLabel(yes, Round(rVol, 2));
AddLabel(yes, "ADV :" + ADV);
#AddLabel(yes, asPercent(rVol)); # remove "#" infront of Addlabels to select prefer choice
#AssignPriceColor(if rVol >= 1 then color.dark_red else if rVol <=.5 then Color.black else color.Gray);
AddLabel(ShowDayAvg, "Daily Avg: " + Round(VolDayAvg, 0), Color.LIGHT_GRAY);
AddLabel(ShowTodayVolume, "Today: " + Today + " ", (if PercentOfDayAvg >= UnusualVolumePercent then Color.GREEN else if PercentOfDayAvg >= 100 then Color.ORANGE else Color.LIGHT_GRAY));
AddLabel(ShowPercentOfDayAvg, PercentOfDayAvg + "%", (if PercentOfDayAvg >= UnusualVolumePercent then Color.GREEN else if PercentOfDayAvg >= 100 then Color.ORANGE else Color.WHITE) );
AddLabel(ShowBarAvg, "Avg 30 Bars: " + Round(AvgBars, 0) + " ", Color.LIGHT_GRAY);
AddLabel(ShowCurrentBar, "Cur Bar: " + CurVol + " ", (if CurVol >= AvgBars then Color.GREEN else Color.ORANGE));
Could you explain the meaning of RVol label?!
def ADV = Average(volume, length)[offset];
def rVol = volume / ADV;
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
323 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top