```
#Red_Green_Multi_Bar Buy_Sell Stats_v2 *LOWER MTF*
#Parts derived from Horseriders "Volume Buy Sell Indicator with Hot Percent for ThinkorSwim"
#declare zerobase;
#===08-06-2021 Updated to make it easier to switch inputs.====== Added "Hot Volume" to Multibar
#========08-07-2021===Removed Rate of change part of study. can still be accessed from link in post #1 if you wish to use it. https://usethinkscript.com/threads/buy-sell-volume-roc.7386/
input Time1 = {"5 min", "10 min", "15 min", "Hour", "4 Hour", "Daily", default "Weekly", "Monthly"};
input Time2 = {"5 min", "10 min", "15 min", "Hour", "4 Hour", "Daily", default "Weekly", "Monthly"};
input Time3 = {"5 min", "10 min", "15 min", "Hour", "4 Hour", "Daily", default "Weekly", "Monthly"};
#============TIME=========================
def Agg1;
switch (Time1) {
case "5 min":
Agg1 = AggregationPeriod.FIVE_MIN;
case "10 min":
Agg1 = AggregationPeriod.TEN_MIN;
case "15 min":
Agg1 = AggregationPeriod.FIFTEEN_MIN;
case "Hour":
Agg1 = AggregationPeriod.HOUR;
case "4 Hour":
Agg1 = AggregationPeriod.FOUR_HOURS;
case "Daily":
Agg1 = AggregationPeriod.DAY;
case "Weekly":
Agg1 = AggregationPeriod.WEEK;
case "Monthly":
Agg1 = AggregationPeriod.MONTH;
}
def Agg2;
switch (Time2) {
case "5 min":
Agg2 = AggregationPeriod.FIVE_MIN;
case "10 min":
Agg2 = AggregationPeriod.TEN_MIN;
case "15 min":
Agg2 = AggregationPeriod.FIFTEEN_MIN;
case "Hour":
Agg2 = AggregationPeriod.HOUR;
case "4 Hour":
Agg2 = AggregationPeriod.FOUR_HOURS;
case "Daily":
Agg2 = AggregationPeriod.DAY;
case "Weekly":
Agg2 = AggregationPeriod.WEEK;
case "Monthly":
Agg2 = AggregationPeriod.MONTH;
}
def Agg3;
switch (Time3) {
case "5 min":
Agg3 = AggregationPeriod.FIVE_MIN;
case "10 min":
Agg3 = AggregationPeriod.TEN_MIN;
case "15 min":
Agg3 = AggregationPeriod.FIFTEEN_MIN;
case "Hour":
Agg3 = AggregationPeriod.HOUR;
case "4 Hour":
Agg3 = AggregationPeriod.FOUR_HOURS;
case "Daily":
Agg3 = AggregationPeriod.DAY;
case "Weekly":
Agg3 = AggregationPeriod.WEEK;
case "Monthly":
Agg3 = AggregationPeriod.MONTH;
}
#==============END TIME==================
declare lower;
#Inputs
input ShowFiveBar = yes;
input ShowTenBar = yes;
#=======Agg1===========
def O1 = open(period = agg1);
def H1 = high(period = agg1);
def C1 = close(period = agg1);
def L1 = low(period = agg1);
def V1 = volume(period = agg1);
def buying1 = V1 * (C1 - L1) / (H1 - L1);
def selling1 = V1 * (H1 - C1) / (H1 - L1);
def buy1agg1 = buying1 + buying1[1];
def buy2agg1 = buying1 + buying1[1] + buying1[2];
def buy3agg1 = buying1 + buying1[1] + buying1[2] + buying1[3];
def buy4agg1 = buying1 + buying1[1] + buying1[2] + buying1[3] + buying1[4];
def buy5agg1 = buying1 + buying1[1] + buying1[2] + buying1[3] + buying1[4] + buying1[5];
def buy6agg1 = buying1 + buying1[1] + buying1[2] + buying1[3] + buying1[4] + buying1[5] + buying1[6];
def buy7agg1 = buying1 + buying1[1] + buying1[2] + buying1[3] + buying1[4] + buying1[5] + buying1[6] + buying1[7];
def buy8agg1 = buying1 + buying1[1] + buying1[2] + buying1[3] + buying1[4] + buying1[5] + buying1[6] + buying1[7] + buying1[8];
def buy9agg1 = buying1 + buying1[1] + buying1[2] + buying1[3] + buying1[4] + buying1[5] + buying1[6] + buying1[7] + buying1[8] + buying1[9];
def buy10agg1 = buying1 + buying1[1] + buying1[2] + buying1[3] + buying1[4] + buying1[5] + buying1[6] + buying1[7] + buying1[8] + buying1[9] + buying1[10];
def curbuyVolume5agg1 = (buy1agg1 + buy2agg1 + buy3agg1 + buy4agg1 + buy5agg1) / 5;
def curbuyvol10agg1 = (buy1agg1 + buy2agg1 + buy3agg1 + buy4agg1 + buy5agg1 + buy6agg1 + buy7agg1 + buy8agg1 + buy9agg1 + buy10agg1) / 10;
def sell1agg1 = Selling1 + Selling1[1];
def sell2agg1 = Selling1 + Selling1[1] + Selling1[2];
def sell3agg1 = Selling1 + Selling1[1] + Selling1[2] + Selling1[3];
def sell4agg1 = Selling1 + Selling1[1] + Selling1[2] + Selling1[3] + Selling1[4];
def sell5agg1 = Selling1 + Selling1[1] + Selling1[2] + Selling1[3] + Selling1[4] + Selling1[5];
def sell6agg1 = Selling1 + Selling1[1] + Selling1[2] + Selling1[3] + Selling1[4] + Selling1[5] + selling1[6];
def sell7agg1 = Selling1 + Selling1[1] + Selling1[2] + Selling1[3] + Selling1[4] + Selling1[5] + selling1[6] +selling1[7];
def sell8agg1 = Selling1 + Selling1[1] + Selling1[2] + Selling1[3] + Selling1[4] + Selling1[5]+ selling1[6] +selling1[7] + selling1[8];
def sell9agg1 = Selling1 + Selling1[1] + Selling1[2] + Selling1[3] + Selling1[4] + Selling1[5]+ selling1[6] + selling1[7] + selling1[8] + Selling1[9];
def sell10agg1 = Selling1 + Selling1[1] + Selling1[2] + Selling1[3] + Selling1[4] + Selling1[5] + Selling1[6] + selling1[7] + selling1[8] + selling1[9] + selling1[10];
def cursellVolume5agg1 = (sell1agg1 + sell2agg1 + sell3agg1 + sell4agg1 + sell5agg1) / 5;
def cursellvol10agg1 = (sell1agg1 + sell2agg1 + sell3agg1 + sell4agg1 + sell5agg1 + sell6agg1 + sell7agg1 + sell8agg1 + sell9agg1 + sell10agg1) / 10;
def Sellbuydiff5agg1 = (curbuyVolume5agg1 - cursellVolume5agg1);
def Sellbuydiff10agg1 = (curbuyvol10agg1 - cursellvol10agg1);
#============AGG1 plots===============
plot V5agg1 = if !ShowFiveBar then Double.NaN else .08;
V5agg1.SetPaintingStrategy(PaintingStrategy.LINE);
#V2.SetDefaultColor(Color.DARK_GREEN);
V5agg1.HideTitle();
V5agg1.HideBubble();
V5agg1.SetLineWeight(3);
V5agg1.assignValueColor(if curbuyVolume5agg1 > cursellVolume5agg1 then createColor(9,206,138) else if curbuyVolume5agg1 < cursellVolume5agg1 then createColor(206,9,26) else color.DARK_GRAY );
plot V10agg1 = if !showTenBar then Double.NaN else .08;
V10agg1.SetPaintingStrategy(PaintingStrategy.POINTS);
#V2.SetDefaultColor(Color.DARK_GREEN);
V10agg1.HideTitle();
V10agg1.HideBubble();
V10agg1.SetLineWeight(5);
V10agg1.assignValueColor(if curbuyVol10agg1 > cursellVol10agg1 then createColor(38,129,88) else if curbuyVol10agg1 < cursellVol10agg1 then createColor(138,5,16) else color.DARK_GRAY );
#======AGG2======================================================
def O2 = open(period = agg2);
def H2 = high(period = agg2);
def C2 = close(period = agg2);
def L2 = low(period = agg2);
def V2 = volume(period = agg2);
def buying2 = V2 * (C2 - L2) / (H2 - L2);
def selling2 = V2 * (H2 - C2) / (H2 - L2);
# Total Volume
def curVolume2 = volume(period = agg2);
def SellVolPercent2 = Round((selling2 / volume(period = agg2)) * 100, 0);
#Buy/sell difference================================
def buy1agg2 = buying2 + buying2[1];
def buy2agg2 = buying2 + buying2[1] + buying2[2];
def buy3agg2 = buying2 + buying2[1] + buying2[2] + buying2[3];
def buy4agg2 = buying2 + buying2[1] + buying2[2] + buying2[3] + buying2[4];
def buy5agg2 = buying2 + buying2[1] + buying2[2] + buying2[3] + buying2[4] + buying2[5];
def buy6agg2 = buying2 + buying2[1] + buying2[2] + buying2[3] + buying2[4] + buying2[5] + buying2[6];
def buy7agg2 = buying2 + buying2[1] + buying2[2] + buying2[3] + buying2[4] + buying2[5] + buying2[6] + buying2[7];
def buy8agg2 = buying2 + buying2[1] + buying2[2] + buying2[3] + buying2[4] + buying2[5] + buying2[6] + buying2[7] + buying2[8];
def buy9agg2 = buying2 + buying2[1] + buying2[2] + buying2[3] + buying2[4] + buying2[5] + buying2[6] + buying2[7] + buying2[8] + buying2[9];
def buy10agg2 = buying2 + buying2[1] + buying2[2] + buying2[3] + buying2[4] + buying2[5] + buying2[6] + buying2[7] + buying2[8] + buying2[9] + buying2[10];
def curbuyVolume5agg2 = (buy1agg2 + buy2agg2 + buy3agg2 + buy4agg2 + buy5agg2) / 5;
def curbuyvol10agg2 = (buy1agg2 + buy2agg2 + buy3agg2 + buy4agg2 + buy5agg2 + buy6agg2 + buy7agg2 + buy8agg2 + buy9agg2 + buy10agg2) / 10;
def sell1agg2 = Selling2 + Selling2[1];
def sell2agg2 = Selling2 + Selling2[1] + Selling2[2];
def sell3agg2 = Selling2 + Selling2[1] + Selling2[2] + Selling2[3];
def sell4agg2 = Selling2 + Selling2[1] + Selling2[2] + Selling2[3] + Selling2[4];
def sell5agg2 = Selling2 + Selling2[1] + Selling2[2] + Selling2[3] + Selling2[4] + Selling2[5];
def sell6agg2 = Selling2 + Selling2[1] + Selling2[2] + Selling2[3] + Selling2[4] + Selling2[5] + selling2[6];
def sell7agg2 = Selling2 + Selling2[1] + Selling2[2] + Selling2[3] + Selling2[4] + Selling2[5] + selling2[6] +selling2[7];
def sell8agg2 = Selling2 + Selling2[1] + Selling2[2] + Selling2[3] + Selling2[4] + Selling2[5]+ selling2[6] +selling2[7] + selling2[8];
def sell9agg2 = Selling2 + Selling2[1] + Selling2[2] + Selling2[3] + Selling2[4] + Selling2[5]+ selling2[6] +selling2[7] + selling2[8] + selling2[9];
def sell10agg2 = Selling2 + Selling2[1] + Selling2[2] + Selling2[3] + Selling2[4] + Selling2[5]+ selling2[6] +selling2[7] + selling2[8] + selling2[9] + selling2[10];
def cursellVolume5agg2 = (sell1agg2 + sell2agg2 + sell3agg2 + sell4agg2 + sell5agg2) / 5;
def cursellvol10agg2 = (sell1agg2 + sell2agg2 + sell3agg2 + sell4agg2 + sell5agg2 + sell6agg2 + sell7agg2 + sell8agg2 + sell9agg2 + sell10agg2) / 10;
def Sellbuydiff5agg2 = (curbuyVolume5agg2 - cursellVolume5agg2);
def Sellbuydiff10agg2 = (curbuyvol10agg2 - cursellvol10agg2);
#======AGG2 Plots========
plot V5agg2 = if !ShowFiveBar then Double.NaN else .06;
V5agg2.SetPaintingStrategy(PaintingStrategy.LINE);
#V2.SetDefaultColor(Color.DARK_GREEN);
V5agg2.HideTitle();
V5agg2.HideBubble();
V5agg2.SetLineWeight(3);
V5agg2.assignValueColor(if curbuyVolume5agg2 > cursellVolume5agg2 then createColor(9,206,138) else if curbuyVolume5agg2 < cursellVolume5agg2 then createColor(206,9,26) else color.DARK_GRAY );
plot V10agg2 = if !showTenBar then Double.NaN else .06;
V10agg2.SetPaintingStrategy(PaintingStrategy.POINTS);
#V2.SetDefaultColor(Color.DARK_GREEN);
V10agg2.HideTitle();
V10agg2.HideBubble();
V10agg2.SetLineWeight(5);
V10agg2.assignValueColor(if curbuyVol10agg2 > cursellVol10agg2 then createColor(38,129,88) else if curbuyVol10agg2 < cursellVol10agg2 then createColor(138,5,16) else color.DARK_GRAY );
#=========AGG3================================================================
def O = open(period = agg3);
def H = high(period = agg3);
def C = close(period = agg3);
def L = low(period = agg3);
def V = volume(period = agg3);
def buying = V * (C - L) / (H - L);
def selling = V * (H - C) / (H - L);
def buy1 = buying + buying[1];
def buy2 = buying + buying[1] + buying[2];
def buy3 = buying + buying[1] + buying[2] + buying[3];
def buy4 = buying + buying[1] + buying[2] + buying[3] + buying[4];
def buy5 = buying + buying[1] + buying[2] + buying[3] + buying[4] + buying[5];
def buy6 = buying + buying[1] + buying[2] + buying[3] + buying[4] + buying[5] + buying[6];
def buy7 = buying + buying[1] + buying[2] + buying[3] + buying[4] + buying[5] + buying[6] + buying[7];
def buy8 = buying + buying[1] + buying[2] + buying[3] + buying[4] + buying[5] + buying[6] + buying[7] + buying[8];
def buy9 = buying + buying[1] + buying[2] + buying[3] + buying[4] + buying[5] + buying[6] + buying[7] + buying[8] + buying[9];
def buy10 = buying + buying[1] + buying[2] + buying[3] + buying[4] + buying[5] + buying[6] + buying[7] + buying[8] + buying[9] + buying[10];
def curbuyVolume5 = (buy1 + buy2 + buy3 + buy4 + buy5) / 5;
def curbuyvol10 = (buy1 + buy2 + buy3 + buy4 + buy5 + buy6 + buy7 + buy8 + buy9 + buy10) / 10;
def sell1 = Selling + Selling[1];
def sell2 = Selling + Selling[1] + Selling[2];
def sell3 = Selling + Selling[1] + Selling[2] + Selling[3];
def sell4 = Selling + Selling[1] + Selling[2] + Selling[3] + Selling[4];
def sell5 = Selling + Selling[1] + Selling[2] + Selling[3] + Selling[4] + Selling[5];
def sell6 = Selling + Selling[1] + Selling[2] + Selling[3] + Selling[4] + Selling[5] + selling[6];
def sell7 = Selling + Selling[1] + Selling[2] + Selling[3] + Selling[4] + Selling[5] + selling[6] +selling[7];
def sell8 = Selling + Selling[1] + Selling[2] + Selling[3] + Selling[4] + Selling[5]+ selling[6] +selling[7] + selling[8];
def sell9 = Selling + Selling[1] + Selling[2] + Selling[3] + Selling[4] + Selling[5]+ selling[6] +selling[7] + selling[8] + selling[9];
def sell10 = Selling + Selling[1] + Selling[2] + Selling[3] + Selling[4] + Selling[5]+ selling[6] +selling[7] + selling[8] + selling[9] + selling[10];
def cursellVolume5 = (sell1 + sell2 + sell3 + sell4 + sell5) / 5;
def cursellvol10 = (sell1 + sell2 + sell3 + sell4 + sell5 + sell6 + sell7 + sell8 + sell9 + sell10) / 10;
def Sellbuydiff5 = (curbuyVolume5 - cursellVolume5);
def Sellbuydiff10 = (curbuyvol10 - cursellvol10);
#====AGG3 Plots============
plot V5agg3 = if !ShowFiveBar then Double.NaN else .04;
V5agg3.SetPaintingStrategy(PaintingStrategy.LINE);
#V2.SetDefaultColor(Color.DARK_GREEN);
V5agg3.HideTitle();
V5agg3.HideBubble();
V5agg3.SetLineWeight(3);
V5agg3.assignValueColor(if curbuyVolume5 > cursellVolume5 then createColor(9,206,138) else if curbuyVolume5 < cursellVolume5 then createColor(206,9,26) else color.DARK_GRAY );
plot V10agg3 = if !showTenBar then Double.NaN else .04;
V10agg3.SetPaintingStrategy(PaintingStrategy.POINTS);
#V2.SetDefaultColor(Color.DARK_GREEN);
V10agg3.HideTitle();
V10agg3.HideBubble();
V10agg3.SetLineWeight(5);
V10agg3.assignValueColor(if curbuyVol10 > cursellVol10 then createColor(38,129,88) else if curbuyVol10 < cursellVol10 then createColor(138,5,16) else color.DARK_GRAY );
def PlaceH = .1;
plot PH1 = PlaceH;
ph1.setpaintingStrategy(paintingStrategy.LINE);
ph1.setlineWeight(5);
ph1.setdefaultColor(color.DARK_GRAY);
def PlaceH2 = .02;
plot PH2 = PlaceH2;
ph2.setpaintingStrategy(paintingStrategy.LINE);
ph2.setlineWeight(5);
ph2.setdefaultColor(color.DARK_GRAY);
addcloud(placeH2, 0, color.BLACK);
addcloud(.12, placeH, color.BLACK);
```