# CustVolumeStudy by 7of9 for BRT (Modified for Whole Numbers)
declare lower;
#Inputs
input Show10DayAvg = yes;
input ShowTodayVolume = yes;
input ShowPercentOf10DayAvg = yes;
input UnusualVolumePercent = 200;
input Show10BarAvg = yes;
input ShowCurrentBar = yes;
input ShowPercentOf10BarAvg = yes;
input ShowSellVolumePercent = yes;
def O = open;
def H = high;
def C = close;
def L = low;
# Rounded base volume to 0 decimal places
def V = Round(volume, 0);
# Rounded buying and selling volume calculations
def buying = Round(V * (C - L) / (H - L), 0);
def selling = Round(V * (H - C) / (H - L), 0);
AddVerticalLine(( GetDay() <> GetDay()[1]), "", Color.YELLOW, Curve.SHORT_DASH);
# Selling Volume
Plot SellVol = selling;
SellVol.setPaintingStrategy(PaintingStrategy.Histogram);
SellVol.SetDefaultColor(Color.Red);
SellVol.HideTitle();
SellVol.HideBubble();
SellVol.SetLineWeight(5);
# Total Volume (Updated to use rounded 'V' instead of raw 'volume')
Plot BuyVol = V;
BuyVol.setPaintingStrategy(PaintingStrategy.Histogram);
BuyVol.SetDefaultColor(Color.Dark_Green);
BuyVol.HideTitle();
BuyVol.HideBubble();
BuyVol.SetLineWeight(5);
# Volume Data (Rounded raw inputs)
def volLast10DayAvg = Round((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]) / 10, 0);
def today = Round(volume(period = "DAY"), 0);
def percentOf10Day = Round((today / volLast10DayAvg) * 100, 0);
def avg10Bars = Round((volume[1] + volume[2] + volume[3] + volume[4] + volume[5] + volume[6] + volume[7] + volume[8] + volume[9] + volume[10]) / 10, 0);
def curVolume = V;
def percentOf10Bar = Round((curVolume / avg10Bars) * 100, 0);
# Prevent potential division by zero if volume is exactly 0
def SellVolPercent = if V == 0 then 0 else Round((selling / V) * 100, 0);
# Labels (Cleaned up redundant rounding since base variables are now rounded)
AddLabel(Show10DayAvg, "Avg 10 Days: " + volLast10DayAvg, Color.LIGHT_GRAY);
AddLabel(ShowTodayVolume, "Today: " + today, (if percentOf10Day >= UnusualVolumePercent then Color.GREEN else if percentOf10Day >= 100 then Color.ORANGE else Color.LIGHT_GRAY));
AddLabel(ShowPercentOf10DayAvg, percentOf10Day + "%", (if percentOf10Day >= UnusualVolumePercent then Color.GREEN else if percentOf10Day >= 100 then Color.ORANGE else Color.WHITE) );
AddLabel(Show10BarAvg, "Avg 10 Bars: " + avg10Bars, Color.LIGHT_GRAY);
AddLabel(ShowCurrentBar, "Cur Bar: " + curVolume, (if percentOf10Bar >= UnusualVolumePercent then Color.GREEN else if percentOf10Bar >= 100 then Color.ORANGE else Color.LIGHT_GRAY));
AddLabel(ShowPercentOf10BarAvg, percentOf10Bar + "%", (if percentOf10Bar >= UnusualVolumePercent then Color.GREEN else if percentOf10Bar >= 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 = 50;
# Updated to use rounded 'V' and rounded the average
plot Vol = V;
plot VolAvg = Round(Average(volume, length), 0);
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));
declare lower;
#Inputs
input Show10DayAvg = yes;
input ShowTodayVolume = yes;
input ShowPercentOf10DayAvg = yes;
input UnusualVolumePercent = 200;
input Show10BarAvg = yes;
input ShowCurrentBar = yes;
input ShowPercentOf10BarAvg = 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);
AddVerticalLine(( GetDay() <> GetDay()[1]), "", Color.YeLLOW, Curve.SHORT_DASH);
# Selling Volume
Plot SellVol = selling;
SellVol.setPaintingStrategy(PaintingStrategy.Histogram);
SellVol.SetDefaultColor(Color.Red);
SellVol.HideTitle();
SellVol.HideBubble();
SellVol.SetLineWeight(5);
# Total Volume
Plot BuyVol = volume;
BuyVol.setPaintingStrategy(PaintingStrategy.Histogram);
BuyVol.SetDefaultColor(Color.Dark_Green);
BuyVol.HideTitle();
BuyVol.HideBubble();
BuyVol.SetLineWeight(5);
#Volume Data
def volLast10DayAvg = (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]) / 10;
def today = volume(period = "DAY");
def percentOf10Day = Round((today / volLast10DayAvg) * 100, 0);
def avg10Bars = (volume[1] + volume[2] + volume[3] + volume[4] + volume[5] + volume[6] + volume[7] + volume[8] + volume[9] + volume[10]) / 10;
def curVolume = volume;
def percentOf10Bar = Round((curVolume / avg10Bars) * 100, 0);
def SellVolPercent = Round((Selling / Volume) * 100, 0);
# Labels
AddLabel(Show10DayAvg, "Avg 10 Days: " + Round(volLast10DayAvg, 0), Color.LIGHT_GRAY);
AddLabel(ShowTodayVolume, "Today: " + today, (if percentOf10Day >= UnusualVolumePercent then Color.GREEN else if percentOf10Day >= 100 then Color.ORANGE else Color.LIGHT_GRAY));
AddLabel(ShowPercentOf10DayAvg, percentOf10Day + "%", (if percentOf10Day >= UnusualVolumePercent then Color.GREEN else if percentOf10Day >= 100 then Color.ORANGE else Color.WHITE) );
AddLabel(Show10BarAvg, "Avg 10 Bars: " + Round(avg10Bars, 0), Color.LIGHT_GRAY);
AddLabel(ShowCurrentBar, "Cur Bar: " + curVolume, (if percentOf10Bar >= UnusualVolumePercent then Color.GREEN else if PercentOf10Bar >= 100 then Color.ORANGE else Color.LIGHT_GRAY));
AddLabel(ShowPercentOf10BarAvg, PercentOf10Bar + "%", (if PercentOf10Bar >= UnusualVolumePercent then Color.GREEN else if PercentOf10Bar >= 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 = 50;
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));