Data Analytic Investments
OscillatorsBeginner

Williams %R

Inverted Stochastic that measures where price sits within its recent high-low range.

1H, 4H, Daily
Crypto, Forex, Equities
Pine Script v5

What is it?

Developed by Larry Williams in 1973, Williams %R is essentially an inverted Stochastic %K. Formula: %R = (Highest High - Close) / (Highest High - Lowest Low) × -100. The scale runs from 0 to -100 (note the negative values). Readings from 0 to -20 are overbought; -80 to -100 are oversold. Because it uses only the close relative to the high-low range (no smoothing), it is faster and more sensitive than the Stochastic. This makes it useful for short-term timing but prone to noise.

When to use it

  • Short-term timing: Williams %R reaching -80 or below in an uptrend is a potential pullback-entry signal; reaching 0 to -20 in a downtrend is a potential short entry.
  • Failure swings: %R reaching -80 but failing to reach -100 on the next dip, then crossing back above -80, is a bullish failure swing.
  • Momentum confirmation: %R staying above -50 in an uptrend confirms bullish momentum; staying below -50 in a downtrend confirms bearish momentum.
  • Combining with trend filters: use a 200-period EMA to determine trend direction, then use Williams %R only for entries in the trend direction.
  • Divergence: price making a new low while %R makes a higher low is a bullish divergence signal.

Common pitfalls

  • Williams %R uses no smoothing — it reacts to every single candle. This makes it very noisy on short timeframes. Apply a 3-period SMA to %R for smoother signals.
  • The inverted scale (0 to -100) confuses many traders. Remember: -80 is oversold (near the low of the range), not overbought.
  • Like all oscillators, %R can remain in overbought or oversold territory for extended periods during strong trends.
  • Williams %R is highly sensitive to the lookback period. The default 14 periods is very short — try 21 or 28 for less noise.
  • Because %R and Stochastic %K are mathematically equivalent (just inverted), using both simultaneously adds no new information.

Free code template

Paste directly into TradingView Pine Editor → Add to chart.

Pine Script v5
/indicator("Williams %R — DAI Template", shorttitle="DAI W%R", overlay=false)

wrLen = input.int(14, "Length", minval=1)
obLevel = input.int(-20, "Overbought", maxval=0)
osLevel = input.int(-80, "Oversold",   minval=-100)

hh = ta.highest(high, wrLen)
ll = ta.lowest(low, wrLen)
wrVal = (hh - close) / (hh - ll) * -100
wrSma = ta.sma(wrVal, 3)

wrColor = wrVal >= obLevel ? #ef4444 : wrVal <= osLevel ? #3b82f6 : #22c55e

plot(wrVal,  "W%R",      color=wrColor,                      linewidth=2)
plot(wrSma,  "W%R SMA3", color=color.new(#f97316, 30),       linewidth=1)
hline(obLevel, "Overbought", color=color.new(#ef4444, 40), linestyle=hline.style_dashed)
hline(-50,     "Midline",    color=color.new(#94a3b8, 60), linestyle=hline.style_dotted)
hline(osLevel, "Oversold",   color=color.new(#3b82f6, 40), linestyle=hline.style_dashed)
bgcolor(wrVal >= obLevel ? color.new(#ef4444, 92) : wrVal <= osLevel ? color.new(#3b82f6, 92) : na)

bullCross = ta.crossover(wrVal, osLevel)
bearCross = ta.crossunder(wrVal, obLevel)
plotshape(bullCross, "Bull", shape.triangleup,   location.bottom, #22c55e, size=size.small)
plotshape(bearCross, "Bear", shape.triangledown, location.top,    #ef4444, size=size.small)

alertcondition(bullCross, "W%R Bull", "Williams %R crossed above " + str.tostring(osLevel))
alertcondition(bearCross, "W%R Bear", "Williams %R crossed below " + str.tostring(obLevel))