Quote from the script creator:
This indicator combines two features: VWAP bands for range trading and trends for trend-following.
The white bands offer support/resistance levels ideal for range trading: short when rejecting off the upper band, long when rejecting off the lower. Take profit either when hitting the (faint gray) midline and/or when hitting the band on the far side.
The trend analysis shows green or red ranges above or below the bands to indicate trend strength - larger swaths of green or red indicates strong trend while shorter swathes indicate weak. If the upper trend color doesn't match the lower trend color, the trend is undecided or transitioning.
Optionally, trend initiation indicators can be turned on to show above/below candles where a trend switch is taking place.
Here is the script
This indicator combines two features: VWAP bands for range trading and trends for trend-following.
The white bands offer support/resistance levels ideal for range trading: short when rejecting off the upper band, long when rejecting off the lower. Take profit either when hitting the (faint gray) midline and/or when hitting the band on the far side.
The trend analysis shows green or red ranges above or below the bands to indicate trend strength - larger swaths of green or red indicates strong trend while shorter swathes indicate weak. If the upper trend color doesn't match the lower trend color, the trend is undecided or transitioning.
Optionally, trend initiation indicators can be turned on to show above/below candles where a trend switch is taking place.
Here is the script
CSS:
#//This indicator combines two features: VWAP bands for range trading and trends for trend-following.
#//The white bands offer support/resistance levels ideal for range trading: short when rejecting off the upper band, long when rejecting off the lower. Take profit either when hitting the (faint gray) midline and/or when hitting the band on the far side.
#//The trend analysis shows green or red ranges above or below the bands to indicate trend strength - larger swaths of green or red indicates strong trend while shorter swathes indicate weak. If the upper trend color doesn't match the lower trend color, the trend is undecided or transitioning.
#//Optionally, trend initiation indicators can be turned on to show above/below candles where a trend switch is taking place.
#// © Austimize
#https://www.tradingview.com/script/NXYJAL69-VWAP-Band-Trend/
#indicator("VWAP Band Trend", shorttitle = "VWAPbt", overlay = true)
# Converted by SamCok @ samer800 - 08/2022
input length = 100; # "Length"
input stdevMulti = 1.5; # "Stdev Multiplier"
input stdevMulti2 = 2; # "Stdev 2nd Multiplier"
input showTrend = yes; # "Show Trend?"
input showTrendCrosses = no; # "Show Trend Crossovers?"
input Source = hlc3; # "Source"
def na = Double.NaN;
########### Color ################
DefineGlobalColor("buyFill" , Color.GREEN);
DefineGlobalColor("sellFill" , Color.RED);
DefineGlobalColor("bandFill" , Color.WHITE);
##################################
def sum = Sum(volume, length);
def sumSrc = Sum(Source * volume, length);
def sumSrcSrc = Sum(volume * Power(Source, 2), length);
def VWAP1 = sumSrc / sum;
def variance = sumSrcSrc / sum - Power(vwap1, 2);
def Deviation = Sqrt(if variance < 0 then 0 else variance);
def thresholdDown = VWAP1 - Deviation * stdevMulti;
def thresholdUp = VWAP1 + Deviation * stdevMulti;
def td = thresholdDown;
#td.SetDefaultColor(GlobalColor("buyFill"));
def tu = thresholdUp;
#tu.SetDefaultColor(GlobalColor("sellFill"));
def v3 = VWAP1 - Deviation * stdevMulti2;
#v3.SetDefaultColor(GlobalColor("buyFill"));
AddCloud(v3, td, GlobalColor("bandFill"), GlobalColor("bandFill"), no);
def v4 = VWAP1 + Deviation * stdevMulti2;
#v4.SetDefaultColor(GlobalColor("sellFill"));
AddCloud(v4, tu, GlobalColor("bandFill"), GlobalColor("bandFill"), no);
plot VolWAP = VWAP1;
VolWAP.SetDefaultColor(GlobalColor("bandFill"));
def psVWAP = reference VWAP;
def tup2 = psVWAP + StDev(psVWAP, length) * stdevMulti;
def tdn2 = psVWAP - StDev(psVWAP, length) * stdevMulti;
def p2 = if showTrend then psVWAP else na;
#p2.SetDefaultColor(GlobalColor("bandFill"));
def tu2 = if showTrend then tup2 else na;
#tu2.SetDefaultColor(GlobalColor("sellFill"));
def td2 = if showTrend then tdn2 else na;
#td2.SetDefaultColor(GlobalColor("buyFill"));
AddCloud(if showTrend then (if thresholdUp < tup2 then tu2 else na) else na, tu, GlobalColor("buyFill"));
AddCloud(if showTrend then (if thresholdUp > tup2 then tu2 else na) else na, tu, GlobalColor("sellFill"));
AddCloud(if showTrend then (if thresholdDown < tdn2 then td2 else na) else na, td, GlobalColor("buyFill"));
AddCloud(if showTrend then (if thresholdDown > tdn2 then td2 else na) else na, td, GlobalColor("sellFill"));
plot psVolWAP = psVWAP;
psVolWAP.setDefaultColor(getColor(0));
plot CrossDn1 = if showTrendCrosses then if tdn2 crosses below thresholdDown then high else na else na;
CrossDn1.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
CrossDn1.SetDefaultColor(Color.RED);
CrossDn1.SetLineWeight(4);
plot CrossUp1 = if showTrendCrosses then if tdn2 crosses above thresholdDown then low else na else na;
CrossUp1.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
CrossUp1.SetDefaultColor(Color.GREEN);
CrossUp1.SetLineWeight(4);
plot CrossDn2 = if showTrendCrosses then if tup2 crosses below thresholdUp then high else na else na;
CrossDn2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
CrossDn2.SetDefaultColor(Color.RED);
CrossDn2.SetLineWeight(3);
plot CrossUp2 = if showTrendCrosses then if tup2 crosses above thresholdUp then low else na else na;
CrossUp2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
CrossUp2.SetDefaultColor(Color.GREEN);
CrossUp2.SetLineWeight(3);
plot CrossVdn = if showTrendCrosses then if psVWAP crosses below VWAP1 then high else na else na;
CrossVdn.SetPaintingStrategy(PaintingStrategy.SQUARES);
CrossVdn.SetDefaultColor(Color.RED);
CrossVdn.SetLineWeight(4);
plot CrossVup = if showTrendCrosses then if psVWAP crosses above VWAP1 then low else na else na;
CrossVup.SetPaintingStrategy(PaintingStrategy.SQUARES);
CrossVup.SetDefaultColor(Color.GREEN);
CrossVup.SetLineWeight(4);
#### End ####