Ultimate VWAP Indicator for ThinkorSwim

Welkin

Welkin

Active member
VIP
This is kind of an all in one VWAP Deviation Bands indicator with some other bells and whistles.

Main VWAP with 3 Standard Deviation bands can be set to Daily, Weekly, or Monthly. Clouds form when Daily 2nd Deviation Upper/Lowerband crosses the Weekly 2nd Std Deviation Upper/Lowerband. Same goes for Weekly x Monthly 2nd Std Deviation Upper/Lowerbands. Included Squeeze Clouds. Can toggle painting VWAP and/or Candlesticks according to Heiken Ashi Trend.

I had someone ask me what the point of showing 2nd deviation crossovers for the Daily x Weekly and Weekly x Monthly VWAP is. After looking at thousands of charts I've found that this a great indicator of a top/bottom/pivot area being reached when price breaks out after trading within or touch and rejection of those clouds. I recommend you do your own research and come to your own conclusions as to whether this is the case.

I kept the color scheme for the deviation bands and crossover clouds a bit dark because if you use other indicators on top of it, such as pivot points, moving averages, etc... i find it helps to better distinguish between everything and not have it be so distracting. At least it works that way for me, others may differ. Feel free to change them if you so choose.

Please note that the weekly and monthly vwaps reset at the start of a new week/month. You will see them split off from the daily vwap as a new week or month progresses.

Added MTF Squeeze clouds as seen from this post.
By default the yellow squeeze cloud is current aggregation, orange is 30 min, and red is 1 hour.

Made some quality of life adjustments. Added labels that will show a warning if your current chart's time frame is set higher than what the VWAPAggregation (DAY, WEEK, or MONTH) is set to.

Example: if your current chart's time frame is set to Daily or greater and VWAPAggregation is set to DAY, the VWAP Deviation bands will not show unless you have it set to WEEK or MONTH. Same thing applies for if your time frame is set to Weekly and VWAP Aggregation is set to WEEK then VWAP Aggregation should be changed to MONTH.

A seperate warning label will also show for the Squeeze cloud aggregations, only appearing if you have them enabled and your current charts time frame is greater than SqzAggregation2 or SqzAggregation3. Note that Squeeze1 will always adjust to your current chart time frame.



Added labels that shows $ distance from the daily, weekly, and monthly VWAPS and will change color according to which is nearest in price (by default daily = white, weekly = orange, monthly = red).
Added label that shows deviation bandwidth
Added labels that show whether daily x weekly and weekly x monthly 2nd deviation bands are actively crossing and will change color according to what the cloud colors are set to.
Added labels that show whether Squeeze1, 2, or 3 clouds are actively being plotted
Added Alerts for price crossing above or below the set VWAP bands specified by user
Added Alerts for when Squeeze 1, 2, or 3 begin plotting
Added Vertical Lines that draw when Squeeze 1, 2, or 3 begin plotting.








http://tos.mx/bOMweGQ


Code:
#VWAP Deviation Bands
#VWAP DAILY x WEEKLY AND WEEKLY x MONTHLY 2nd deviation CROSSOVER CLOUDS
#VWAP Alerts
#Paint VWAP or Candlesticks according to Heiken Ashi Trend
#Bollinger and Keltner MTF Squeeze Clouds
#[email protected]
#version 7.29.2020

declare upper;
def NA = Double.NaN;

#Colored VWAP to Heiken Ashi Trend toggles
input paintHeikenAshiCandles = yes;
input paintHeikenAshiVWAP = no;
def haAgg1 = GetAggregationPeriod();
input haAgg2 = AggregationPeriod.FIVE_MIN;
input paintVwapBullBear = yes;
#VWAP Deviation Band inputs
input vwapAggregation = {default "DAY", "WEEK", "MONTH"};

input vwapAlertSound = Sound.Ring;
input vwapAlertType = Alert.BAR;

input alertVwapDaily = yes;
input alertVwapWeekly = yes;
input alertVwapMonthly = yes;

input alertVwapUB1   = no;
input alertVwapUB2    =yes;
input alertVwapUB3    =yes;
input alertVwapUB4    =yes;
input alertVwapWKHB   =yes;
input alertVwapMNTHHB =yes;

input alertVwapLB1    =no;
input alertVwapLB2    =yes;
input alertVwapLB3    =yes;
input alertVwapLB4    =yes;
input alertVwapWKLB   =yes;
input alertVwapMNTHLB =yes;

input enableDeviationClouds = yes;
input enableDailyXWeeklyClouds = yes;
input enableWeeklyXMonthlyClouds = yes;

input showVwapFromPriceLabels = yes;
input showDeviationBandWidthLabel = Yes;
input showDxwLabel = yes;
input showWxmLabel = yes;

input band1Dev = 1.0;
input band2Dev = 2.0;
input band3Dev = 3.0;
input band4Dev = 4.0;
input band5Dev = 0.5;
input band6Dev = 1.5;
input band7Dev = 2.5;
input band8Dev = 3.5;

#Bollinger and Keltner SQUEEZE inputs
input enableSqueeze1 = yes;
input enableSqueeze2 = yes;
input enableSqueeze3 = yes;

def sqzAggregation1 = GetAggregationPeriod();
input sqzAggregation2 = AggregationPeriod.THIRTY_MIN;
def SqzAgg2 = if GetAggregationPeriod() > SqzAggregation2 then GetAggregationPeriod() else SqzAggregation2;
input sqzAggregation3 = AggregationPeriod.HOUR;
def SqzAgg3 = if GetAggregationPeriod() > SqzAggregation3 then GetAggregationPeriod() else SqzAggregation3;

