Williams
Williams in ProBuilder returns Williams %R, a -100 to 0 oscillator locating the close within the high-low range of N bars. Syntax, formula, examples, gotchas.
Syntax
Williams[N](close)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
N | integer | 14 | Lookback period over which the highest high and lowest low are taken. |
close | price source | close | The price compared against the range. The conventional input is close. |
Formula
Williams %R = ((Highest High over N - Close) / (Highest High over N - Lowest Low over N)) * -100When the close sits at the very top of the N-bar range the value is 0, and at the very bottom it is -100.
How it works
Each bar, the indicator finds the highest high and the lowest low of the last N bars, then expresses how far the current close is from that high as a fraction of the whole range. Multiplying by -100 flips the scale, so the output always lies between -100 and 0.
Williams %R is essentially an inverted Stochastic %K. Where Stochastic measures distance from the low of the range on a 0 to 100 scale, %R measures distance from the high on a -100 to 0 scale. The two lines contain the same information, only the axis differs, and %R is typically plotted without the additional smoothing that Stochastic applies.
Because the calculation is anchored to the range rather than to average gains and losses, %R reacts immediately when price presses against recent extremes, which makes it faster but also noisier than RSI at the same period.
Examples
Example 1, Standard 14-period Williams %R (Indicator)
// 14-period Williams %R with the conventional threshold lines
myWR = Williams[14](close)
RETURN myWR AS "Williams %R", -20 AS "Overbought", -80 AS "Oversold"Plots the classic 14-period %R together with its -20 and -80 reference levels, matching the source's standard usage.
Example 2, Oversold bounce entries in an uptrend (ProBacktest)
// Buy oversold readings above a rising long-term average
trend = Average[200](close)
wr = Williams[14](close)
IF NOT LongOnMarket THEN
IF close > trend AND wr < -80 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
ELSE
IF wr > -20 THEN
SELL AT MARKET
ENDIF
ENDIFBuys when %R signals oversold conditions while price remains above its 200-bar average, and exits once %R reaches the overbought zone.
Example 3, Screening for overbought instruments (ProScreener)
// Instruments overbought on both daily and hourly Williams %R
TIMEFRAME(1 day, updateonclose)
wrDaily = Williams[14](close)
TIMEFRAME(1 hour)
wrHourly = Williams[14](close)
SCREENER[wrDaily > -20 AND wrHourly > -20](wrDaily AS "%R daily")Returns instruments whose %R is above -20 on both the daily and hourly timeframes, flagging stretched conditions across two horizons.
Interpretation
| Zone | Range | Reading |
|---|---|---|
| Overbought | -20 to 0 | Close is near the top of the recent range. Momentum is strong, but the move is stretched. |
| Neutral | -80 to -20 | Close sits inside the body of the range, no extreme condition. |
| Oversold | -100 to -80 | Close is near the bottom of the recent range. Selling has been persistent. |
In trending markets %R can pin at one extreme for long stretches: a strong uptrend routinely holds above -20 for many bars. Overbought is therefore not a sell signal by itself. Common refinements include requiring %R to exit the extreme zone before acting, or filtering signals with a trend measure such as a long moving average or ADX.
Common errors and gotchas
- Sign confusion. The scale runs from -100 to 0, so "above -20" means overbought and "below -80" means oversold. Conditions such as
wr > 80can never be true and silently disable the logic. - Wrong bracket types. The period uses square brackets and the price parentheses:
Williams[14](close).Williams(14)is a syntax error. - Fading strong trends. Selling every overbought reading in an uptrend is the classic %R failure mode. The indicator marks range position, not an imminent reversal.
- Assuming it differs from Stochastic. %R equals
Stochastic %K - 100(a sign-flipped %K). Running both on the same chart adds no new information.
Related instructions
Stochastic, the same range-position calculation on a 0 to 100 scale.StochasticD, smoothed signal line of the Stochastic.RSI, momentum oscillator based on average gains and losses.CCI, unbounded oscillator measuring deviation from an average.SMI, stochastic momentum index, a double-smoothed relative.Highest, highest value over N bars, one building block of %R.Lowest, lowest value over N bars, the other building block.Momentum, raw price change over N bars.
