Average True Range ATR
Average True Range, Wilder's — the average of true range, where true range is the bar's own range or its gap from the previous close, whichever is larger.
It measures typical bar movement in price units, with no direction in it at all. Read as a volatility yardstick — stop distances and position sizes are the usual uses — and remember it is in price units, so it is not comparable between instruments without scaling. The conventions differ more here than for any other indicator: MT5 averages true range with a SIMPLE moving average, TA-Lib with Wilder's smoothing, so the two can differ noticeably on a volatile market. Both are correct implementations of different definitions.
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. ATR has no value on the first 14 — the bars it needs before it can answer — and its first value stands on bar 15. Its line runs between 0.00066 and 0.0013 on these bars, and the last value is 0.001. Counting the conditions the study declares on these bars: turns up 75 times; turns down 75 times. Press a condition under the figure to see each place marked. As states rather than moments: is rising on 132 bars; is falling on 153 bars.
02Its parts, named
03What you see
A line in its own pane, in price units: how far price typically travels in one bar, averaged over the last bars (14). It rises when bars get bigger and falls when they shrink — whatever their direction.
04Where it comes from
J. Welles Wilder introduced the true range and its average in his 1978 book, for commodities that often opened with a gap. A bar's high minus its low misses a gap from the previous close; the true range includes it.
05The formula
TRₜ = max (Hₜ − Lₜ, | Hₜ − C_(t−1) |, | Lₜ − C_(t−1) |)
ATRₜ = ((N−1) ATR_(t−1) + TRₜ)/N
Wilder's smoothing (TA-Lib's default). MetaTrader 5's ATR is a simple average of the true range instead; the two differ, most at the start. See Calculation convention.
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.
The true range of a bar is the largest of three distances: its high to its low, its high to the previous close, its low to the previous close. For bars 2 to 5 that gives 3, 4, 3, 4.
With a period of 3 the first ATR is the plain average of the first three: (3 + 4 + 3) / 3 = 3.33. After that Wilder's smoothing keeps two thirds and adds a third of the new true range:
ATR = (2 × 3.33 + 4) / 3 = 3.56
It is in price units: on this market a typical bar, gaps included, has lately covered about 3.6 points.
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("Average True Range") length = input.int(14, "Length") // The true range: the bar's own range, or the gap from the last close when that is larger. trueRange = math.max(high - low, math.abs(high - close[1]), math.abs(low - close[1])) atr = ta.rma(trueRange, length) plot(atr, "ATR")
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
Sizing stops. Traders set stops at a multiple of the ATR — 1.5 or 2 ATR from the entry — so the stop's distance follows the market's ordinary movement. Read the ATR's value from its legend and enter that distance in the trade panel in points or price.
Sizing positions. Dividing the risk per trade by the stop's distance in money makes positions smaller in wild markets and larger in calm ones.
Rising ATR is read as bars getting larger — often around a breakout or in a fall; falling ATR as a calmer market.
How a rising ATR fails. It says bars are getting larger. It does so at the start of a trend, at a panic low, and in a violent sideways market alike — the line has no direction in it.
ATR as a unit of distance. Many traders measure stops and targets in ATRs so that the same rule adapts to a quiet and a wild market. It fails when volatility changes faster than the smoothing: after a sudden shock the ATR is still small for several bars.
09In different markets and timeframes
The ATR has no direction and is used on every timeframe as the market's own unit of distance. It rises in trends and in panics alike and lags a sudden change of volatility by its smoothing. On Renko charts the box size is itself often an ATR.
10With other studies
It is a building block: Keltner Channels, SuperTrend, the Chande Kroll Stop and chandelier-type stops are all an ATR multiple from something. Read beside NATR when markets are compared.
11What it does not tell you
The ATR has no direction: a rally and a collapse can have the same ATR. It describes how big recent bars were, not how big the next one will be.
12Inputs and defaults
- 1Period — 14The N of Wilder's smoothing. Short (5 to 7): the line jumps with each wide bar. Long (20 and more): it describes the market's general state and barely notices one bar.
- 2Average — The study's ownThe kind of moving average inside the study. Left at the study's own, it is the one the study's calculation uses by itself.
- 3Timeframe — ChartThe chart's own by default; any higher one, read on the last closed candle. A finer one is never offered.
- 4Calculation — TA-LibOr MT5, which computes it as MetaTrader 5 does — see the calculation convention below.
- 5Wait for the candle to close — OnThe value of a higher timeframe is taken only from a candle that has finished.
What each input changes
- AverageThe kind of average taken of the true range. Left at the study's own it is the one the chosen calculation uses; a simple average forgets an unusually wide bar the moment it leaves the window, where Wilder's smoothing lets it fade.
- In use14 is Wilder's; 5 to 10 for a quick reading; 20 to 50 for the market's general state. Multiples of 1.5 to 3 ATR are common for stop distances.
13Calculation convention
This is one of the studies whose result differs between the two conventions Bentrix offers. The difference is in how the first values are seeded and how the series is smoothed, so the two agree after the warm-up and differ at its start. Choose it on the settings card's Calculation row.
defaultTA-Lib
The convention of the TA-Lib library, which most charting software follows.
MT5
Computed as MetaTrader 5 computes it, so a value matches the terminal's own.
14Limits and common misreadings
The ATR is in price units, so it cannot be compared between markets or across years of very different prices — the NATR divides it by the close.
15Conditions 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.
16Practise it in the laboratory
Read the ATR on a quiet day and on a busy day of the same market, set a stop at twice it in the trade panel with the size mode on Risk %, and compare the sizes the panel gives.
Open the laboratory18On pages of their own
19In Bentrix
- From the menu: a chart's Indicators button › Volatility › ATR, or type ATR in its search.
- Its settings: the settings card opens when it is added; its legend's name opens it again.
20From 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": "atr"}).
The study, as a chart files it
This is a new ATR’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": "talib",
"kind": "atr",
"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": "talib",
"kind": "atr",
"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": "talib", "kind": "atr", "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": "talib", "kind": "atr", "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"] = "talib", ["kind"] = "atr", ["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": "talib", "kind": "atr", "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", "talib", "kind", "atr", "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", "talib"}, {"kind", "atr"}, {"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" => "talib", "kind" => "atr", "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 = "talib", kind = "atr", 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": "talib", "kind": "atr", "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.
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 atr: {"atr": {"applied": "close", "convention": "talib", "kind": "atr", "settings": {"period": 14, "shape": "period"}}} — its rules can name:
| Write | What it is |
|---|---|
atr | its main line, as a value in a compare |
{"cond": "atr:line.turns_up"} | a condition it declares itself |
{"cond": "atr:line.turns_down"} | a condition it declares itself |
{"cond": "atr:line.rising"} | a condition it declares itself |
{"cond": "atr:line.falling"} | a condition it declares itself |
21Sources
- Wilder, J. Welles Jr. New Concepts in Technical Trading Systems. Trend Research, 1978.
Bentrix 0.1.382Every number, name and default on these pages is read from the application itself.What is comingWhat changed