WiseTrader Toolbox

VariablePeriodWilliamsR

Background

Williams %R, created by Larry Williams, is a momentum oscillator that measures where the current price sits relative to the high-low range of the last n bars. It is essentially the mirror image of the fast Stochastic: it runs from 0 down to −100, where readings near 0 mean price is closing near the top of its range and readings near −100 mean it is closing near the bottom. Traders use it to flag overbought and oversold conditions and to time entries within a trend.

A standard Williams %R uses a fixed look-back. VariablePeriodWilliamsR takes a period for each bar, so the range window adapts to market conditions. The per-bar periods often come from an adaptor such as the DominantCycle.

Included formula

The toolbox ships a ready-made Adaptive Smoothed Williams %R indicator built on this function, so you can use it without writing any code. In AmiBroker open the Charts window, expand the WiseTraderToolbox group and drag Adaptive Smoothed Williams %R onto a chart.

It plots Williams %R in its own pane below price. The Adaptor you pick is what produces the per-bar period this function needs — so the range window adapts to the market — and an optional Smoother cleans up the input first. The adaptor's bounds, the smoothing and the colours are all set from the indicator's parameters.

The exported function

If you would rather build your own formula, the toolbox exports the calculation as a single AFL function you can call directly — it is the engine inside that indicator.

VariablePeriodWilliamsR(Price, Periods)
ParameterDescription
Price The price array the oscillator is calculated on. The Close is the usual choice.
Periods An array (or value) giving the range look-back to use at each bar. Most often this is fed from an adaptor such as the DominantCycle.

Usage

periods = DominantCycle( Close );
wr = VariablePeriodWilliamsR( Close, periods );
Plot( wr, "Adaptive Williams %R", colorRed );
Plot( -20, "", colorGrey40, styleDashed | styleNoLabel );
Plot( -80, "", colorGrey40, styleDashed | styleNoLabel );
Note

%R ranges from 0 to −100. Readings above −20 are generally considered overbought and below −80 oversold.