VWAP Band Trend for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
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.
M6xjbpp.png


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 ####
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
351 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top