Momentum

Williams %R Buy Sell Signals: Range Position and Divergence

Read Williams %R threshold exits, -50 centerline crosses and confirmed divergence. Includes Pine Script v6, zero-range handling and the Stochastic relation.

Williams %R Signal Interpretation

Quick-reference guide to 6 signal types you will see on the chart.

Signal TypeIndicator ConditionMarket MeaningInterpretation limits
Oversold exitWilliams %R crosses above the lower threshold at a confirmed close.The close has moved upward through the selected relative-range threshold.A move from -85 to -75 qualifies at -80; merely reading below -80 does not.
Overbought exitWilliams %R crosses below the upper threshold at a confirmed close.The close has moved downward through the selected relative-range threshold.The high-low window can change as old extremes leave it.
Regular bullish divergenceConsecutive confirmed price lows are lower while sampled %R values are higher.The lower price swing has a higher range-position reading.The oscillator values are sampled at price pivots; no separate oscillator-pivot or trend filter is used.
Regular bearish divergenceConsecutive confirmed price highs are higher while sampled %R values are lower.The higher price swing has a lower range-position reading.A divergence does not guarantee that the next move will reverse.
Centerline up-crossWilliams %R crosses above -50 on a closed bar.The close is now in the upper half of its lookback high-low range.-50 is the centerline, not zero.
Centerline down-crossWilliams %R crosses below -50 on a closed bar.The close is now in the lower half of its range.No earlier overbought or oversold visit is required by the code.

Williams %R Pine Script Signal Code

Educational indicator example. Review its exact rules and compare its plots with your intended calculation in TradingView. It does not place orders or establish profitability.

Pine Script v6
//@version=6
indicator("Williams Percent R Signal Rules", overlay=false)
length = input.int(14, "Range Length", minval=1)
upper = input.float(-20, "Upper Threshold", minval=-49.9, maxval=0)
lower = input.float(-80, "Lower Threshold", minval=-100, maxval=-50.1)
pivotBars = input.int(2, "Pivot Bars Each Side", minval=1, maxval=20)
highestPrice = ta.highest(high, length)
lowestPrice = ta.lowest(low, length)
width = highestPrice - lowestPrice
wr = bar_index >= length - 1 and width > 0 ? -100 * (highestPrice - close) / width : na
exitLowRaw = ta.crossover(wr, lower)
exitHighRaw = ta.crossunder(wr, upper)
midUpRaw = ta.crossover(wr, -50)
midDownRaw = ta.crossunder(wr, -50)
exitLow = barstate.isconfirmed and exitLowRaw
exitHigh = barstate.isconfirmed and exitHighRaw
midUp = barstate.isconfirmed and midUpRaw
midDown = barstate.isconfirmed and midDownRaw
priceLow = ta.pivotlow(low, pivotBars, pivotBars)
priceHigh = ta.pivothigh(high, pivotBars, pivotBars)
newLow = not na(priceLow)
newHigh = not na(priceHigh)
priorLow = ta.valuewhen(newLow, priceLow, 1)
priorLowWr = ta.valuewhen(newLow, wr[pivotBars], 1)
priorHigh = ta.valuewhen(newHigh, priceHigh, 1)
priorHighWr = ta.valuewhen(newHigh, wr[pivotBars], 1)
bullDiv = barstate.isconfirmed and newLow and priceLow < priorLow and wr[pivotBars] > priorLowWr
bearDiv = barstate.isconfirmed and newHigh and priceHigh > priorHigh and wr[pivotBars] < priorHighWr
plot(wr, "Williams %R", color.blue, 2)
hline(upper, "Upper", color.red)
hline(-50, "Center", color.gray)
hline(lower, "Lower", color.green)
plotshape(exitLow, "Lower Exit", shape.triangleup, location.bottom, color.green)
plotshape(exitHigh, "Upper Exit", shape.triangledown, location.top, color.red)
// Plot on the confirmation bar; do not move the labels back to the pivot.
plotshape(bullDiv, "Bull Divergence", shape.labelup, location.bottom, color.teal, text="DIV")
plotshape(bearDiv, "Bear Divergence", shape.labeldown, location.top, color.orange, text="DIV")
plotshape(midUp, "Center Up", shape.circle, location.bottom, color.blue, size=size.tiny)
plotshape(midDown, "Center Down", shape.circle, location.top, color.purple, size=size.tiny)
alertcondition(exitLow, "Williams R Lower Exit", "Williams R crossed above the configured lower threshold")
alertcondition(exitHigh, "Williams R Upper Exit", "Williams R crossed below the configured upper threshold")
alertcondition(midUp, "Williams R Center Up", "Williams R crossed above -50")
alertcondition(midDown, "Williams R Center Down", "Williams R crossed below -50")
alertcondition(bullDiv, "Williams R Bull Divergence", "Confirmed bullish price-pivot divergence")
alertcondition(bearDiv, "Williams R Bear Divergence", "Confirmed bearish price-pivot divergence")