input showSqz1Label = yes;
input showSqz2Label = yes;
input showSqz3Label = yes;
input sqz1Alert = yes;
input sqz2Alert = yes;
input sqz3Alert = yes;
input sqzAlertType = Alert.BAR;
input sqzAlertSound = Sound.Ding;
input sqz1VerticalLine = yes;
input sqz2VerticalLine = yes;
input sqz3VerticalLine = yes;

def displace = 0;
def length = 20;
def Num_Dev_Dn = -2.0;
def Num_Dev_up = 2.0;
def averageType = AverageType.SIMPLE;
def factor = 1.5;
def trueRangeAverageType = AverageType.SIMPLE;

#Aggregation Warning Labels
AddLabel(if (EnableSqueeze2 and GetAggregationPeriod() > SqzAggregation2) or (EnableSqueeze3 and GetAggregationPeriod() > SqzAggregation3) then 1 else 0, if GetAggregationPeriod() > SqzAggregation2 then "Time Frame > SqzAggregation2" else "Time Frame > SqzAggregation3" , Color.YELLOW);

AddLabel(if (GetAggregationPeriod() >= AggregationPeriod.DAY and VWAPAggregation == VWAPAggregation."DAY") or (GetAggregationPeriod() >= AggregationPeriod.WEEK and VWAPAggregation == VWAPAggregation."WEEK") or (GetAggregationPeriod() >= AggregationPeriod.MONTH and VWAPAggregation == VWAPAggregation."MONTH") then 1 else 0, "Time Frame >= VWAPAggregation", Color.YELLOW);

#VWAP Bull Bear Coloring
plot VWAPBullBear = NA;
VWAPBullBear.HideTitle();
VWAPBullBear.DefineColor("Above", CreateColor(0,100,100));
VWAPBullBear.DefineColor("Below", Color.DARK_RED);
#VWAP Dev Above Below Coloring
plot VWAPDevColoring = NA;
VWAPDevColoring.HideTitle();
VWAPDevColoring.DefineColor("UpperAbove", Color.GRAY);
VWAPDevColoring.DefineColor("UpperBelow", CreateColor(30,30,30));
VWAPDevColoring.DefineColor("LowerAbove", CreateColor(30,30,30));
VWAPDevColoring.DefineColor("LowerBelow", Color.GRAY);

#VWAP Deviation Clouds Coloring
plot DeviationClouds = NA;
DeviationClouds.HideTitle();
DeviationClouds.DefineColor("2+3 UpperBand", Color.GRAY);
DeviationClouds.DefineColor("1+2 UpperBand", Color.DARK_GRAY);
DeviationClouds.DefineColor("vwap+1 UpperBand", Color.BLACK);
DeviationClouds.DefineColor("vwap-1 LowerBand", Color.BLACK);
DeviationClouds.DefineColor("1-2 LowerBand", Color.DARK_GRAY);
DeviationClouds.DefineColor("2-3 LowerBand", Color.GRAY);

#Crossover Clouds Coloring
plot CrossoverClouds = NA;
CrossoverClouds.HideTitle();
CrossoverClouds.DefineColor("Daily x Weekly UpperBands", Color.DARK_ORANGE);
CrossoverClouds.DefineColor("Weekly x Monthly UpperBands", Color.RED);
CrossoverClouds.DefineColor("Daily x Weekly LowerBands", CreateColor(0, 100, 200));
CrossoverClouds.DefineColor("Weekly x Monthly LowerBands", Color.GREEN);

#Squeeze Clouds Coloring
plot SqueezeClouds = NA;
SqueezeClouds.HideTitle();
SqueezeClouds.DefineColor("Squeeze1", Color.YELLOW);
SqueezeClouds.DefineColor("Squeeze2", Color.DARK_ORANGE);
SqueezeClouds.DefineColor("Squeeze3", Color.RED);

#Heiken Trend Coloring
plot HeikenAshiPaintColors = NA;
HeikenAshiPaintColors.HideTitle();
HeikenAshiPaintColors.DefineColor("Heiken Up", Color.GREEN);
HeikenAshiPaintColors.DefineColor("Heiken Down", Color.RED);
HeikenAshiPaintColors.DefineColor("Neutral", Color.YELLOW);

#MTF Heiken Ashi
def o = open;
def h = high;
def l = low;
def c = close;


#HAgg1
def o1 = open("period" = haAgg1);
def h1 = high("period" = haAgg1);
def l1 = low("period" = haAgg1);
def c1 = close("period" = haAgg1);
def HA1open;
def HA1high;
def HA1low;
def HA1close;
HA1open = CompoundValue(1, (HA1open[1] + HA1close[1]) / 2, (o1[1] + c1[1]) / 2);
HA1high = Max(Max(h1, HA1open), HA1close[1]);
HA1low = Min(Min(l1, HA1open), HA1close[1]);
HA1close = (o1 + h1 + l1 + c1) / 4;


#HAgg2
def o2 = open("period" = haAgg2);
def h2 = high("period" = haAgg2);
def l2 = low("period" = haAgg2);
def c2 = close("period" = haAgg2);
def HA2open;
def HA2high;
def HA2low;
def HA2close;
HA2open = CompoundValue(1, (HA2open[1] + HA2close[1]) / 2, (o2[1] + c2[1]) / 2);
HA2high = Max(Max(h2, HA2open), HA2close[1]);
HA2low = Min(Min(l2, HA2open), HA2close[1]);
HA2close = (o2 + h2 + l2 + c2) / 4;

