Anchored VWAP scripts

To calculate the distance from the anchored VWAP line for IPOs - and therefore be alerted when the level is crossed - use the following scripts.

[Click here and here for other IPO posts.]

Distance from A-VWAP as a Show View tool or watchlist column:

//Get IPO Date
$IPO=FIRST(BARDATE());
//Calculate VWAP from IPO Date
R1=AVWAP(BACKTYPE=Fixed, DATE=$IPO);
//Calculate % difference
((CLOSE()/R1)-1)

The following can be added to a watchlist for A-VWAP crosses:

//Get IPO Date
$IPO=FIRST(BARDATE()); 
//Calc VWAP from IPO Date;
V1=AVWAP(BACKTYPE=Fixed, DATE=$IPO); 
//Does Close cross VWAP? 
Above = CLOSE() CrossesAbove V1; 
Below = CLOSE() CrossesBelow V1; 
//For formatting column in a watchlist 
//Cross above will display as 1, cross below as 0.5;
IF(Above==1,1,(IF(Below==1,0.5),0))

This shows PTON crossing below, and WORK above:

Capture

To format the A-VWAP Cross column right-click on the header and change the Custom Labels to match the values in the script (ie ==1 is Above, etc):

Capture

Here’s a script for breakouts above the AVWAP from the previous high. Based on Brian Shannon’s Tweet.

The high has been defined using a 22 bar Pivot Label, ie there has to be 22 bars (1 month on a daily chart) of lower highs before and after the high. Change the value of $PL (line 3 below) to change the significance of the high.

//Define high based on pivots labels, eg a value of 22 requires at least 22 bars before the high and 22 bars after;
$PL=22;
P1=PIVOT(TYPE=High, MIN=$PL, IGNOREUNCONFIRMED=True, DIR=Both);
//Get the date of the high from which the AVWAP will be calculated;
$DATE = BarDate(NonZero(P1));
//Calculate the VWAP from Pivot High date;
R1=AVWAP(BACKTYPE=Fixed, DATE=$DATE);
//Did the close cross above AVWAP and make a new month high?;
CLOSE() CrossesAbove R1 and HIGH() > HIGHESTHIGH(BARS=22)

AVWAP Pivot Hi Crosses

I am pretty new to this kind of scripting. I did not succeed in getting this script plot anything with ShowPlot on a chart. Can anyone share a workbook with this example please?

Hi Paul,

The above is a script for a scan, so it won’t plot anything. To automatically plot the AVWAP from a pivot high try this in a Show Plot:

//Set Pivot Label value and get pivot date;
$PL=22;
P1=PIVOT(TYPE=High, MIN=$PL, IGNOREUNCONFIRMED=True, DIR=Both);
$DATE = BarDate(NonZero(P1));
//Calculate VWAP from Pivot Low Date;
AVWAP(BACKTYPE=Fixed, DATE=$DATE)

Workbook attached, with the scan formula in the watchlist column and the AVWAP plotted in blue from the 22 bar pivot high.

AVWAP-Pivot-High.owb (35.7 KB)

Thank you Darren!

Hi,
I tried to use the above script with the 22 day pivot, but changed the last line to Close() > R1 instead of Plot1= R1 in an attempt to scan for all stocks that are closing today above the AVWAP, but it doesn’t work, even though if I used the same script in the WL, it calculates the AVWAP correctly.
Any reason why it doesn’t work on the scanner? I’d like to scan for all stocks that are trading above a 3 month AVWAP for example.
Thanks!
Syd

I’m not sure what formula you are using but this will get you those trading above the VWAP from their 3 month high (as long as the high occurred at least 2 days ago to avoid those making new highs).

//Get 3 month high ie over last 63 trading days;
Start = BARINDEX()==LAST(BARINDEX())-63;
//Find where date matches the Highest High value in the lookback period;
Sig = HIGH() == HIGHESTSINCE(Start);
//Remove Non Zero results to show most recent result as latest value;
$DATE = BarDate(NonZero(Sig));
//Calculate VWAP from High Date;
R1=AVWAP(BACKTYPE=Fixed, DATE=$DATE);
//Is close above VWAP and the high more that a day ago?;
CLOSE()>R1 and TIMESINCESIGNAL(Sig) > 1

Only 60 of the $SPX members are currently above their 3 month A-VWAP high, with $TSLA 15% above. Duplicate the scan formula above and change the last line to DIFFPCT(CLOSE(),R1) to display the percentage above in a watchlist or Show View.

Image