Hey guys. I have been working on this indicator to make it so that you can input the loopback period and that way you aren't stuck with only 30 Days/Bars. I think I've got a decent replacement (I also changed the labels that show Buy/Sell percentages so that you see one for each). However my numbers don't add up to the originals even with the simple moving average. Any hep would be appreciated.
The top window is the original version posted here. The bottom one is my mod.
Here is the code to my mod:
Here is the shareable link to my mod:
https://tos.mx/owi0kjx
The top window is the original version posted here. The bottom one is my mod.
Here is the code to my mod:
Code:
# Original author: Unknown
# Modified by 7of9
# Second Mod by Ramon DV
declare lower;
#Inputs
input ShowDayAvg = yes;
input AvgDayVolLength = 30;
input ShowTodayVolume = yes;
input ShowPercentOfDayAvg = yes;
input UnusualVolumePercent = 200;
input ShowBarAvg = yes;
input AvgBarVolLength = 30;
input ShowCurrentBar = yes;
input ShowPercentOfBarAvg = yes;
input ShowSellVolumePercent = yes;
input ShowBuyVolumePercent = yes;
input AvgType = AverageType.SIMPLE;
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 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 DayVol = volume(period = “DAY”);
def AvgDayVol = MovingAverage(AvgType, DayVol, AvgDayVolLength);
def percentOfDay = Round((DayVol / AvgDayVol) * 100, 0);
def AvgBarVol = MovingAverage(AvgType, Volume, AvgBarVolLength);
def percentOfBar = Round((Volume / AvgBarVol) * 100, 0);
def SellVolPercent = Round((Selling / Volume) * 100, 0);
def BuyVolPercent = 100 - SellVolPercent;
# Labels
AddLabel(ShowDayAvg, "Avg “ + AvgDayVolLength + “ Days: " + Round(AvgDayVol, 0), Color.LIGHT_GRAY);
AddLabel(ShowTodayVolume, "Today: " + DayVol, (if percentOfDay >= UnusualVolumePercent then Color.GREEN else if percentOfDay >= 100 then Color.ORANGE else Color.LIGHT_GRAY));
AddLabel(ShowPercentOfDayAvg, percentOfDay + "%", (if percentOfDay >= UnusualVolumePercent then Color.GREEN else if percentOfDay >= 100 then Color.ORANGE else Color.WHITE) );
AddLabel(ShowBarAvg, "Avg “ + AvgBarVolLength + ” Bars: " + Round(AvgBarVol, 0), Color.LIGHT_GRAY);
AddLabel(ShowCurrentBar, "Cur Bar: " + volume, (if percentOfBar >= UnusualVolumePercent then Color.GREEN else if percentOfBar >= 100 then Color.ORANGE else Color.LIGHT_GRAY));
AddLabel(ShowPercentOfBarAvg, percentOfBar + "%", (if percentOfBar >= UnusualVolumePercent then Color.GREEN else if percentOfBar >= 100 then Color.ORANGE else Color.WHITE) );
AddLabel(ShowSellVolumePercent, "Cur Bar Sell %: "+SellVolPercent, if SellVolPercent > BuyVolPercent then color.red else color.black);
AddLabel(ShowBuyVolumePercent, "Cur Bar Buy %: "+BuyVolPercent, if BuyVolPercent > SellVolPercent then color.green else color.black);
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));
Here is the shareable link to my mod:
https://tos.mx/owi0kjx