put two standard deviations onto anchored VWAP

BillW

Member
VIP
I want to put two standard deviations onto anchored VWAP
Code:
#yakBro intraday anchoredVWAP excluding extended hours volume 2019
# https://usethinkscript.com/threads/anchored-vwap-indicator-for-thinkorswim.171/post-11014

declare hide_on_daily;

def anchorTime = 0800;
def anchorEnd = 1600;

input ShowTodayOnly = yes;
def Today = if GetDay() == GetLastDay() then 1 else 0;
def postAnchorTime = if SecondsFromTime(anchorTime) >= 0 then 1 else 0;
def endAchorTime = if SecondsTillTime(anchorEnd) >= 0 then 1 else 0;

#plot anchorVWAP for intraday
def  volumeSum = compoundValue(1, if postAnchorTime and endAchorTime then volumeSum[1] + volume else 0, volume);
def  volumeVwapSum = compoundValue(1, if postAnchorTime and endAchorTime then volumeVwapSum[1] + volume * vwap else 0, volume * vwap);

plot anchorVWAP = if ShowTodayOnly and !Today then Double.NaN else if anchorTime then volumeVwapSum / volumeSum else Double.NaN;
anchorVWAP.setStyle(Curve.Firm);
anchorVWAP.setDefaultColor(Color.white);
anchorVWAP.setlineWeight(2);





Like I have done to VWAP on this chart
shared chart link: https://tos.mx/!HUJOhtRh
Screen Shot 07-22-25 at 08.15 AM.PNG
 
Last edited by a moderator:
Solution
I want to put two standard deviations onto anchored VWAP
Code:
#yakBro intraday anchoredVWAP excluding extended hours volume 2019
# https://usethinkscript.com/threads/anchored-vwap-indicator-for-thinkorswim.171/post-11014

declare hide_on_daily;

def anchorTime = 0800;
def anchorEnd = 1600;

input ShowTodayOnly = yes;
def Today = if GetDay() == GetLastDay() then 1 else 0;
def postAnchorTime = if SecondsFromTime(anchorTime) >= 0 then 1 else 0;
def endAchorTime = if SecondsTillTime(anchorEnd) >= 0 then 1 else 0;

#plot anchorVWAP for intraday
def  volumeSum = compoundValue(1, if postAnchorTime and endAchorTime then volumeSum[1] + volume else 0, volume);
def  volumeVwapSum = compoundValue(1, if postAnchorTime and endAchorTime then...
I want to put two standard deviations onto anchored VWAP
Code:
#yakBro intraday anchoredVWAP excluding extended hours volume 2019
# https://usethinkscript.com/threads/anchored-vwap-indicator-for-thinkorswim.171/post-11014

declare hide_on_daily;

def anchorTime = 0800;
def anchorEnd = 1600;

input ShowTodayOnly = yes;
def Today = if GetDay() == GetLastDay() then 1 else 0;
def postAnchorTime = if SecondsFromTime(anchorTime) >= 0 then 1 else 0;
def endAchorTime = if SecondsTillTime(anchorEnd) >= 0 then 1 else 0;

#plot anchorVWAP for intraday
def  volumeSum = compoundValue(1, if postAnchorTime and endAchorTime then volumeSum[1] + volume else 0, volume);
def  volumeVwapSum = compoundValue(1, if postAnchorTime and endAchorTime then volumeVwapSum[1] + volume * vwap else 0, volume * vwap);

plot anchorVWAP = if ShowTodayOnly and !Today then Double.NaN else if anchorTime then volumeVwapSum / volumeSum else Double.NaN;
anchorVWAP.setStyle(Curve.Firm);
anchorVWAP.setDefaultColor(Color.white);
anchorVWAP.setlineWeight(2);





Like I have done to VWAP on this chart
shared chart link: https://tos.mx/!HUJOhtRh
View attachment 25246

Added deviations like your other vwap code
You can adjust the line weight at the input screen as well as the deviations and times.

Screenshot 2025-07-22 123300.jpg

Code:
#yakBro intraday anchoredVWAP excluding extended hours volume 2019
# https://usethinkscript.com/threads/anchored-vwap-indicator-for-thinkorswim.171/post-11014

declare hide_on_daily;

input lineweight = 3;
input anchorTime = 0800;
input anchorEnd  = 1600;

def na = Double.NaN;

input ShowTodayOnly = yes;
def Today = if GetDay() == GetLastDay() then 1 else 0;
def postAnchorTime = if SecondsFromTime(anchorTime) >= 0 then 1 else 0;
def endAchorTime = if SecondsTillTime(anchorEnd) >= 0 then 1 else 0;

#plot anchorVWAP for intraday
def  volumeSum = CompoundValue(1, if postAnchorTime and endAchorTime then volumeSum[1] + volume else 0, volume);
def  volumeVwapSum = CompoundValue(1, if postAnchorTime and endAchorTime then volumeVwapSum[1] + volume * vwap else 0, volume * vwap);
def volumeVwap2Sum = CompoundValue(1, if postAnchorTime and endAchorTime then volumeVwap2Sum[1] + volume * Sqr(vwap) else 0, volume * Sqr(vwap));

plot anchorVWAP = if ShowTodayOnly and !Today then Double.NaN else if anchorTime then volumeVwapSum / volumeSum else na;
anchorVWAP.SetStyle(Curve.FIRM);
anchorVWAP.SetDefaultColor(Color.WHITE);
anchorVWAP.SetLineWeight(lineweight);

input numdeviations1    = 1.0;
input numdeviations2    = 2.0;
input show_deviations   = yes;

def price = volumeVwapSum / volumeSum;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));

plot UpperBand1 = if ShowTodayOnly and !Today then na else if show_deviations then price + numdeviations1 * deviation else na ;
plot LowerBand1 = if ShowTodayOnly and !Today then na else if show_deviations then price - numdeviations1 * deviation else na;

UpperBand1.AssignValueColor(if UpperBand1 > UpperBand1[1] then CreateColor(0, 89, 104)
                      else if UpperBand1 < UpperBand1[1] then CreateColor(104, 15, 0)
                      else Color.YELLOW);
UpperBand1.SetLineWeight(lineweight);
UpperBand1.SetStyle(Curve.FIRM);

LowerBand1.AssignValueColor(if LowerBand1 > LowerBand1[1] then CreateColor(0, 89, 104)
                      else if LowerBand1 < LowerBand1[1] then  CreateColor(104, 15, 0)
                      else Color.BLUE);
LowerBand1.SetLineWeight(lineweight);
LowerBand1.SetStyle(Curve.FIRM);

plot UpperBand2 = if ShowTodayOnly and !Today then na else if show_deviations then price + numdeviations2 * deviation else na ;
plot LowerBand2 = if ShowTodayOnly and !Today then na else if show_deviations then price - numdeviations2 * deviation else na;

UpperBand2.AssignValueColor(if UpperBand2 > UpperBand2[1] then CreateColor(0, 89, 104)
                      else if UpperBand2 < UpperBand2[1] then CreateColor(104, 15, 0)
                      else Color.YELLOW);
UpperBand2.SetLineWeight(lineweight);
UpperBand2.SetStyle(Curve.FIRM);

LowerBand2.AssignValueColor(if LowerBand2 > LowerBand2[1] then CreateColor(0, 89, 104)
                      else if LowerBand2 < LowerBand2[1] then  CreateColor(104, 15, 0)
                      else Color.BLUE);
LowerBand2.SetLineWeight(lineweight);
LowerBand2.SetStyle(Curve.FIRM);

#
 
Solution

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