
Author Message:
The indicator compares the size of volume bars so that if there is a noticeable increase in volume (noticeable here meaning above the indicator threshold) it marks the bar high and low prior to the bigger volume candle.
CODE:
CSS:
# https://www.tradingview.com/v/XchidFiQ/
#//@shtcoinr
#study(title="Volume Based S/R", shorttitle="VSR", precision=0, overlay=true)
# Converted and mod by Sam4Cok@Samer800 - 07/2023
input length = 20;#, minval=1)
input Threshold = 5.0;
input DisplayType = {"Support Lines Only", "Resistance Lines Only",Default "Show Both S/R", "Fair S/R"};
input useVwma = {"Yes",default "No"};
input useChartTimeframe = {default "Yes", "No"};
input ManualTimeframe = AggregationPeriod.FIFTEEN_MIN;
def na = Double.NaN;
def last = isNaN(close);
def tf = ManualTimeframe;
DefineGlobalColor("SDColor" , CreateColor(23, 105, 170));
def v; def h; def l; def c;def o;
Switch(useChartTimeframe) {
Case "Yes" :
v = volume;
h = high;
l = low;
c = close;
o = open;
Case "No" :
v = volume(Period=tf);
h = high(Period=tf);
l = low(Period=tf);
c = close(Period=tf);
o = open(Period=tf);
}
def VWMA = Average(c * v, length) / Average(v, length);
def vol;
Switch (useVwma) {
Case "Yes" :
vol = VWMA;
Case "No" :
vol = v;
}
def change = vol / vol[1] - 1;
def stdev = StDev(change, length);
def difference = change / stdev[1];
def signal = AbsValue(difference);
def cond = (signal > Threshold);
def upCandle = c > o;
def fairHi = if cond then h[1] else fairHi[1];
def fairLo = if cond then l[1] else fairLo[1];
def BullHi;
def BullLo;
def BearHi;
def BearLo;
if cond {
BullHi = if upCandle then h[1] else BullHi[1];
BullLo = if upCandle then l[1] else BullLo[1];
} else {
BullHi = BullHi[1];
BullLo = BullLo[1];
}
if cond {
BearHi = if !upCandle then h[1] else BearHi[1];
BearLo = if !upCandle then l[1] else BearLo[1];
} else {
BearHi = BearHi[1];
BearLo = BearLo[1];
}
def upHi; def upLo; def DnHi; def DnLo;
Switch (DisplayType) {
Case "Support Lines Only" :
upHi = BullHi;
upLo = BullLo;
DnHi = na;
DnLo = na;
Case "Resistance Lines Only" :
upHi = na;
upLo = na;
DnHi = BearHi;
DnLo = BearLo;
Case "Show Both S/R" :
upHi = BullHi;
upLo = BullLo;
DnHi = BearHi;
DnLo = BearLo;
Case "Fair S/R" :
upHi = fairHi;
upLo = fairLo;
DnHi = na;
DnLo = na;
}
#//plot(UpperTreshold, color=black)
plot s1 = if !upHi or last then na else upHi;
plot s2 = if !upLo or last then na else upLo;
def sMid = (s1 + s2) / 2;
plot s3 = sMid;
s1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
s2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
s3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
s3.SetStyle(Curve.SHORT_DASH);
s1.SetDefaultColor(GlobalColor("SDColor"));
s2.SetDefaultColor(GlobalColor("SDColor"));
s3.SetDefaultColor(GlobalColor("SDColor"));
plot r1 = if !DnHi or last then na else DnHi;
plot r2 = if !DnLo or last then na else DnLo;
def rMid = (r1 + r2) / 2;
plot r3 = rMid;
r1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
r2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
r3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
r3.SetStyle(Curve.SHORT_DASH);
r1.SetDefaultColor(Color.DARK_RED);
r2.SetDefaultColor(Color.DARK_RED);
r3.SetDefaultColor(Color.DARK_RED);
AddCloud(if s1!=s1[1] then na else s1, s2, GlobalColor("SDColor"));
AddCloud(if r1!=r1[1] then na else r1, r2, Color.DARK_RED);
#-- END of CODE