# Volume Labels
# Version 1.4
# Created: 06/23/20 # Modified 08/09/2020
# 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.
declare on_volume; # Decalared on_volume, if you need to use only labes 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 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 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);
##################
# 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;
########################
# Adding Volume Labels #
########################
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
########################
# Labels
########################
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(yes, "rVol :" + Round(rVol, 2), (if rVol >= 2 then Color.GREEN else if rVol > 1 then Color.LIME else Color.WHITE));
###########################
#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