# Volume Labels
# Version 1.5
# Created: 06/23/20 # Modified on 08/17/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.
# Change 3) Tried to integrate $ Value of the stock sold for Day and for 30 Day average. ## These are experiential only, Need to verify them. But I think they still give you an idea of the $ Value traded, if not accurate.
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 ShowDayAvg = yes;
input ShowTodayVolume = yes;
input PreviousDayVolume = no;
input ShowPercentOfDayAvg = yes;
input UnusualVolumePercent = 200;
input ShowBarAvg = yes;
input ShowCurrentBar = yes;
input ShowrVol = yes;
input ShowDollarTraded = yes;
input ShowDaysDollarTraded = yes;
input VolStatsPeriod = AggregationPeriod.DAY;
input PreMktVol = yes;
input RTH1HrVol = yes;
input PostMktVol = yes;
def VolDayAvg = Average(volume(period = "DAY")[1], length);
def AvgBars = Average(volume[1], length);
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 Vol = volume(period = "DAY");
def CurVol = volume;
def DollarVolume = hl2 * Vol;
def AvgHL2 = Average(hl2[1], 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 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);
###############################################
# For Higher Frame UPTICK / DOWNTICK CRITERIA #
###############################################
def HO = open(period = VolStatsPeriod);
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 SV = Selling;
SV.DefineColor("Decrease", Color.DARK_RED);
SV.DefineColor("DevDecrease", Color.LIGHT_RED);
SV.AssignValueColor(if devdecrease then SV.Color("DevDecrease") else SV.Color("Decrease"));
SV.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
SV.HideTitle();
SV.HideBubble();
SV.SetLineWeight(5);
#################
# Buying Volume #
#################
plot BV = Buying;
BV.DefineColor("Increase", Color.DARK_GREEN);
BV.DefineColor("DevIncrease", Color.GREEN);
BV.AssignValueColor(if devincrease then BV.Color("DevIncrease") else BV.Color("Increase"));
BV.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
BV.HideTitle();
BV.HideBubble();
BV.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;
#################
# Volume % #
#################
def HtotVol = Round(HBuying, 0) + Round(HSelling, 0) ;
def HbuyPercent = ( Round(HBuying, 0) / HtotVol ) * 100;
def HsellPercent = ( Round(HSelling, 0) / HtotVol ) * 100;
########################
# Adding Volume Labels #
########################
#Higher Time Frame Buying & Selling Volumes#
input ShowHigherVolStats = no;
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, 0) + " " + 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, 0) + " " + 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, 0) + " " + Round(buyPercent, 2) + "% ", if Buying > Selling then Color.GREEN else Color.RED);
AddLabel(Show_Labels, "Sell: " + Round(Selling, 0) + " " + Round(sellPercent, 2) + "% ", if Selling > Buying then Color.GREEN else Color.RED);
######################## End of Buying & Selling Labels Study
AddLabel(ShowDayAvg, length + "DAvg: " + Round(VolDayAvg, 0) + " ", Color.LIGHT_GRAY);
AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 1 else if PreviousDayVolume then 1 else 0, "Day4: " + Vol4 + " ", (if Vol4 >= VolDayAvg4 and Vol5 then Color.GREEN else if Vol4 >= Vol5 then Color.LIME else Color.RED));
AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 1 else if PreviousDayVolume then 1 else 0, "Day3: " + Vol3 + " ", (if Vol3 >= VolDayAvg3 and Vol4 then Color.GREEN else if Vol3 >= Vol4 then Color.LIME else Color.RED));
AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 1 else if PreviousDayVolume then 1 else 0, "Day2: " + Vol2 + " ", (if Vol2 >= VolDayAvg2 and Vol3 then Color.GREEN else if Vol2 >= Vol3 then Color.LIME else Color.RED));
AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 1 else if PreviousDayVolume then 1 else 0, "Day1: " + Vol1 + " ", (if Vol1 >= VolDayAvg1 and Vol2 then Color.GREEN else if Vol1 >= Vol2 then Color.LIME else Color.RED));
AddLabel(ShowTodayVolume, "Day: " + Vol + " ", (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) );
AddLabel(ShowBarAvg, "Avg" + length + "Bars: " + Round(AvgBars, 0) + " ", Color.LIGHT_GRAY);
AddLabel(ShowCurrentBar, "Cur Bar: " + CurVol + " ", (if CurVol >= AvgBars then Color.GREEN else Color.LIME));
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(DollarVolume) + " ", Color.WHITE);
AddLabel(ShowDaysDollarTraded, length + "DayTraded : " + AsDollars(DaysDollarvol) + " ", Color.WHITE);
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 PrestartTime = 0400;
input PreendTime = 0930;
def PreMkt = SecondsFromTime(PrestartTime) >= 0 and SecondsTillTime(PreendTime) >= 0;
def PreVolMins = if PreMkt and !PreMkt[1] then volume
else if PreMkt then PreVolMins[1] + volume
else PreVolMins[1];
AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 0 else if PreMktVol then 1 else 0, "PreMktVol = " + PreVolMins + " ", Color.YELLOW);
# End Volume PreMarket
input RTH1HrstartTime = 0930;
input RTH1HrendTime = 1030;
def RTH1Hr = SecondsFromTime(RTH1HrstartTime) >= 0 and SecondsTillTime(RTH1HrendTime) >= 0;
def RTH1HrMins = if RTH1Hr and !RTH1Hr[1] then volume
else if RTH1Hr then RTH1HrMins[1] + volume
else RTH1HrMins[1];
AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 0 else if RTH1HrVol then 1 else 0, "RTH1HrVol = " + RTH1HrMins + " ", Color.YELLOW);
#End Volume RTH First 60 Mins
input PoststartTime = 1600;
input PostendTime = 2000;
def PostMkt = SecondsFromTime(PoststartTime) >= 0 and SecondsTillTime(PostendTime) >= 0;
def PostVolMins = if PostMkt and !PostMkt[1] then volume
else if PostMkt then PostVolMins[1] + volume
else PostVolMins[1];
AddLabel(if GetAggregationPeriod() >= AggregationPeriod.DAY then 0 else if PostMktVol then 1 else 0, "PostMktVol = " + PostVolMins + " ", Color.YELLOW);
# End Volume PostMarket