def HA1 = HA1close > HA1open;
def HA2 = HA2close > HA2open;

AddLabel(1, "HA1", if HA1 then HeikenAshiPaintColors.Color("Heiken UP") else HeikenAshiPaintColors.Color("Heiken Down"));
AddLabel(1, "HA2", if HA2 then HeikenAshiPaintColors.Color("Heiken UP") else HeikenAshiPaintColors.Color("Heiken Down"));

#Paint Heiken Candles
AssignPriceColor(if !paintHeikenAshiCandles then Color.CURRENT else if HA1 and HA2 then HeikenAshiPaintColors.Color("Heiken UP") else if !HA1 and !HA2 then HeikenAshiPaintColors.Color("Heiken Down") else HeikenAshiPaintColors.Color("Neutral"));

#VWAP Daily, Weekly, and Monthly
plot VWAPDAY =  reference VWAP("num dev dn" = -2.0, "num dev up" = 2.0, "time frame" = "DAY");
plot VWAPWK = reference VWAP("num dev dn" = -2.0, "num dev up" = 2.0, "time frame" = "WEEK");
plot VWAPMNTH = reference VWAP("num dev dn" = -2.0, "num dev up" = 2.0, "time frame" = "MONTH");

VWAPDAY.SetHiding(GetAggregationPeriod() >= AggregationPeriod.DAY);
VWAPWK.SetHiding(GetAggregationPeriod() >= AggregationPeriod.WEEK);
VWAPMNTH.SetHiding(GetAggregationPeriod() >= AggregationPeriod.MONTH);
#VWAP Distance Label
def VWAPDAYDistance = c - VWAPDAY;
def VWAPWKDistance = c - VWAPWK;
def VWAPMNTHDistance = c - VWAPMNTH;

AddLabel(if ShowVwapFromPriceLabels then 1 else 0, "DVWAP: " + AsDollars(VWAPDAYDistance) + " WVWAP: " + AsDollars(VWAPWKDistance) + " MVWAP: " + AsDollars(VWAPMNTHDistance), if AbsValue(VWAPDAYDistance) < AbsValue(VWAPWKDistance) and AbsValue(VWAPDAYDistance) < AbsValue(VWAPMNTHDistance) then Color.WHITE else if AbsValue(VWAPWKDistance) < AbsValue(VWAPDAYDistance) and AbsValue(VWAPWKDistance) < AbsValue(VWAPMNTHDistance) then Color.DARK_ORANGE else if VWAPWKDistance and VWAPMNTHDistance == VWAPDAYDistance then Color.WHITE else Color.RED);


#VWAP UpperBand and LowerBand values
def VWAPDAYLB = reference VWAP("num dev dn" = -2.0, "num dev up" = 2.0, "time frame" = "DAY")."LowerBand";
plot VWAPWKLB = reference VWAP("num dev dn" = -2.0, "num dev up" = 2.0, "time frame" = "WEEK")."LowerBand";
plot VWAPMNTHLB = reference VWAP("num dev dn" = -2.0, "num dev up" = 2.0, "time frame" = "MONTH")."LowerBand";


def VWAPDAYHB = reference VWAP("num dev dn" = -2.0, "num dev up" = 2.0, "time frame" = "DAY")."UpperBand";
plot VWAPWKHB = reference VWAP("num dev dn" = -2.0, "num dev up" = 2.0, "time frame" = "WEEK")."UpperBand";
plot VWAPMNTHHB = reference VWAP("num dev dn" = -2.0, "num dev up" = 2.0, "time frame" = "MONTH")."UpperBand";

VWAPWKLB.SetHiding(GetAggregationPeriod() >= AggregationPeriod.FOUR_HOURS);
VWAPWKHB.SetHiding(GetAggregationPeriod() >= AggregationPeriod.FOUR_HOURS);
VWAPMNTHLB.SetHiding(GetAggregationPeriod() >= AggregationPeriod.DAY);
VWAPMNTHHB.SetHiding(GetAggregationPeriod() >= AggregationPeriod.DAY);

# VWAP Day/Week and Week/Month LowerBand and UpperBand crossover validations
#Day x Week
def VDAYxWKLBDiffH = if !EnableDailyXWeeklyClouds then NA else if VWAPWKLB - VWAPDAYLB <= 0 then NA else VWAPWKLB;
def VDAYxWKLBDiffL = if !EnableDailyXWeeklyClouds then NA else if VWAPWKLB - VWAPDAYLB <= 0 then NA else VWAPDAYLB;
def VDAYxWKHBDiffH = if !EnableDailyXWeeklyClouds then NA else if VWAPDAYHB - VWAPWKHB <= 0 then NA else VWAPDAYHB;
def VDAYxWKHBDiffL = if !EnableDailyXWeeklyClouds then NA else if VWAPDAYHB - VWAPWKHB <= 0 then NA else VWAPWKHB;

#Week x Month
def VWKxMNTHLBDiffH = if !EnableWeeklyXMonthlyClouds then NA else if VWAPMNTHLB - VWAPWKLB <= 0 then NA else VWAPMNTHLB;
def VWKxMNTHLBDiffL = if !EnableWeeklyXMonthlyClouds then NA else if VWAPMNTHLB - VWAPWKLB <= 0 then NA else VWAPWKLB;
def VWKxMNTHHBDiffH = if !EnableWeeklyXMonthlyClouds then NA else if VWAPWKHB - VWAPMNTHHB <= 0 then NA else VWAPWKHB;
def VWKxMNTHHBDiffL = if !EnableWeeklyXMonthlyClouds then NA else if VWAPWKHB - VWAPMNTHHB <= 0 then NA else VWAPMNTHHB;

