Scripting and Anchored VWAP April 24th Blog

I noticed in the script you used "Crossabove 0.5 - see second line below: What is it referencing?

Thanks, Jamie

//Define lookback eg 12 weeks, 127 = 84 calendar days;
Start = (BARDATE() == LAST(BARDATE()) - (12
7)) CrossesAbove 0.5;
//Find where signal matches the Highest High Value
Sig1 = HIGH() == HIGHESTSINCE(Start);
//Remove NonZero results showing most recent result as latest value
$Date = BarDate(NonZero(Sig1));
//Apply VWAP from Date
L1=AVWAP(BACKTYPE=Fixed, DATE=$Date);
//Calculate % difference from close
(CLOSE()/L1)-1

Hi Jamie,

That condition was added because if the lookback period of the ‘start’ variable begins on a non-trading day (eg weekend or holiday) then the calculation doesn’t work.

By adding the CrossesAbove 0.5 condition will trigger when the value changes from 0 (false) to 1 (true), so on the next trading day. Note we could have used any value between 0 and 1, or the ChangeTo 1 condition.

Here’s an alternative to the script to automatically plot the AVWAP tool from the YTD high rather than manually place it on the chart:

//Define starting date for YTD high;
Start = (BARDATE() == STRDATE(DATE=2019-12-31));
//Find where date matches the Highest High since Dec 31st;
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);
//Plot the VWAP;
Plot1 = R1

Note: to turn the formula into a scan change the last line to CLOSE() Crosses R1.

In this example, ALGN’s 2020 high occurred on Jan 9th, so starting the AVWAP on that date gives a value of $121.56, which was crossed yesterday (closed at $215.93):

Capture

Another anchored VWAP scan formula, this time starting from the highest volume day this year and looking for crosses above or below the average price since that date.

//Define start date eg end of last year;
Start = (BARDATE() == STRDATE(DATE=2019-12-31));
//Find where date matches the Highest High Volume value in the lookback period;
Sig = VOL() == HIGHESTSINCE(VOL(),Start);
//Remove Non Zero results to show most recent result as latest value;
$DATE = BarDate(NonZero(Sig));
//Calculate VWAP from High Vol Date
R1=AVWAP(BACKTYPE=Fixed, DATE=$DATE);
//Did close cross AVWAP?
R2=CLOSE() Crosses R1;
//Only include highs which occurred more than 10 days ago;
R2 and TIMESINCESIGNAL(Sig)>10

Capture