WilliamsVixFix Using PercentRank (Amibroker And Tradestation Code)

The strategy in plain English:

  • Go long if the WilliamsVixFix closed high on the x-day PercentRank. We used 98% as threshold and entry on the close.
  • The exit is when today’s close is higher than yesterday’s close. Exit on the close.

Click here to see the original article.

Amibroker code:

HighestClose = HHV(close,22);
WilliamsVixFix = (((HighestClose – Low) / HighestClose)*100);
Plot(WilliamsVixFix,”WilliamsVixFix”,colorBlue,styleLine);

Buy = PercentRank(WilliamsVixFix,10) > 98 ;
BuyPrice=Close;
Sell = C > Ref(H,-1);
SellPrice = Close;

Second code:

Let’s flip the strategy and short:

Short = PercentRank(WilliamsVixFix,50) < 2;
shortPrice = C;
Cover = C < MA(C,5);
coverPrice = C ;

Tradestation code:

{
WilliamsVixFix long  (strategy no.5A)
https://www.quantifiedstrategies.com/williamsvixfix-explained-does-it-work/
Go long if the WilliamsVixFix closed high on the x-day PercentRank. 
We used 98% as threshold and entry on the close.
The exit is when today’s close is higher than yesterday’s close. 
Exit on the close.
}

Inputs:
	HighestCloseLookback(22),
	PercentRankLookback(10),
	PercentRankTreshold(98);
	
Vars:
	index1(0),
	index2(0),
	highestClose(0);

Arrays:
	WilliamsVixFix[](0);

Array_setmaxindex(WilliamsVixFix, PercentRankLookback+1);

for index1 = 0 to PercentRankLookback Begin
	highestClose = 0;
	for index2 = 0 to HighestCloseLookback-1 Begin
		if Close[index1 + index2] > highestClose then 
			highestClose = Close[index1 + index2];  
	end;
	WilliamsVixFix[index1] = (((highestClose - Low[index1]) / highestClose) * 100);
end;

if (Marketposition = 0) and (PercentRankAB(WilliamsVixFix, PercentRankLookback) > PercentRankTreshold) Then
	Buy this bar at close;

if Close > High[1] Then
	Sell this bar at close;

Second strategy:

{
WilliamsVixFix short  (strategy no.5B)
https://www.quantifiedstrategies.com/williamsvixfix-explained-does-it-work/
Go short if the WilliamsVixFix closed low on the x-day PercentRank. 
We used 2% as threshold and entry on the close.
The exit is Close is lower than average of previous five Closes. 
Exit on the close.
}

Inputs:
	HighestCloseLookback(22),
	PercentRankLookback(50),
	PercentRankTreshold(2),
	ExitAverageLookback(5);
	
Vars:
	index1(0),
	index2(0),
	highestClose(0);

Arrays:
	WilliamsVixFix[](0);

Array_setmaxindex(WilliamsVixFix, PercentRankLookback+1);

for index1 = 0 to PercentRankLookback Begin
	highestClose = 0;
	for index2 = 0 to HighestCloseLookback-1 Begin
		if Close[index1 + index2] > highestClose then 
			highestClose = Close[index1 + index2];  
	end;
	WilliamsVixFix[index1] = (((highestClose - Low[index1]) / highestClose) * 100);
end;

if (Marketposition = 0) and (PercentRankAB(WilliamsVixFix, PercentRankLookback) < PercentRankTreshold) Then
	Sellshort this bar at close;

if Close < Average(Close, ExitAverageLookback) Then
	Buytocover this bar at close;

Disclosure: We are not financial advisors. Please do your own due diligence and investment research or consult a financial professional. All articles are our opinions – they are not suggestions to buy or sell any securities.