Momentum indicator
Williams %R Calculator
Compute Williams %R for one bar from the highest high, lowest low, and current close over your lookback period. Its meaning, where price sits within its recent range, is the useful takeaway.
What Williams %R is
Williams %R, created by Larry Williams, is a momentum oscillator closely related to the Stochastic. It measures where the current close sits within the high-to-low range of the last N bars, but expresses the result on a scale from 0 down to −100.
The formula is −100 × (highest high − close) ÷ (highest high − lowest low), where the highest high and lowest low are taken over the lookback period, by default 14. When the close is at the very top of the recent range the value is near 0; when it is at the very bottom the value is near −100. It is effectively the inverse of the Stochastic %K, shifted onto a negative scale.
Why Williams %R is used
Williams %R is used to study momentum and to spot when price is pressing against the top or bottom of its recent range. Traders traditionally treat readings above −20 as overbought and below −80 as oversold, and some watch for the oscillator failing to confirm new price extremes.
As with all such thresholds, these levels and the 14-period default are conventions that many adapt to context. Any interpretation is your own.
What are TradingView and Pine Script?
TradingView is one of the most widely used charting and market-analysis platforms, where traders and analysts study price movement across stocks, crypto, forex, and futures on interactive charts. Pine Script is TradingView's own lightweight programming language, created so anyone can build custom tools that run directly on those charts.
People use Pine Script to build four main kinds of tools. Indicators calculate and plot values on the chart, exactly like the calculation above, but recomputed automatically on every bar. Strategies add explicit entry and exit rules and can be backtested against historical data in TradingView's Strategy Tester to see how they would have behaved. Screeners scan many symbols at once for conditions you define. Alerts notify you the moment a condition you specified occurs, so you do not have to watch the screen.
The value is precision and automation. Instead of eyeballing a chart, you describe exactly what you want measured, visualized, or notified about, and TradingView runs it consistently across any market and timeframe. That is why traders, analysts, and developers write Pine Script: it turns a manual charting idea into a repeatable tool. These tools are for tracking, visualizing, and testing market ideas; they do not tell you what to trade, and that decision always remains yours.
Writing that code by hand means learning Pine Script's syntax, its type system, and the exact names of hundreds of built-in functions. It is a real programming language, and small mistakes stop a script from compiling in the Pine Editor.
Turn this into Pine Script
This calculator returns one Williams %R reading. On a chart it updates every bar within its pane alongside the overbought and oversold lines. Pine Script gives it to you as ta.wpr(14), but the guide lines, coloring, and any signal logic around it still need to be built.
//@version=6
indicator("Williams %R", overlay=false)
wpr = ta.wpr(14)
plot(wpr, "Williams %R", color=color.blue)
hline(-20, "Overbought")
hline(-80, "Oversold")PineScripter is an AI built specifically for Pine Script. You describe what you want in plain English and it writes TradingView-ready v5 or v6 code. Because it is specialized on the Pine Script language and its exact function signatures, it tends to produce code that compiles far more reliably than general-purpose models like ChatGPT, which often invent functions that do not exist in Pine Script.
PineScripter is an AI developer tool that helps you write Pine Script code. It is not a financial advisor and will never offer financial, investment, or trading advice. Everything on this page, including the calculator and the explanations, is provided purely for educational and informational purposes. Any decision about how to interpret an indicator or trade a market is entirely your own. See our full disclaimer for more.