Williams Volatility Channel (Amibroker Code)

The article can be found here.

Backtest no. 1:

  • We use a N-day lookback period.
  • We go long when the close crosses above the upper volatility channel.
  • We sell when the close crosses below the lower volatility channel.

Amibroker code:

oddis=Optimize(“Lookback period”,5,2,10,1) ;

Vc= oddis ;
Up=HHV(((((H+L+C)/3)*2)- H),Vc);
Lo=LLV(((((H+L+C)/3)*2)- L),Vc);

Buy = Cross(Close,up) ;
BuyPrice=Close;
Sell = Cross(lo,Close) ;
SellPrice=Close;

Tradestation code:

{
Strategy 117A - Williams volatility channel
We use a N-day lookback period.
We go long when the close crosses above the upper volatility channel.
We sell when the close crosses below the lower volatility channel.
}

Inputs: Lookback(5);

Vars: Up(0), Lo(0);

Up = Highest(((((High + Low + Close) / 3) * 2)- High), Lookback);
Lo = Lowest(((((High + Low + Close) / 3) * 2)- Low), Lookback);

if Close cross over Up Then
	buy this bar on close;

if Close cross under Lo then 
	sell this bar on close;

Backtest no. 2:

  • We use a N-day lookback period.
  • We go long when the close crosses below the lower volatility channel.
  • We sell when the close crosses above the upper volatility channel.

Amibroker code:

oddis=Optimize(“Lookback period”,5,2,10,1) ;

Vc= oddis ;
Up=HHV(((((H+L+C)/3)*2)- H),Vc);
Lo=LLV(((((H+L+C)/3)*2)- L),Vc);

Buy = Cross(lo, Close) ;
BuyPrice=Close;
Sell = Cross(Close,up) ;
SellPrice=Close;

Tradestation code:

{
Strategy 117B - Williams volatility channel
We use a N-day lookback period.
We go long when the close crosses below the lower volatility channel.
We sell when the close crosses above the upper volatility channel.
}

Inputs: Lookback(5);

Vars: Up(0), Lo(0);

Up = Highest(((((High + Low + Close) / 3) * 2)- High), Lookback);
Lo = Lowest(((((High + Low + Close) / 3) * 2)- Low), Lookback);

if Close cross under Lo Then
	buy this bar on close;

if Close cross over Up then 
	sell this bar on close;