Example settings for Williams %R

Record the inputs used by the example. These settings are not an optimized trading recommendation.

Feature comparison table: Default vs Description
ParameterDefaultDescription
Range Length14Defines the highest-high and lowest-low window, including the current bar. A full window is required before this example returns a value.
Upper / Lower Threshold-20 / -80The plot lines and alerts use these same inputs. Upper stays above -50; lower stays below -50.
Pivot Bars Each Side2Price swings need this number of bars on both sides. Two right-side bars imply a two-bar confirmation delay, not advance knowledge of a swing.

Turn the condition into an explicit rule

Specify the calculation, confirmation time, entry and exit rules before asking Pineify to draft or revise Pine Script. Review the code and simulate realistic costs before evaluating a strategy.

Explore Pine Script coding

FAQ

Williams %R Signals FAQ

How is Williams %R calculated?
For a nonzero range, %R = -100 × (highest high - close) / (highest high - lowest low). A hypothetical high of 110, low of 100 and close of 108 gives -20. Close at the high gives 0; close at the low gives -100. This example uses standard close and returns no value when the high-low range is zero.
Why does the example return no value for a flat range?
With identical high and low, the denominator is zero and the close position within the range is undefined. Assigning -100 would falsely label flat data as maximally oversold. The script instead returns na and cannot create a threshold cross from that unavailable value.
How does Williams %R relate to fast Stochastic?
With the same close, high-low window and no smoothing, Williams %R equals raw Stochastic K minus 100. It is a scale shift, not a reversed time series. Raw K at 80 corresponds to %R at -20. Comparable threshold events have the same timing; differences can arise if the Stochastic line is smoothed or uses different inputs.
Does a confirmed divergence predict a swing before it happens?
No. This script samples %R at confirmed price pivots. With two right-side bars, a price low is recognized two bars later, and the divergence marker stays on that later bar. For hypothetical lows of 100 then 98 and readings of -90 then -75, bullish divergence qualifies only after the second pivot confirms.
Are momentum failures and extreme holds implemented?
No. Those need separate rules for duration, visits to an extreme, pullbacks and later triggers. The six supplied alerts cover two threshold exits, two centerline crosses and two regular divergences. A reading above -10 or below -90 alone is not a multi-bar hold or a prediction of an imminent snap-back.
Does Williams %R change during an open bar?
Yes. The current close, high and low are part of the calculation. The line can move while the bar is open; these conditions wait for the confirmed close. Changed inputs or historical feed revisions can still change past results.
Which settings or Supertrend combination are most reliable?
No tested ranking is supplied. A Supertrend filter would be a new rule, with negative ta.supertrend direction representing its bullish state. It is not included here. Define full entry, exit and execution assumptions before evaluating any such combination; indicator crossings alone do not establish a win rate.