Williams %R indicator on TradingView: formula and limits
Williams %R places the current close within a recent high-low range on a scale from -100 to 0. Readings near zero mean the close is near the window high. That can persist during a rising trend; it does not establish an imminent reversal.
Calculate the negative scale
Use the highest high H and lowest low L from the same N bars, including the current bar, with close C. The formula is:
The following is an illustrative five-bar dataset, not market data or a backtest. At bar 5, H = 110, L = 90 and C = 106, giving -100 × 4 / 20 = -20.
| Bar | High | Low | Close |
|---|---|---|---|
| 1 | 110 | 100 | 104 |
| 2 | 108 | 97 | 100 |
| 3 | 105 | 90 | 94 |
| 4 | 107 | 93 | 102 |
| 5 | 109 | 99 | 106 |
Holding H = 110 and L = 90 fixed, closes of 110, 106, 100, 94 and 90 produce %R values of 0, -20, -50, -80 and -100. A move from -80 to -20 is an increase in the oscillator. The minus sign does not reverse that ordering.
A crossing without a price move
Now append bar 6 with high 108, low 101 and close 106. Bar 1 leaves the five-bar window. H becomes 109 while L stays 90, so %R becomes -100 × 3 / 19 = -15.789. The close stayed at 106 but the oscillator moved above -20. Check expired extremes before attributing every crossing to new buying or selling.
Copy a Williams %R window check
Paste this complete indicator into TradingView Pine Editor, save it, and add it to the chart. It plots the formula explicitly and exposes the difference from ta.wpr(length) in the Data Window. Alerts describe crossings; the script places no orders.
//@version=6
indicator("Williams %R window check", shorttitle="WPR check", overlay=false)
length = input.int(14, "Length", minval=1)
confirmedOnly = input.bool(true, "Confirmed bars only")
highestHigh = ta.highest(high, length)
lowestLow = ta.lowest(low, length)
priceRange = highestHigh - lowestLow
fullWindow = bar_index >= length - 1
wpr = fullWindow and priceRange > 0 ? -100.0 * (highestHigh - close) / priceRange : na
builtIn = ta.wpr(length)
showBar = not confirmedOnly or barstate.isconfirmed
plot(showBar ? wpr : na, "Williams %R", color=color.blue, linewidth=2, style=plot.style_linebr)
upper = hline(-20, "Upper reference", color=color.gray)
hline(-50, "Range midpoint", color=color.new(color.gray, 50))
lower = hline(-80, "Lower reference", color=color.gray)
fill(upper, lower, color=color.new(color.blue, 92))
plot(showBar and not na(wpr) ? wpr - builtIn : na, "Manual minus ta.wpr", display=display.data_window)
crossAbove = ta.crossover(wpr, -80)
crossBelow = ta.crossunder(wpr, -20)
alertcondition(showBar and crossAbove, "WPR crossed above -80", "Williams %R crossed above -80")
alertcondition(showBar and crossBelow, "WPR crossed below -20", "Williams %R crossed below -20")The blue line is %R; the gray lines mark -20, -50 and -80. On eligible bars, "Manual minus ta.wpr" should be zero apart from floating-point rounding when both calculations use the same OHLC data. A discrepancy is a reason to inspect the inputs, not a trading signal.
| Input | Default | Effect |
|---|---|---|
| Length | 14; minimum 1 | Sets the high-low window and the required startup bar count. |
| Confirmed bars only | On | Hides the open bar and gates alert conditions until its closing update. |
With confirmation off, high, low and close can change during the live bar, and a crossing can disappear. With confirmation on, choose a bar-close alert frequency for the intended workflow. This script reads only the chart timeframe.
Compare Williams %R, Stochastic and RSI
| Calculation | Inputs and transformation | Comparison boundary |
|---|---|---|
| Williams %R | -100 × (H - C) / (H - L) | Range position on a negative scale. |
| Raw Stochastic %K | 100 × (C - L) / (H - L) | %R = raw %K - 100 with identical inputs. |
| Smoothed Stochastic | SMA of raw %K; %D smooths %K again | Smoothing changes the series and can delay crossings. |
| RSI | 100 - 100 / (1 + average gain / average loss) | Uses smoothed close-to-close gains and losses, not H and L. |
For the five-bar example, raw %K is 100 × 16 / 20 = 80, so %R is 80 - 100 = -20. This is an exact algebraic offset, not an approximate inverse or evidence that %R reacts faster. To compare TradingView Stochastic, use the same length and set its extra %K smoothing to 1; %D remains a separate series.
RSI cannot be recovered from those three final numbers. For example, two close sequences ending at 106 can share H = 110 and L = 90 while having different intermediate gains and losses. Their %R matches, but their RSI need not match.
Check these limits before using a signal
- A flat window has H = L. This example outputs
na, rather than inventing a midpoint or an extreme. - The script intentionally suppresses the first N - 1 bars of the loaded dataset. With N = 14, the first eligible index is 13. This is an explicit startup policy; do not assume every script shares it.
- An expired high or low changes the denominator. Use the same window boundary when reconciling two implementations.
- A close near the top or bottom of its window can continue there. Treat -20 and -80 as reference levels, not automatic sell and buy orders.
- Timeframe, session and feed differences change the bars. Compare the same completed bar before changing the formula to force a match.
To test a trading rule, define entry timing, exit, loss limit, position size and execution costs separately. This calculation example provides no performance estimate. Educational information, not investment advice.
Turn the checked calculation into a script specification
Use Pineify's Pine Script AI Coding Agent to describe the inputs and behavior you need. A reviewable request starts with the calculation and boundary rules:
Create Williams %R with length 14 and chart OHLC. Require a full window, return na when its range is zero, and confirm crossings at bar close. Keep the manual calculation and ta.wpr comparison visible for inspection. Do not add strategy orders.
- Open the coding agent and provide the specification.
- Inspect the generated length and price inputs.
- Copy the code into TradingView and compare completed bars.
- Check startup, flat windows and a live bar before enabling alerts.
- Define exits and costs separately if you later request a strategy.
Williams %R FAQ
Sources and related calculations
Official documentation checked October 17, 2026. The numerical dataset and window-expiry example are illustrative calculations created for this page.