Williams %R
Where the close sits below the highest high of the last N bars, as a range from 0 down to −100.
It is the stochastic inverted and unsmoothed. Readings: above −20 called overbought, below −80 oversold, and the fact that it pins at 0 or −100 whenever the close is the window's extreme. MT5 and TA-Lib compute it identically.
01The study, live
Computed by Bentrix’s own code over the same synthetic bars on every page — an illustration of how the study behaves, not a market.
What this figure shows
The figure is computed over 300 sample bars. Williams %R has no value on the first 13 — the bars it needs before it can answer — and its first value stands on bar 14. Its line runs between -99.96 and -0.2031 on these bars, and the last value is -33.49. The pane's scale is fixed at -100 to 0, the range the study can take. Counting the conditions the study declares on these bars: crosses above -80 18 times; crosses below -80 18 times; crosses above -20 15 times; crosses below -20 16 times. Press a condition under the figure to see each place marked. As states rather than moments: is above -80 on 192 bars; is below -80 on 95 bars; is above -20 on 88 bars; is below -20 on 199 bars.
02Its parts, named
03What you see
A line between 0 and −100, with reference lines at −20 and −80: where the close sits relative to the highest high of the last bars.
04Where it comes from
Larry Williams introduced %R in the 1960s and describes it in his books on short-term trading. It is the fast Stochastic's %K turned upside down.
05The formula
%R = −100 · (max (H_N) − Cₜ)/(max (H_N) − min (L_N))
06A worked example
The sample bars used here are eight: closes 20, 21, 23, 22, 24, 25, 24, 26; highs 21, 22, 24, 24, 25, 26, 26, 27; lows 18, 19, 20, 21, 21, 23, 23, 23; opens 19, 20, 21, 23, 22, 24, 25, 24.
Take a period of 5. Over the last five bars the highest high is 27 and the lowest low 21; the close is 26.
%R = (27 − 26) / (27 − 21) × −100 = -16.67
The close is 16.7 % of the range below the top. The fast stochastic on the same bars reads 83.33: the two always add up to 100 in size, because one measures from the bottom of the range and the other from the top.
07Built in Assay
The same study written in Assay, Bentrix’s script language, and drawn by Bentrix itself as the script’s graph: each block is one step of the formula. On the ladder the steps stand in the script’s order, one a row; on the board each wire carries a value from the block that gives it to the block that reads it, left to right. The script computes exactly what the study computes — Bentrix checks the two against each other, candle by candle.
//@version=6 indicator("Williams' Percent Range") length = input.int(14, "Length") highest = ta.highest(high, length) lowest = ta.lowest(low, length) // How far the close is below the window's high, as a percentage of its range: 0 at the high, -100 at the low. var float wpr = na if not na(highest) wpr := highest != lowest ? -(highest - close) * 100 / (highest - lowest) : nz(wpr, 0.0) plot(wpr, "%R") hline(-20) hline(-80)
Paste it into the Assay IDE to put it on a chart, or to change it. Looking at the graph is free in every package; editing it as blocks is Plus.
08Readings — what traders look for
Above −20 is read as the close near the top of the recent range; below −80, near the bottom.
A move out of an extreme zone is read as the close having left the edge of the range.
How the −20 and −80 readings fail. A close near the top of the range (above −20) is what every bar of a steady rise looks like. In a strong trend the line stays at one end of its scale for a long time; a high reading there describes the trend and does not mark its end.
Failure to reach the edge. Williams watched for the line failing to return to an edge it had been reaching — read as the closes no longer pressing against the range. It fails when the range itself has widened: one wide bar stretches the window and pushes every later close away from the edge.
09In different markets and timeframes
Williams %R is the fast stochastic on an inverted scale and behaves like it: a range instrument that pins near 0 in advances and near −100 in declines. Williams read it on daily bars with a 10 to 14-bar window.
10With other studies
Read beside the Stochastic Oscillator only to see that they agree; usefully, beside a trend filter and beside price for its failure swings.
11What it does not tell you
As with the Stochastic, a close near the top of its range is common in a rise and says nothing about the next bar.
12Inputs and defaults
- 1Period — 14The number of bars the study looks back over. Longer: a calmer line that reaches its extremes less often. Shorter: a jumpy line that reaches them constantly.
- 2Timeframe — ChartThe chart's own by default; any higher one, read on the last closed candle. A finer one is never offered.
- 3Wait for the candle to close — OnThe value of a higher timeframe is taken only from a candle that has finished.
The settings in use
- In use14 by default; 10 is Williams' own; 20 to 28 for a slower line.
13Limits and common misreadings
One wide bar changes every reading for as long as it stays in the window.
The scale is upside down compared with most oscillators: 0 is the top, −100 the bottom.
14Conditions an alert or a strategy can watch
an event happens on one bar a state holds on every bar while it lasts
These are the conditions the study itself declares — the same rules the alert editor and the strategy engine read, and the ones the figure's chips show.
15Practise it in the laboratory
Put Williams %R 14 and the fast Stochastic %K 14 in two panes and check that they are mirror images; then replay a steady trend and note how long %R stays above −20.
Open the laboratory17In Bentrix
- From the menu: a chart's Indicators button › Oscillators › Williams %R, or type Williams %R in its search.
- Its settings: the settings card opens when it is added; its legend's name opens it again.
18From an agent or a program
Two tools reach it. study_values computes it over a workbench’s candles up to the clock — no chart needed — and study_attach puts it on a chart, where it is drawn and saved with the chart ({"chart": "<chart uri>", "kind": "wpr"}).
The study, as a chart files it
This is a new Williams %R’s entry — its kind, its calculation, the price it reads and its settings. Change a setting here to read it with other inputs.
{
"applied": "close",
"convention": "mt5",
"kind": "wpr",
"settings": {
"period": 14,
"shape": "period"
}
}An agent
An agent calls the MCP tool with it:
{
"name": "study_values",
"arguments": {
"bench": "bentrix://lab/\u2026/bench/\u2026",
"symbol": "EURUSD",
"timeframe": "H1",
"limit": 5,
"study": {
"applied": "close",
"convention": "mt5",
"kind": "wpr",
"settings": {
"period": 14,
"shape": "period"
}
}
}
}A program
A program does the same in its language — bench and market as in the built-in indicators guide:
Python
values = client.study.values(bench, market, "H1", {"applied": "close", "convention": "mt5", "kind": "wpr", "settings": {"period": 14, "shape": "period"}}, limit=5)
print("times:", values["times"])
for line in values["lines"]:
print("line:", line["line"])
print(" newest values:", line["values"])JavaScript
const values = await client.study.values({ bench, symbol: market, timeframe: "H1", study: { "applied": "close", "convention": "mt5", "kind": "wpr", "settings": { "period": 14, "shape": "period" } }, limit: 5 });
console.log("times:", values.times);
for (const line of values.lines) {
console.log("line:", line.line);
console.log(" newest values:", line.values);
}C#
var values = await client.Study.Values(bench, market, "H1", new Dictionary<string, object?> { ["applied"] = "close", ["convention"] = "mt5", ["kind"] = "wpr", ["settings"] = new Dictionary<string, object?> { ["period"] = 14, ["shape"] = "period" } }, limit: 5);
Console.WriteLine($"times: {values!["times"]!}");
foreach (var line in values!["lines"]!.AsArray())
{
Console.WriteLine($"line: {line!["line"]!}");
Console.WriteLine($" newest values: {line!["values"]!}");
}Go
values := must(client.Study.Values(ctx, mcp.StudyValuesArgs{Bench: bench, Symbol: market, Timeframe: "H1", Study: map[string]any{"applied": "close", "convention": "mt5", "kind": "wpr", "settings": map[string]any{"period": 14, "shape": "period"}}, Limit: mcp.Ptr[int64](5)}))
fmt.Println("times:", at(values, "times"))
for _, line := range at(values, "lines").([]any) {
fmt.Println("line:", at(line, "line"))
fmt.Println(" newest values:", at(line, "values"))
}Java
Object values = client.study.values(new Bentrix.StudyApi.ValuesArgs(bench, market, "H1", obj("applied", "close", "convention", "mt5", "kind", "wpr", "settings", obj("period", 14, "shape", "period"))).limit(5L));
System.out.println("times:" + " " + at(values, "times"));
for (Object line : (List<Object>) at(values, "lines")) {
System.out.println("line:" + " " + at(line, "line"));
System.out.println(" newest values:" + " " + at(line, "values"));
}C++
auto values = client.study.values_(StudyApi::ValuesArgs(bench, market, "H1", Json::Object{{"applied", "close"}, {"convention", "mt5"}, {"kind", "wpr"}, {"settings", Json::Object{{"period", 14}, {"shape", "period"}}}}).limit(5));
std::cout << "times:" << " " << values["times"].dump() << std::endl;
for (const Json &line : values["lines"].arr()) {
std::cout << "line:" << " " << line["line"].dump() << std::endl;
std::cout << " newest values:" << " " << line["values"].dump() << std::endl;
}Julia
values = client.study.values(bench, market, "H1", Dict{String,Any}("applied" => "close", "convention" => "mt5", "kind" => "wpr", "settings" => Dict{String,Any}("period" => 14, "shape" => "period")); limit = 5)
println("times:", " ", values["times"])
for line in values["lines"]
println("line:", " ", line["line"])
println(" newest values:", " ", line["values"])
endR
values <- client$study$values(bench, market, "H1", list(applied = "close", convention = "mt5", kind = "wpr", settings = list(period = 14, shape = "period")), limit = 5)
cat("times:", format(values$times), "\n")
for (line in values$lines) {
cat("line:", format(line$line), "\n")
cat(" newest values:", format(line$values), "\n")
}Rust
let values = client.study().values(mcp::StudyValuesArgs::new(bench.clone(), market.clone(), "H1", serde_json::json!({"applied": "close", "convention": "mt5", "kind": "wpr", "settings": {"period": 14, "shape": "period"}})).limit(5))?;
println!("times: {}", values["times"]);
for line in values["lines"].as_array().into_iter().flatten() {
println!("line: {}", line["line"]);
println!(" newest values: {}", line["values"]);
}Reading the answer
times— the candles’ open times, in milliseconds since 1970 (UTC), oldest first.lines— one entry per line, in this order, each with itslinename and itsvalues;values[i]belongs to the candle attimes[i].- The last value is the candle at the clock’s, which may still be forming: it changes until that candle closes, as on the chart. Nothing after the clock is ever computed.
nullis a candle with no value yet — the warm-up, about 1 × the period at the start of the history.- Its fixed levels, drawn on the chart:
[-80.0, -20.0].
line | What it is |
|---|---|
Main | the indicator's own value |
In a strategy
Filed under a key of your choice in a strategy document’s studies — here wpr: {"wpr": {"applied": "close", "convention": "mt5", "kind": "wpr", "settings": {"period": 14, "shape": "period"}}} — its rules can name:
| Write | What it is |
|---|---|
wpr | its main line, as a value in a compare |
{"cond": "wpr:level.cross_up:-80"} | a condition it declares itself |
{"cond": "wpr:level.cross_down:-80"} | a condition it declares itself |
{"cond": "wpr:level.above:-80"} | a condition it declares itself |
{"cond": "wpr:level.below:-80"} | a condition it declares itself |
{"cond": "wpr:level.cross_up:-20"} | a condition it declares itself |
{"cond": "wpr:level.cross_down:-20"} | a condition it declares itself |
{"cond": "wpr:level.above:-20"} | a condition it declares itself |
{"cond": "wpr:level.below:-20"} | a condition it declares itself |
19Sources
- Williams, Larry. Long-Term Secrets to Short-Term Trading. Wiley, 1999.
Bentrix 0.1.382Every number, name and default on these pages is read from the application itself.What is comingWhat changed