#Format Main VWAP Bands
#PaintVWAP According to HeikenAshi
VWAPDAY.DefineColor("Default", Color.YELLOW);

VWAPDAY.AssignValueColor(if !paintHeikenAshiVWAP and !paintVwapBullBear then VWAPDAY.Color("Default") else if paintHeikenAshiVWAP and HA1 and HA2 then HeikenAshiPaintColors.Color("Heiken Up") else if paintHeikenAshiVWAP and !HA1 and !HA2 then HeikenAshiPaintColors.Color("Heiken Down") else if paintHeikenAshiVWAP and (HA1 and !HA2) or paintHeikenAshiVWAP and (!HA1 and HA2) then HeikenAshiPaintColors.Color("Neutral") else if paintVwapBullBear and c > VWAPDAY then HeikenAshiPaintColors.Color("Heiken Up") else HeikenAshiPaintColors.Color("Heiken Down"));
VWAPDAY.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

VWAPWK.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VWAPWK.SetDefaultColor(Color.DARK_ORANGE);

VWAPWKHB.SetStyle(Curve.SHORT_DASH);
VWAPWKHB.SetDefaultColor(Color.DARK_ORANGE);

VWAPWKLB.SetStyle(Curve.SHORT_DASH);
VWAPWKLB.SetDefaultColor(Color.DARK_ORANGE);

VWAPMNTH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VWAPMNTH.SetDefaultColor(Color.RED);

VWAPMNTHHB.SetStyle(Curve.LONG_DASH);
VWAPMNTHHB.SetDefaultColor(Color.RED);

VWAPMNTHLB.SetStyle(Curve.LONG_DASH);
VWAPMNTHLB.SetDefaultColor(Color.RED);

AddCloud(VDAYxWKLBDiffH, VDAYxWKLBDiffL, CrossoverClouds.Color("Daily x Weekly LowerBands"), CrossoverClouds.Color("Daily x Weekly LowerBands"));
AddCloud(VDAYxWKHBDiffH, VDAYxWKHBDiffL, CrossoverClouds.Color("Daily x Weekly UpperBands"), CrossoverClouds.Color("Daily x Weekly UpperBands"));

AddCloud(VWKxMNTHLBDiffH, VWKxMNTHLBDiffL, CrossoverClouds.Color("Weekly x Monthly LowerBands"), CrossoverClouds.Color("Weekly x Monthly LowerBands"));
AddCloud(VWKxMNTHHBDiffH, VWKxMNTHHBDiffL, CrossoverClouds.Color("Weekly x Monthly UpperBands"), CrossoverClouds.Color("Weekly x Monthly UpperBands"));

#VWAP Deviation Bands
#UpperBands 1234
plot VWAPUB1 = reference VWAP("num dev up" = Band1Dev, "time frame" = VWAPAggregation)."UpperBand";
plot VWAPUB2 = reference VWAP("num dev up" = Band2Dev, "time frame" = VWAPAggregation)."UpperBand";
plot VWAPUB3 = reference VWAP("num dev up" = Band3Dev, "time frame" = VWAPAggregation)."UpperBand";
plot VWAPUB4 = reference VWAP("num dev up" = Band4Dev, "time frame" = VWAPAggregation)."UpperBand";
plot VWAPUB5 = reference VWAP("num dev up" = Band5Dev, "time frame" = VWAPAggregation)."UpperBand";
plot VWAPUB6 = reference VWAP("num dev up" = Band6Dev, "time frame" = VWAPAggregation)."UpperBand";
plot VWAPUB7 = reference VWAP("num dev up" = Band7Dev, "time frame" = VWAPAggregation)."UpperBand";
plot VWAPUB8 = reference VWAP("num dev up" = Band8Dev, "time frame" = VWAPAggregation)."UpperBand";

VWAPUB1.Hide();
VWAPUB2.Hide();
VWAPUB3.Hide();
VWAPUB4.Hide();

#LowerBands 1234
plot VWAPLB1 = reference VWAP("num dev dn" = -Band1Dev, "time frame" = VWAPAggregation)."LowerBand";
plot VWAPLB2 = reference VWAP("num dev dn" = -Band2Dev, "time frame" = VWAPAggregation)."LowerBand";
plot VWAPLB3 = reference VWAP("num dev dn" = -Band3Dev, "time frame" = VWAPAggregation)."LowerBand";
plot VWAPLB4 = reference VWAP("num dev dn" = -Band4Dev, "time frame" = VWAPAggregation)."LowerBand";
plot VWAPLB5 = reference VWAP("num dev dn" = -Band5Dev, "time frame" = VWAPAggregation)."LowerBand";
plot VWAPLB6 = reference VWAP("num dev dn" = -Band6Dev, "time frame" = VWAPAggregation)."LowerBand";
plot VWAPLB7 = reference VWAP("num dev dn" = -Band7Dev, "time frame" = VWAPAggregation)."LowerBand";
plot VWAPLB8 = reference VWAP("num dev dn" = -Band8Dev, "time frame" = VWAPAggregation)."LowerBand";

