VWAP bands calculation question

Tidan

Member
I'm struggling to figure out how to calculate the +/-2 VWAP bands for this method of calculating the vwap. Any ideas?
Code:
plot VWAP = TotalSum(((high+low+close)/3) * (volume))/TotalSum(volume);
 
I'm struggling to figure out how to calculate the +/-2 VWAP bands for this method of calculating the vwap. Any ideas?
Code:
plot VWAP = TotalSum(((high+low+close)/3) * (volume))/TotalSum(volume);

This should help

Screenshot-2023-04-07-061522.png
Code:
input numdev = 2;
input price  = hlc3;
plot VWAP = TotalSum(price * volume) / TotalSum(volume);
def dev   = sqrt( totalsum(sqr(price - vwap)) / barnumber() );
plot UpperBand = vwap + numdev * dev;
plot LowerBand = vwap - numdev * dev;
 

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

Thank you SleepyZ, unfortunately the bands do not quite line up with the default vwap bands.

Thanks for letting me know. The following should work better.

There are two studies in the image. The upper chart is with the revised study using your basis. The second is the VWAP study, modified to include other timeframe options, using "Chart" as the timeframe. These both appear to match.


Code:
input numdev = 2;
input price  = hlc3;

plot VWAP = TotalSum(price * volume) / TotalSum(volume);
def dev   = Sqrt(totalsum(volume*sqr(price))/totalsum(volume) - Sqr(vwap));
plot UpperBand = VWAP + numdev * dev;
plot LowerBand = VWAP - numdev * dev;

Code:
# Standard VWAP modified to allow more timeframes

#
# TD Ameritrade IP Company, Inc. (c) 2011-2023
#

input numDevDn = -2.0;
input numDevUp = 2.0;
input timePerProfile = { default CHART, MINUTE, HOUR, DAY, WEEK, MONTH, "OPT EXP", BAR};


def period;
def yyyymmdd = GetYYYYMMDD();
def seconds = SecondsFromTime(0);
def month = GetYear() * 12 + GetMonth();
def day_number = DaysFromDate(First(yyyymmdd)) + GetDayOfWeek(First(yyyymmdd));
def dom = GetDayOfMonth(yyyymmdd);
def dow = GetDayOfWeek(yyyymmdd - dom + 1);
def expthismonth = (if dow > 5 then 27 else 20) - dow;
def exp_opt = month + (dom > expthismonth);
switch (timePerProfile) {
case CHART:
    period = 0;
case MINUTE:
    period = floor(seconds / 60 + day_number * 24 * 60);
case HOUR:
    period = floor(seconds / 3600 + day_number * 24);
case DAY:
    period = countTradingDays(min(first(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
case WEEK:
    period = floor(day_number / 7);
case MONTH:
    period = floor(month - first(month));
case "OPT EXP":
    period = exp_opt - first(exp_opt);
case BAR:
    period = barNumber() - 1;
}
def isPeriodRolled = no;#CompoundValue(1, period != period[1], yes);

def volumeSum;
def volumeVwapSum;
def volumeVwap2Sum;

if (isPeriodRolled) {
    volumeSum = volume;
    volumeVwapSum = volume * vwap;
    volumeVwap2Sum = volume * Sqr(vwap);
} else {
    volumeSum = CompoundValue(1, volumeSum[1] + volume, volume);
    volumeVwapSum = CompoundValue(1, volumeVwapSum[1] + volume * vwap, volume * vwap);
    volumeVwap2Sum = CompoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap), volume * Sqr(vwap));
}
def price = volumeVwapSum / volumeSum;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));

plot VWAP = price;
plot UpperBand = price + numDevUp * deviation;
plot LowerBand = price + numDevDn * deviation;

VWAP.SetDefaultColor(GetColor(0));
UpperBand.SetDefaultColor(GetColor(2));
LowerBand.SetDefaultColor(GetColor(4));
 
Thanks for letting me know. The following should work better.

There are two studies in the image. The upper chart is with the revised study using your basis. The second is the VWAP study, modified to include other timeframe options, using "Chart" as the timeframe. These both appear to match.
Its close enough(usually only a few cents off depending on where I anchor the vwap).
Thank you very much!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
221 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