Scripting and Anchored VWAPs

Scripting and Anchored VWAPs

Learn how to create scans and tools based on the Anchored Volume-Weighted Average Price (AVWAP) tool.

The Anchored Volume-Weighted Average Price tool is a great way to determine potential support and resistance levels for any stock. Brian Shannon, CMT believes that it is because of “anchoring bias” - the human tendency to rely heavily on the first piece of information encountered when making decisions and then use that initial piece of information to make future decisions.

To learn more about AVWAPs and how they can be used we highly recommend Brian’s fantastic new book: Maximum Trading Gains With Anchored VWAP - The Perfect Combination of Price, Time & Volume. Click here to order.

Significant highs and lows are suitable starting points from which to calculate the average price paid. In the following example of Microsoft ($MSFT), the tool has been placed on the November 2021 high (in green) and the November 2022 low (in blue). It’s telling us the average price paid for Microsoft since the high is $273.02, but only $245.28 since the low, and the price is currently trading between these levels after failing to break above the green line three times:

Anchored VWAP Anchored VWAP

With Optuma’s scripting language you can use the AVWAP() function in a number of ways to automatically find these AVWAP levels to really speed up your analysis.

For example, in a watchlist column you can use the following to find how far the current price is from a VWAP anchored to a fixed date, such as the first trading day of the year:

1
2
V1=AVWAP(BACKTYPE=Fixed, DATE=2023-01-03);
DIFFPCT(CLOSE(), V1)

It’s good practice to click on the text in the Scripting Manager to open a pop-up window where you can change the parameters of the function (this is better than typing the text and risking using the wrong syntax ).

Script Editor Script Editor

You could also scan for when the price crosses a VWAP anchored to a 3-month lookback. It might be useful to run this at the end of a month:

CLOSE() Crosses AVWAP(BACKTYPE=Month, BARS=3))

Variable Lookback Dates

These formulas are great for anchoring to a specific date, but of course not all stocks have highs and lows on the same day. This is a bit trickier, but it can be done! The first part of the following formula identifies the respective 3-month high date for each stock. It uses the high or low day over that period from which to start the AVWAP calculation. It will return a true result when the closing price crosses above the AVWAP level, with the caveat that the high must have occurred more than 10 days ago:

1
2
3
4
5
6
7
8
9
10
11
12
//Set highest high lookback period in bars eg 63 bars for 3 months;
Start = BARINDEX()==LAST(BARINDEX())-63;
//Find when high occurred;
Sig = HIGH() == HIGHESTSINCE(Start);
//Find when low occurred;
//Sig = LOW() == LOWESTSINCE(Start);
//Remove Non Zero results showing most recent result as latest value;
$DATE = BarDate(NonZero(Sig));
//Calculate VWAP from Signal date;
R1=AVWAP(BACKTYPE=Fixed, DATE=$DATE);
//Signal when price crosses above the VWAP if high occurred > 10 days ago;
TIMESINCESIGNAL(Sig)>10 and CLOSE() CrossesAbove R1

NOTE: To change it from the 3-month high to the low, comment out line 5 (add // to the start of the line) and enable line 7 (delete the //).

AVWAP Scan AVWAP Scan

Automatically applying AVWAPs to a chart

By modifying the scan formula used above we can use a Show Plot tool to automatically apply the tool to an important high or low, instead of manually drawing it on the chart. The following will apply the tool to the 6-month low.

1
2
3
4
5
6
7
8
9
10
11
//Set lowest low lookback period in bars eg 126 bars for 6 months;
Start = BARINDEX()==LAST(BARINDEX())-126;
//Find when low occurred;
Sig = LOW() == LOWESTSINCE(Start);
//Find when high occurred;
//Sig = HIGH() == HIGHESTSINCE(Start);
//Remove Non Zero results showing most recent result as latest value;
$DATE = BarDate(NonZero(Sig));
//Calculate VWAP from Signal date;
R1=AVWAP(BACKTYPE=Fixed, DATE=$DATE);
R1

TIP: In the Script Editor window save the script formula as an indicator to the same view to add it to your toolbox.

As you scroll down the watchlist the tool will automatically be drawn from the respective turning dates on the chart:

Show Plot Tool Show Plot Tool

Using AVWAP from the IPO date

As Brian writes in his book, the AVWAP from a stock’s IPO date can be an important level to keep on your chart. To do this automatically, use the following in a Show Plot tool to draw the AVWAP on the chart from the first trading day:

1
2
3
4
Get IPO Date;
$IPO=FIRST(BARDATE());
//Draw VWAP from IPO Date;
AVWAP(BACKTYPE=Fixed, DATE=$IPO)

From there it’s a small adjustment if you wish to find the percentage the price is from the IPO level, or to get a signal when it crosses, as per this example of Airbnb ($ABNB):

IPO AVWAP IPO AVWAP

As you can see, scripting for AVWAP levels and price proximity in Optuma is very flexible. I’m sure you have more ideas. Feel free to share or post queries on this forum thread, and Optuma clients can click the buttons below to download and open Australian and US watchlists featuring the AVWAP scripting.

Next time we’ll look at some quantitative tests using AVWAP levels.