VWAPLB1.Hide();
VWAPLB2.Hide();
VWAPLB3.Hide();
VWAPLB4.Hide();

#VWAP Alerts
Alert(if AlertVWAPDaily then (h >= VWAPDAY) and (l <= VWAPDAY) else NA, "VWAP Daily Cross", vwapAlertType, vwapAlertSound); 
Alert(if AlertVWAPWeekly then (h >= VWAPWK) and (l <= VWAPWK) else NA, "VWAP Weekly Cross", vwapAlertType, vwapAlertSound); 
Alert(if AlertVWAPMonthly then (h >= VWAPMNTH) and (l <= VWAPMNTH) else NA, "VWAP Monthly Cross", vwapAlertType, vwapAlertSound);

#VWAP UpperBand Alerts
Alert(if AlertVWAPUB1 then (h >= VWAPUB1) and (l <= VWAPUB1) else NA, "VWAP Upper 1 Std Dev Cross", vwapAlertType, vwapAlertSound); 
Alert(if AlertVWAPUB2 then (h >= VWAPUB2) and (l <= VWAPUB2) else NA, "VWAP Upper 2 Std Dev Cross", vwapAlertType, vwapAlertSound); 
Alert(if AlertVWAPUB3 then (h >= VWAPUB3) and (l <= VWAPUB3) else NA, "VWAP Upper 3 Std Dev Cross", vwapAlertType, vwapAlertSound); 
Alert(if AlertVWAPUB4 then (h >= VWAPUB4) and (l <= VWAPUB4) else NA, "VWAP Upper 4 Std Dev Cross", vwapAlertType, vwapAlertSound); 
Alert(if AlertVWAPWKHB then (h >= VWAPWKHB) and (l <= VWAPWKHB) else NA, "VWAP Weekly Upper 2 Std Dev Cross", vwapAlertType, vwapAlertSound); 
Alert(if AlertVWAPMNTHHB then (h >= VWAPMNTHHB) and (l <= VWAPMNTHHB) else NA, "VWAP Monthly Upper 2 Std Dev Cross", vwapAlertType, vwapAlertSound); 
#VWAP LowerBand ALerts
Alert(if AlertVWAPLB1 then (l <= VWAPLB1) and (h >= VWAPLB1) else NA, "VWAP Lower 1 Std Dev Cross", vwapAlertType, vwapAlertSound); 
Alert(if AlertVWAPLB2 then (l <= VWAPLB2) and (h >= VWAPLB2) else NA, "VWAP Lower 2 Std Dev Cross", vwapAlertType, vwapAlertSound); 
Alert(if AlertVWAPLB3 then (l <= VWAPLB3) and (h >= VWAPLB3) else NA, "VWAP Lower 3 Std Dev Cross", vwapAlertType, vwapAlertSound); 
Alert(if AlertVWAPLB4 then (l <= VWAPLB4) and (h >= VWAPLB4) else NA, "VWAP Lower 4 Std Dev Cross", vwapAlertType, vwapAlertSound); 
Alert(if AlertVWAPWKLB then (l <= VWAPWKLB) and (h >= VWAPWKLB) else NA, "VWAP Weekly Lower 2 Std Dev Cross", vwapAlertType, vwapAlertSound); 
Alert(if AlertVWAPMNTHLB then (l <= VWAPMNTHLB) and (h >= VWAPMNTHLB) else NA, "VWAP Monthly Lower 2 Std Dev Cross", vwapAlertType, vwapAlertSound); 

#Format Deviation Bands
VWAPUB1.SetStyle(Curve.FIRM);
VWAPUB1.AssignValueColor(if h >= VWAPUB1 then VWAPDevColoring.Color("UpperAbove") else VWAPDevColoring.Color("UpperBelow"));
VWAPUB2.SetStyle(Curve.FIRM);
VWAPUB2.AssignValueColor(if h >= VWAPUB2 then VWAPDevColoring.Color("UpperAbove") else VWAPDevColoring.Color("UpperBelow"));
VWAPUB3.SetStyle(Curve.FIRM);
VWAPUB3.AssignValueColor(if h >= VWAPUB3 then VWAPDevColoring.Color("UpperAbove") else VWAPDevColoring.Color("UpperBelow"));
VWAPUB4.SetStyle(Curve.FIRM);
VWAPUB4.AssignValueColor(if h >= VWAPUB4 then VWAPDevColoring.Color("UpperAbove") else VWAPDevColoring.Color("UpperBelow"));
VWAPUB5.SetStyle(Curve.SHORT_DASH);
VWAPUB5.SetDefaultColor(CreateColor(30,30,30));
VWAPUB6.SetStyle(Curve.SHORT_DASH);
VWAPUB6.SetDefaultColor(CreateColor(30,30,30));
VWAPUB7.SetStyle(Curve.SHORT_DASH);
VWAPUB7.SetDefaultColor(CreateColor(30,30,30));
VWAPUB8.SetStyle(Curve.SHORT_DASH);
VWAPUB8.SetDefaultColor(CreateColor(30,30,30));


