#Chris' Enhanced Volume V.2 /w Uptick/Downtick
declare lower;
###############
#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.rED);
SV.DefineColor("DevDecrease", Color.pink);
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 #
#################
DefineGlobalColor("LabelGreen", CreateColor(0, 165, 0)) ;
plot BV = Buying;
BV.DefineColor("Increase", GlobalColor("LabelGreen"));
BV.DefineColor("DevIncrease", Color.light_GREEN);
BV.AssignValueColor(if devincrease then BV.Color("DevIncrease") else BV.Color("Increase"));
BV.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
BV.HideTitle();
BV.HideBubble();
BV.SetLineWeight(5);
#################
# Adding Volume Labels #
#################
input Show_Labels = yes;
AddLabel(Show_Labels, "Buy Vol = " + Round(Buying, 0),
if Buying > Selling then GlobalColor("LabelGreen") else color.red);
AddLabel(Show_Labels, "Buy %: " + Round((Buying/(Buying+Selling))*100,2), If Buying>Selling then color.green else color.red);
AddLabel(Show_Labels, "Sell Vol = " + Round(Selling, 0),
if Selling > Buying then GlobalColor("LabelGreen") else color.red);
AddLabel(Show_Labels, "Sell %: " + Round((Selling/(Selling+Buying))*100,2), If Buying>Selling then color.green else color.red);
#HIGHEST VOLUME OF THE YEAR, SINCE EARNINGS, ALL TIME
#Set your agggregation to make sure the entire year is visible, most people would use Day
#by XeoNoX via usethinkscript.com
def yearhighvol = HighestAll(if GetLastYear() == GetYear() and !IsNaN(close) and !IsNaN(close[-1]) then volume else 0);
def himonth1 = if volume==yearhighvol then getmonth() else himonth1[1];
def hiday1 = if volume==yearhighvol then getDayOfMonth(getYYYYMMDD()) else hiday1[1];
def hiyear1 = if volume==yearhighvol then getyear() else hiyear1[1];
AddLabel (yes, "HVCE: "+ himonth1 + "/" + hiday1 + "/" + hiyear1 , If Buying>Selling then color.green else color.red);
AddChartBubble(volume==yearhighvol, volume, "HVCE " , If Buying>Selling then color.green else color.red, yes);
def Earnings_Highest_Volume = if HasEarnings()[0] then (volume) else if volume > Earnings_Highest_Volume[1] then volume else Earnings_Highest_Volume[1];
def himonth2 = if volume==Earnings_Highest_Volume then getmonth() else himonth2[1];
def hiday2 = if volume==Earnings_Highest_Volume then getDayOfMonth(getYYYYMMDD()) else hiday2[1];
def hiyear2 = if volume==Earnings_Highest_Volume then getyear() else hiyear2[1];
AddLabel (yes, "HVSLE: "+ himonth2 + "/" + hiday2 + "/" + hiyear2 , If Buying>Selling then color.green else color.red);
AddChartBubble(volume==Earnings_Highest_Volume, volume, "HVSLE" , If Buying>Selling then color.green else color.red, yes);
def alltimehi_vol = HighestAll(volume);
def himonth3 = if volume==alltimehi_vol then getmonth() else himonth3[1];
def hiday3 = if volume==alltimehi_vol then getDayOfMonth(getYYYYMMDD()) else hiday3[1];
def hiyear3 = if volume==alltimehi_vol then getyear() else hiyear3[1];
AddLabel (yes, "ATHV: "+ himonth3 + "/" + hiday3 + "/" + hiyear3 , If Buying>Selling then color.green else color.red);
AddChartBubble(volume==alltimehi_vol, volume, "ATHV " , If Buying>Selling then color.green else color.red, yes);