# HORSERIDER VOLUME V3 - @HODL
# Volume Buy Sell Pressure with Hot Percent for ThinkorSwim
# Show total volume in gray. Buying volume in green. Sell Volume in red.
# Volume average is gray line.
# Specified percent over average volume is cyan triangles.
# Horserider 12/30/2019 derived from some already existing studies.
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © sudoMode
#indicator(title = 'Pressure Gauge', shorttitle = 'Equilibrium', overlay = false)
# Converted and mod by Sam4Cok@Samer800 - 05/2023
declare lower;
#Inputs
input ControlPercent = 20; #hint above or below this value colors label
input ControlAvgPercent = 10;
input lengthVolAvgLabel = 30;
input lengthAvgXBarsControl = 30; #hint shows who is in control over X bars
input HotPct = 150.0; #hint total volume of bar greater than hotpct = cyan triangle
input ShowTodayVolume = yes;
input ShowBarVolume = yes;
input ShowBuySellPercent = yes;
input ShowBuySellPercentAvgXBars = yes;
input ShowCurrentBarControl = yes;
input ShowControlAvgXBars = yes;
input type = { default SMP, EXP } ;
#Definitions
def lengthVolAvgPlot = 21;
def tradeDaytimeOnly = yes; #hint tradeDaytimeOnly: (IntraDay Only) Only perform trades during hours stated
def OpenTime = 0930; #hint OpenTime: Opening time of market
def CloseTime = 1600; #hint CloseTime: Closing time of market
def length_HV = 20 ;
def Begin = SecondsFromTime(OpenTime);
def End = SecondsTillTime(CloseTime);
def isIntraDay = if GetAggregationPeriod() > 14400000 or GetAggregationPeriod() == 0 then 0 else 1;
def MarketOpen = if !tradeDaytimeOnly or !isIntraDay then 1 else if tradeDaytimeOnly and isIntraDay and Begin > 0 and End > 0 then 1 else 0;
def na = Double.NaN;
#Horserider Volume
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);
Plot SellVol = selling;
SellVol.setPaintingStrategy(PaintingStrategy.Histogram);
SellVol.SetDefaultColor(Color.Red);
SellVol.HideTitle();
SellVol.HideBubble();
SellVol.SetLineWeight(1);
plot TV = volume;
TV.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
TV.SetDefaultColor(Color.GRAY);
TV.SetLineWeight(1);
Plot BuyVol = buying;
BuyVol.setPaintingStrategy(PaintingStrategy.Histogram);
BuyVol.SetDefaultColor(Color.Green);
BuyVol.HideTitle();
BuyVol.HideBubble();
BuyVol.SetLineWeight(5);
Script F {
Input Length = 30;
def data = volume(period = "DAY");
def data1 =
fold a = 1
to Length + 1
with K = 0
do K + data[a];
def Vol30day_Average = data1 / length;
plot Vol = Vol30day_Average;
}
Script G {
Input Length = 30;
def data = volume;
def data1 =
fold a = 1
to Length + 1
with k = 0
do k + data[a];
def Vol30Bars_Average = data1 / length;
plot Vol2 = Vol30Bars_Average;
}
def AvgVolume30_Day = F(lengthVolAvgLabel);
def AvgVolume30_Bars = G(lengthVolAvgLabel);
def today = volume(period = "DAY");
def curVolume = volume;
def diffFromAvg = today - AvgVolume30_Day;
def diffFromAvgBars = curVolume - AvgVolume30_Bars;
def percentDiffdays = Round((diffFromAvg / AvgVolume30_Day) * 100, 0);
def percentOf30Bar = Round((curVolume / AvgVolume30_Bars) * 100, 0);
def SellVolPercent = Round((Selling / Volume) * 100, 0);
def buyVolPercent = Round((Buying / Volume) * 100, 0);
def percentDiffBars = Round((diffFromAvgBars / AvgVolume30_Bars) * 100, 0);
def BarsBias = if (percentDiffBars <> ControlPercent) and (curVolume > AvgVolume30_Bars) then 1 else if (percentDiffBars <> ControlPercent) and (curVolume < AvgVolume30_Bars) then -1 else 0;
def DaysBias = if (percentDiffdays <> ControlPercent) and (today > AvgVolume30_Day) then 1 else if (percentDiffdays <> ControlPercent) and (curVolume < AvgVolume30_Day) then -1 else 0;
def percentdiff = (sellvolpercent - buyvolpercent);
def percentdiffAbs = absvalue(sellvolpercent - buyvolpercent);
def SellingAvgBars = average(selling,lengthAvgXBarsControl);
def BuyingAvgBars = average(buying,lengthAvgXBarsControl);
def sellavgpercent = (round(AvgVolume30_Bars,0) - Round(SellingAvgBars,0))/Round(AvgVolume30_Bars,0)*100;
def buyavgpercent = (round(AvgVolume30_Bars,0) - Round(BuyingAvgBars,0))/Round(AvgVolume30_Bars,0)*100;
def perdiffavg = absvalue(sellavgpercent - buyavgpercent);
plot VolAvg = Average(volume, lengthVolAvgPlot);
VolAvg.Setdefaultcolor(Color.Gray);
def MA = if type == type.SMP then SimpleMovingAvg(volume, length_HV) else MovAvgExponential(volume, length_HV);
plot HV = if (100 * ((volume / ma) - 1) >= hotPct) then ma else Double.NaN;
hv.SetDefaultColor( Color.CYAN);
hv.SetLineWeight(2) ;
hv.SetPaintingStrategy( PaintingStrategy.TRIANGLES);
def bn = barnumber();
def HighV = if (100 * ((volume / ma) - 1) >= hotPct) then 1 else 0;
def HighV_Foldcondition = if MarketOpen and (100 * ((volume / ma) - 1) >= hotPct) and (buyvolPercent > sellvolpercent) then 1
else if MarketOpen and (100 * ((volume / ma) - 1) >= hotPct) and (buyvolPercent < sellvolpercent) then -1 else 0;
input HighVLookback = 100;
def HighV_lookback = fold uu = 1 to HighVLookback with pp do pp + HighV_Foldcondition[uu];
#Labels
##############################################
## TODAYS VOLUME LABEL
##############################################
AddLabel(ShowTodayVolume,
if (DaysBias == 1) then "Todays Volume: " + (today) + " | " + absvalue(percentDiffdays) + "% Above " + lengthVolAvgLabel + " Day Average (" + Round(AvgVolume30_Day, 0)+ ")"
else if (DaysBias == -1) then "Todays Volume: " + (today) + " | " + absvalue(percentDiffdays) + "% Below " + lengthVolAvgLabel + " Day Average (" + Round(AvgVolume30_Day, 0)+ ")"
else if (DaysBias == 0) and (today > AvgVolume30_Bars) then "Todays Volume: " + (today) + " | " + absvalue(percentDiffdays) + "% above " + lengthVolAvgLabel + " Day Average (" + Round(AvgVolume30_Day, 0)+ ")"
else if (DaysBias == 0) and (today < AvgVolume30_Bars) then "Todays Volume: " + (today) + " | " + absvalue(percentDiffdays) + "% below " + lengthVolAvgLabel + " Day Average (" + Round(AvgVolume30_Day, 0)+ ")"
else "Todays Volume: " + (today) + " | " + absvalue(percentDiffdays) + lengthVolAvgLabel + " Day Average (" + Round(AvgVolume30_day, 0)+ ")",
(if (DaysBias == 1) then Color.green
else if (DaysBias == -1) then Color.RED
else if (DaysBias == 0) and (curVolume > AvgVolume30_Day) then color.orange
else if (DaysBias == 0) and (curVolume < AvgVolume30_Day) then color.orange
else color.light_gray));
##############################################
## CURRENT BUY % LABEL
##############################################
AddLabel(ShowBuySellPercent, "Current Bar Buy: " + BuyVolPercent + "%",
(if (BuyVolPercent > Sellvolpercent) and highV then Color.cyan
else if (BuyVolPercent > Sellvolpercent) and (BuyVolPercent >= ControlPercent) then Color.Green
else if (BuyVolPercent < Sellvolpercent) then Color.Gray
else Color.current));
##############################################
## CURRENT SELL % LABEL
##############################################
AddLabel(ShowBuySellPercent, "Current Bar Sell: " + SellVolPercent + "%",
(if (BuyVolPercent < Sellvolpercent) and highV then Color.cyan
else if (BuyVolPercent < Sellvolpercent) and (SellVolPercent >= ControlPercent) then Color.red
else if (BuyVolPercent > Sellvolpercent) then Color.Gray
else Color.current));
###########################################################
## CURRENT CONTROL % LABEL (Buy % minus Sell % or Sell % mins Buy %)
###########################################################
AddLabel(ShowCurrentBarControl, "Current Bar Control: " + percentdiff + "%",
(if (BuyVolPercent > Sellvolpercent) and highV then Color.cyan
else if (BuyVolPercent > Sellvolpercent) and (percentdiff >= ControlPercent) then Color.green
else if (BuyVolPercent < Sellvolpercent) and (percentdiff >= ControlPercent) then Color.red
else if (percentdiff < ControlPercent) then Color.Gray
else Color.current));
##############################################
## CURRENT BAR VOLUME
##############################################
AddLabel(ShowBarVolume,
if (BarsBias == 1) then "Current Bar Volume: " + (curVolume) + " | " + absvalue(percentDiffBars) + "% Above " + lengthVolAvgLabel + " Bar Average (" + Round(AvgVolume30_Bars, 0)+ ")"
else if (BarsBias == -1) then "Current Bar Volume: " + (curVolume) + " | " + absvalue(percentDiffBars) + "% Below " + lengthVolAvgLabel + " Bar Average (" + Round(AvgVolume30_Bars, 0)+ ")"
else if (BarsBias == 0) and (curVolume > AvgVolume30_Bars) then "Current Bar Volume: " + (curVolume) + " | " + absvalue(percentDiffBars) + "% above " + lengthVolAvgLabel + " Bar Average (" + Round(AvgVolume30_Bars, 0)+ ")"
else if (BarsBias == 0) and (curVolume < AvgVolume30_Bars) then "Current Bar Volume: " + (curVolume) + " | " + absvalue(percentDiffBars) + "% below " + lengthVolAvgLabel + " Bar Average (" + Round(AvgVolume30_Bars, 0)+ ")"
else "Current Bar Volume: " + (curVolume) + " | " + absvalue(percentDiffBars) + lengthVolAvgLabel + " Bar Average (" + Round(AvgVolume30_Bars, 0)+ ")",
(if (BarsBias == 1) then Color.green
else if (BarsBias == -1) then Color.RED
else if (BarsBias == 0) and (curVolume > AvgVolume30_Bars) then color.orange
else if (BarsBias == 0) and (curVolume < AvgVolume30_Bars) then color.orange
else Color.light_gray));
######################################################################################
## AVERAGE BUY % OF X NUMBER OF BARS (ADJUSTABLE LENGTH IN SETTINGS - 30 IS DEFAULT)
######################################################################################
addlabel(ShowBuySellPercentAvgXBars,lengthAvgXBarsControl + " Bar Average Buy: " + round(buyavgpercent,0) + "%",
(if (buyavgpercent > SellingAvgBars) and (perdiffavg >= ControlAvgPercent) then Color.light_green
else if (buyavgpercent < SellingAvgBars) and (perdiffavg >= ControlAvgPercent) then Color.Gray
else if (perdiffavg < ControlAvgPercent) then Color.light_Gray
else Color.current));
#######################################################################################
## AVERAGE SELL % OF X NUMBER OF BARS (ADJUSTABLE LENGTH IN SETTINGS - 30 IS DEFAULT)
#######################################################################################
addlabel(ShowBuySellPercentAvgXBars,lengthAvgXBarsControl + " Bar Average Sell: " + round(sellavgpercent,0) + "%",
(if (buyavgpercent > SellingAvgBars) and (perdiffavg >= ControlAvgPercent) then Color.gray
else if (buyavgpercent < SellingAvgBars) and (perdiffavg >= ControlAvgPercent) then Color.Light_red
else if (perdiffavg < ControlAvgPercent) then Color.light_Gray
else Color.current));
#########################################################################################
## AVERAGE CONTROL % OF X NUMBER OF BARS (ADJUSTABLE LENGTH IN SETTINGS - 30 IS DEFAULT)
#########################################################################################
addlabel(ShowControlAvgXBars,lengthAvgXBarsControl + " Bar Average Control: " + round(perdiffavg,0) + "%",
(if (buyavgpercent > SellingAvgBars) and (perdiffavg >= ControlAvgPercent) then Color.light_green
else if (buyavgpercent < SellingAvgBars) and (perdiffavg >= ControlAvgPercent) then Color.Light_red
else if (perdiffavg < ControlAvgPercent) then Color.light_Gray
else Color.current));
The input type = { default SMP, EXP } ;"
Would you be able to add other types of moving average ex Tema, dema, mama, alma,