VWAPLB1.SetStyle(Curve.FIRM);
VWAPLB1.AssignValueColor(if l >= VWAPLB1 then VWAPDevColoring.Color("LowerAbove") else VWAPDevColoring.Color("LowerBelow"));
VWAPLB2.SetStyle(Curve.FIRM);
VWAPLB2.AssignValueColor(if l >= VWAPLB2 then VWAPDevColoring.Color("LowerAbove") else VWAPDevColoring.Color("LowerBelow"));
VWAPLB3.SetStyle(Curve.FIRM);
VWAPLB3.AssignValueColor(if l >= VWAPLB3 then VWAPDevColoring.Color("LowerAbove") else VWAPDevColoring.Color("LowerBelow"));
VWAPLB4.SetStyle(Curve.FIRM);
VWAPLB4.AssignValueColor(if l >= VWAPLB4 then VWAPDevColoring.Color("LowerAbove") else VWAPDevColoring.Color("LowerBelow"));
VWAPLB5.SetStyle(Curve.SHORT_DASH);
VWAPLB5.SetDefaultColor(CreateColor(30,30,30));
VWAPLB6.SetStyle(Curve.SHORT_DASH);
VWAPLB6.SetDefaultColor(CreateColor(30,30,30));
VWAPLB7.SetStyle(Curve.SHORT_DASH);
VWAPLB7.SetDefaultColor(CreateColor(30,30,30));
VWAPLB8.SetStyle(Curve.SHORT_DASH);
VWAPLB8.SetDefaultColor(CreateColor(30,30,30));

#Clouds for Deviation Bands 2 and 3
AddCloud(if enableDeviationClouds then VWAPUB3 else NA, VWAPUB2, DeviationClouds.Color("2+3 UpperBand"), DeviationClouds.Color("2+3 UpperBand"), no);
AddCloud(if enableDeviationClouds then VWAPUB2 else NA, VWAPUB1, DeviationClouds.Color("1+2 UpperBand"), DeviationClouds.Color("1+2 UpperBand"), yes);
AddCloud(if enableDeviationClouds then VWAPUB1 else NA, VWAPDAY, DeviationClouds.Color("VWAP+1 UpperBand"), DeviationClouds.Color("VWAP+1 UpperBand"), no);

AddCloud(if enableDeviationClouds then VWAPDAY else NA, VWAPLB1, DeviationClouds.Color("VWAP-1 LowerBand"), DeviationClouds.Color("VWAP-1 LowerBand"), no);
AddCloud(if enableDeviationClouds then VWAPLB1 else NA, VWAPLB2, DeviationClouds.Color("1-2 LowerBand"), DeviationClouds.Color("1-2 LowerBand"), yes);
AddCloud(if enableDeviationClouds then VWAPLB2 else NA, VWAPLB3, DeviationClouds.Color("2-3 LowerBand"), DeviationClouds.Color("2-3 LowerBand"), no);
#VWAP Dev Clouds
#AddCloud(hl2, VWAPDAY, VWAPBullBear.Color("Above"), VWAPBullBear.Color("Below"), no);


#Deviation Bandwidth Label
AddLabel(ShowDeviationBandWidthLabel, "DevBW: $" + AsText((VWAPUB1 - VWAPDAY), NumberFormat.TWO_DECIMAL_PLACES), Color.GRAY);


#DxW and WxM Crossover Labels
AddLabel(if EnableDailyXWeeklyClouds and ShowDXWLabel then 1 else 0, "DxW", if (VWAPDAYHB > VWAPWKHB) then CrossoverClouds.Color("Daily x Weekly UpperBands") else if (VWAPDAYLB < VWAPWKLB) then CrossoverClouds.Color("Daily x Weekly LowerBands") else Color.DARK_GRAY);
AddLabel(if EnableWeeklyXMonthlyClouds and ShowWXMLabel then 1 else 0, "WxM", if (VWAPWKHB > VWAPMNTHHB) then CrossoverClouds.Color("Weekly x Monthly UpperBands") else if (VWAPWKLB < VWAPMNTHLB) then CrossoverClouds.Color("Weekly x Monthly LowerBands") else Color.DARK_GRAY);


#Bollinger and Keltner SQUEEZE
#MTF Squeeze Clouds

def price1 = close("Period" = SqzAggregation1);
def price2 = close("Period" = SqzAgg2);
def price3 = close("Period" = SqzAgg3);

#BollingerBands Upper Middle Lower
def sDev1 = StDev(data = price1[-displace], length = length);
def sDev2 = StDev(data = price2[-displace], length = length);
def sDev3 = StDev(data = price3[-displace], length = length);
def MidLine1 = MovingAverage(averageType, data = price1[-displace], length = length);
def MidLine2 = MovingAverage(averageType, data = price2[-displace], length = length);
def MidLine3 = MovingAverage(averageType, data = price3[-displace], length = length);

def BLowerBand1 = MidLine1 + Num_Dev_Dn * sDev1;
def BLowerBand2 = MidLine2 + Num_Dev_Dn * sDev2;
def BLowerBand3 = MidLine3 + Num_Dev_Dn * sDev3;

def BUpperBand1 = MidLine1 + Num_Dev_up * sDev1;
def BUpperBand2 = MidLine2 + Num_Dev_up * sDev2;
def BUpperBand3 = MidLine3 + Num_Dev_up * sDev3;

#Keltner Channels Upper Middle Lower
def shift1 = factor * MovingAverage(trueRangeAverageType, TrueRange(high("Period" = SqzAggregation1), close("Period" = SqzAggregation1), low("Period" = SqzAggregation1)), length);
def shift2 = factor * MovingAverage(trueRangeAverageType, TrueRange(high("Period" = SqzAgg2), close("Period" = SqzAgg2), low("Period" = SqzAgg2)), length);
def shift3 = factor * MovingAverage(trueRangeAverageType, TrueRange(high("Period" = SqzAgg3), close("Period" = SqzAgg3), low("Period" = SqzAgg3)), length);

def average1 = MovingAverage(averageType, price1, length);
def average2 = MovingAverage(averageType, price2, length);
def average3 = MovingAverage(averageType, price3, length);

def Avg1 = average1[-displace];
def Avg2 = average2[-displace];
def Avg3 = average3[-displace];

def KUpperBand1 = average1[-displace] + shift1[-displace];
def kUpperBand2 = average2[-displace] + shift2[-displace];
def kUpperBand3 = average3[-displace] + shift3[-displace];

def KLowerBand1 = average1[-displace] - shift1[-displace];
def KLowerBand2 = average2[-displace] - shift2[-displace];
def KLowerBand3 = average3[-displace] - shift3[-displace];


#Squeeze Verification = Bollinger Upper and Lower Bands Cross inside Keltner Channel Upper and Lower Bands

def sqz1conf = KUpperBand1 - BUpperBand1 <= 0;
def sqz2conf = KUpperBand2 - BUpperBand2 <= 0;
def sqz3conf = KUpperBand3 - BUpperBand3 <= 0;

def BollKeltUB1DiffH = if !EnableSqueeze1 then NA else if sqz1conf then NA else KUpperBand1;
def BollKeltUB1DiffL = if !EnableSqueeze1 then NA else if sqz1conf then NA else BUpperBand1;
def BollKeltLB1DiffH = if !EnableSqueeze1 then NA else if sqz1conf then NA else BLowerBand1;
def BollKeltLB1DiffL = if !EnableSqueeze1 then NA else if sqz1conf then NA else KLowerBand1;

def BollKeltUB2DiffH = if !EnableSqueeze2 then NA else if sqz2conf then NA else kUpperBand2;
def BollKeltUB2DiffL = if !EnableSqueeze2 then NA else if sqz2conf then NA else BUpperBand2;
def BollKeltLB2DiffH = if !EnableSqueeze2 then NA else if sqz2conf then NA else BLowerBand2;
def BollKeltLB2DiffL = if !EnableSqueeze2 then NA else if sqz2conf then NA else KLowerBand2;

def BollKeltUB3DiffH = if !EnableSqueeze3 then NA else if sqz3conf then NA else kUpperBand3;
def BollKeltUB3DiffL = if !EnableSqueeze3 then NA else if sqz3conf then NA else BUpperBand3;
def BollKeltLB3DiffH = if !EnableSqueeze3 then NA else if sqz3conf then NA else BLowerBand3;
def BollKeltLB3DiffL = if !EnableSqueeze3 then NA else if sqz3conf then NA else KLowerBand3;

plot Sqz1H = BollKeltUB1DiffL;
plot Sqz1L = BollKeltLB1DiffH;
plot Sqz2H = BollKeltUB2DiffL;
plot Sqz2L = BollKeltLB2DiffH;
plot Sqz3H = BollKeltUB3DiffL;
plot Sqz3L = BollKeltLB3DiffH;


#Sqz 1 2 3 Labels
AddLabel(if EnableSqueeze1 and ShowSqz1Label then 1 else 0,"Sqz1", if !sqz1conf then SqueezeClouds.Color("Squeeze1") else Color.DARK_GRAY);
AddLabel(if EnableSqueeze2 and ShowSqz2Label then 1 else 0,"Sqz2", if !sqz2conf then SqueezeClouds.Color("Squeeze2") else Color.DARK_GRAY);
AddLabel(if EnableSqueeze3 and ShowSqz3Label then 1 else 0,"Sqz3", if !sqz3conf then SqueezeClouds.Color("Squeeze3") else Color.DARK_GRAY);

#squeeze alerts
Alert(if Sqz1Alert then sqz1conf[1] and !sqz1conf else NA, "Squeeze1", sqzAlertType, sqzAlertSound);
Alert(if Sqz2Alert then sqz2conf[1] and !sqz2conf else NA, "Squeeze2", sqzAlertType, sqzAlertSound);
Alert(if Sqz3Alert then sqz3conf[1] and !sqz3conf else NA, "Squeeze3", sqzAlertType, sqzAlertSound);

AddVerticalLine(if Sqz1VerticalLine then sqz1conf[1] and !sqz1conf else NA, "Sqz1", SqueezeClouds.Color("Squeeze1"), stroke = Curve.POINTS);
AddVerticalLine(if Sqz2VerticalLine then sqz2conf[1] and !sqz2conf else NA, "Sqz2", SqueezeClouds.Color("Squeeze2"), stroke = Curve.POINTS);
AddVerticalLine(if Sqz3VerticalLine then sqz3conf[1] and !sqz3conf else NA, "Sqz3", SqueezeClouds.Color("Squeeze3"), stroke = Curve.POINTS);

Sqz1H.SetPaintingStrategy(PaintingStrategy.LINE);
Sqz1H.AssignValueColor(SqueezeClouds.Color("Squeeze1"));
Sqz1H.SetLineWeight(1);
Sqz1L.SetPaintingStrategy(PaintingStrategy.LINE);
Sqz1L.AssignValueColor(SqueezeClouds.Color("Squeeze1"));
Sqz1L.SetLineWeight(1);
Sqz2H.SetPaintingStrategy(PaintingStrategy.LINE);
Sqz2H.AssignValueColor(SqueezeClouds.Color("Squeeze2"));
Sqz2H.SetLineWeight(1);
Sqz2L.SetPaintingStrategy(PaintingStrategy.LINE);
Sqz2L.AssignValueColor(SqueezeClouds.Color("Squeeze2"));
Sqz2L.SetLineWeight(1);
Sqz3H.SetPaintingStrategy(PaintingStrategy.LINE);

Sqz3H.AssignValueColor(SqueezeClouds.Color("Squeeze3"));
Sqz3H.SetLineWeight(1);
Sqz3L.SetPaintingStrategy(PaintingStrategy.LINE);
Sqz3L.AssignValueColor(SqueezeClouds.Color("Squeeze3"));
Sqz3L.SetLineWeight(1);

#Clouds for Squeezes
AddCloud(BollKeltUB1DiffH, BollKeltUB1DiffL, SqueezeClouds.Color("Squeeze1"), SqueezeClouds.Color("Squeeze1"));
AddCloud(BollKeltLB1DiffH, BollKeltLB1DiffL, SqueezeClouds.Color("Squeeze1"), SqueezeClouds.Color("Squeeze1"));

AddCloud(BollKeltUB2DiffH, BollKeltUB2DiffL, SqueezeClouds.Color("Squeeze2"), SqueezeClouds.Color("Squeeze2"));
AddCloud(BollKeltLB2DiffH, BollKeltLB2DiffL, SqueezeClouds.Color("Squeeze2"), SqueezeClouds.Color("Squeeze2"));

AddCloud(BollKeltUB3DiffH, BollKeltUB3DiffL, SqueezeClouds.Color("Squeeze3"), SqueezeClouds.Color("Squeeze3"));
AddCloud(BollKeltLB3DiffH, BollKeltLB3DiffL, SqueezeClouds.Color("Squeeze3"), SqueezeClouds.Color("Squeeze3"));
 
Last edited:
Adeodatus

Adeodatus

New member
Great! I'm liking the "squeezer" plotting part. it's very complex to view at first nice job indicating what has happened and slight probability to what is next...
 
J007RMC

J007RMC

Well-known member
2019 Donor
VIP
Way nice thanks will give it a try next week.
 
zeek

zeek

Active member
2019 Donor
Look very nice! But the VWAP deviation bands are not showing for me. Anyone else with same problem?
 
Welkin

Welkin

Active member
VIP
This is how it looks after installing the script with no changes made in the settings.


go to edit studies and move the indicator from volume to the upper studies where price indicators go.

also you can edit the thinkscript and add the following line at the top:
Code:
declare upper;
i will edit the main post so this doesn't happen to others
 
zeek

zeek

Active member
2019 Donor
go to edit studies and move the indicator from volume to the upper studies where price indicators go.

also you can edit the thinkscript and add the following line at the top:
Code:
declare upper;
i will edit the main post so this doesn't happen to others

Yeah, i just noticed the study was in the lower volume area. Works great now after moving it up. I really like it!
 
J007RMC

J007RMC

Well-known member
2019 Donor
VIP
I love this script but for some reason it may be glitchy when combined with just a few of my indicators. I started over with a blank chart and added just a few indicators to go with the vwap script and the chart does not always load to the blue red candles and am not sure what the problem is? Does anyone else have similar issues? Perhaps this is a TOS issue it has run slow all weekend on my end. Normally it should look like this I think with the heiken options both checked yes.
 
Last edited:
Welkin

Welkin

Active member
VIP
I love this script but for some reason it may be glitchy when combined with just a few of my indicators. I started over with a blank chart and added just a few indicators to go with the vwap script and the chart does not always load to the blue red candles and am not sure what the problem is? Does anyone else have similar issues? Perhaps this is a TOS issue it has run slow all weekend on my end.
I've had a similar issue but it has also only happened on weekends when markets are down and only for brief periods . I think because tos does all their server maintenance and tweaking during this time that it leads to some loading issues. I've never experience this during any other time.
 
J007RMC

J007RMC

Well-known member
2019 Donor
VIP
Thank you.... my suspicions confirmed. Great script by the way
 
Welkin

Welkin

Active member
VIP
Thank you.... my suspicions confirmed. Great script by the way
also looking at your screenshot, if you are using this on your daily chart as well try setting the time frame from day to month in the settings if you want the deviation bands to show.
 
Welkin

Welkin

Active member
VIP
I do beleive this worked.
Letting you know that I made some changes and added labels that will show a warning if your current charts time frame is set to an equal or higher time frame than what the VWAP Aggregation (DAY, WEEK, or MONTH) is set to. Also, if you have squeezes 2 and 3 enabled, seperate warning label will also show for current chart time frame being larger than the SqzAggregation2 and SqzAggregation3. Squeeze1 is now set to always be your current chart's time frame.
 
zeek

zeek

Active member
2019 Donor
Have been trading with this study today and just want to say, it`s a new favorite of mine. Big thanks to @Welkin for sharing it(y)

:love:



I do have a question too. Is there any way to disable the crossovers that generates the purple & teal clouds? I really prefer to have just the usual black charts background and the greyish color clouds.
Welkin, if you could point me to the lines of code i need to modify, i would appreciate it.
 
D

dolomick

Member
What does the blue cloud indicate? Daily crossing weekly I'm guessing? To be clear, I am not talking about purple. Thanks..
 
Welkin

Welkin

Active member
VIP
What does the blue cloud indicate? Daily crossing weekly I'm guessing? To be clear, I am not talking about purple. Thanks..
yes daily x weekly 2nd deviation, purple is weekly x monthly
 

Similar threads

Top