Volatility · Price units · Wilder smoothing

Average True Range: calculate the distance before using it

ATR averages true range with a specified smoothing method. It describes the size of observed ranges, including gaps from the previous close. A rising line supplies no bullish or bearish direction, and a multiple of ATR supplies no guaranteed stop coverage.

True range includes the previous close

TradingView attributes ATR to J. Welles Wilder's 1978 book, New Concepts in Technical Trading Systems. Its ATR reference defines true range as the largest of three distances and uses RMA by default.

TR = max(high − low, |high − previous close|, |low − previous close|)

The following inputs are synthetic. They show why the candle body and even its high-low range can miss an interbar gap.

Previous closeHighLowHigh − LowTrue range
1001039944
100112110212
1009290210

The gap-up row has range 2 but true range 12. TR includes price levels separated by a gap; it does not say that orders could execute continuously through every intermediate price. On a first bar without a previous close, the displayed helper uses the high-low fallback supplied by ta.tr(true).

ATR is in price units. A forex value of 0.0020 becomes 20 pips only if that instrument's pip size is 0.0001. A futures value in index points needs the contract's value per point before it becomes a cash amount. Price units are not automatically dollars, ticks or pips.

Wilder smoothing has a decaying memory

ATR[t] = TR[t]/n + (1 − 1/n) × ATR[t−1]

After initialization, the new ATR rises when current TR exceeds the previous ATR. It falls when current TR is lower. A large candle body is unnecessary: a wide doji or a gap can produce a large TR. Conversely, a candle can be wider than the previous candle but still have TR below the previous ATR.

Pine's RMA uses an initial simple average before the recursive updates. For a synthetic initialized ATR of 2 and n = 14, a single TR of 16 changes ATR to (13 × 2 + 16)/14 = 3. If the next TR is 2, ATR becomes 41/14 ≈ 2.928571.

If all later true ranges remain 2, the excess above 2 after k additional bars is (13/14)^k. After fourteen additional bars, ATR is approximately 2.354335. About 35.43% of that shock's initial excess remains; it does not disappear at bar fourteen.

At n = 14, EMA puts weight 2/15 on the new value; RMA puts weight 1/14. SMA replaces the oldest value in a finite window. Comparing their responses requires specifying that outgoing value and the prior state; there is no universal ordering of every change. Changing to HMA or another filter also changes the definition. HMA can overshoot even with nonnegative inputs, while volume-weighted smoothing depends on usable volume.

On a monthly chart, length 14 refers to monthly bars, not 3.5 months. On a five-minute chart it is a smoothing parameter over five-minute observations, not a guarantee that only the latest seventy minutes affect RMA.

Pine Script: RMA ATR with a smoothing helper

This source plots a 14-period RMA of true range in a separate pane. The helper is declared before the wrapper that calls it. The other branches are alternate smoothers of true range; the fixed call below selects RMA. There are no input declarations or orders.

Pine Script v6
//@version=6
indicator(title="Average True Range", overlay=false, max_labels_count=500)

// Moving average type selector
p_ta_ma(series float source, simple int length, simple string ma_type) =>
    switch ma_type
        "SMA" => ta.sma(source, length)
        "EMA" => ta.ema(source, length)
        "RMA" => ta.rma(source, length)
        "HMA" => ta.hma(source, length)
        "WMA" => ta.wma(source, length)
        "TMA" => ta.sma(ta.sma(source, math.ceil(length / 2)), math.floor(length / 2) + 1)
        "VWMA" => ta.vwma(source, length)

// ATR calculation using True Range with configurable MA type
p_ta_atr(simple int length, simple string ma_type) =>
    p_ta_ma(ta.tr(true), length, ma_type)

// 14-period RMA-based ATR (Wilder's original smoothing)
p_ind_1 = p_ta_atr(14, "RMA")

plot(p_ind_1, "ATR", color=color.new(#B71C1C, 0), linewidth=1)

Open the Pine Editor from the Pine icon on TradingView's right toolbar, paste the complete source and select Add to chart. Compare the result with the built-in ATR using the same length, RMA smoothing, symbol, session, chart type and available history. The current bar can change before close; compare completed bars for arithmetic checks.

Average True Range plotted in a separate chart pane

Color and line width do not change the calculation. The preview is an illustration of the display, not a backtest or evidence for a stop multiplier.

A stop-distance budget is not a maximum loss

Take an illustrative account of $50,000 and a chosen budget of $500. These are example assumptions, not a recommended risk percentage. Suppose entry is $100, the completed-bar ATR is $2.50 and the chosen distance is 2 × ATR = $5.

Initial stop reference = 100 − 5 = 95
Shares before costs and other constraints = floor(500/5) = 100

A fill at $95 produces a $500 loss on 100 shares before costs. If price gaps and the exit fills at $92, the same position loses $800 before costs. A stop-limit order can instead remain unfilled. The SEC investor bulletin on stop orders explains these execution differences.

For a linear contract, translate the distance using value per point and the account currency, then round down to a permitted quantity. Add fees, spread, slippage assumptions, buying-power constraints and aggregate exposure checks. Inverse or nonlinear contracts need their own payoff calculation. If ATR is zero or unavailable, this sizing formula cannot supply a usable position.

If ATR doubles while the multiplier, budget and unit value stay fixed, the unrounded quantity halves. That describes the next sizing calculation. It does not automatically resize an existing trade or preserve its realized risk.

Define the stop update and signal timing separately

Initial stop versus ratcheting stop

An entry-minus-ATR multiple is an initial price reference. A rolling highest high minus an ATR multiple can move down when the high expires or ATR rises. A long stop that must never move down needs persistent state: at each eligible update, retain the greater of the previous active stop and the new candidate, initialized for each trade.

Illustrative candidate sequence: 110 − 3 × 2 = 104; next, 111 − 3 × 3 = 102. A ratcheting long stop stays at 104. Later, 114 − 3 × 2 = 108 raises it to 108. Taking only the maximum of the current and previous raw candidates is insufficient over a longer sequence. A strategy must also say when the update becomes an active order.

Breakouts and low-volatility experiments

A close cannot exceed the highest high of a window that includes that same candle. To test a close above the previous twenty-bar range, determine that range from completed bars before the signal bar. Likewise, a value cannot be strictly below a rolling minimum that includes itself; use a previous-window comparison or define a new-low equality rule.

A low ATR observation does not establish how soon volatility will expand or in which direction. If testing a squeeze followed by a breakout, record the squeeze first, then the later breakout, the range definition, expiry of the setup and executable entry timing. Specify exits and costs before comparing results on a held-out sample.

The ATR plot implements none of those trading rules. A percentage win rate assigned to position sizing alone would be meaningless without an entry and exit system.

ATR, standard deviation and normalized comparisons

ATR measures smoothed true range. Standard deviation of closing prices measures dispersion of closes around their mean. Both have price units. Bollinger Bands built from that standard deviation also lie on the price scale; they are not inherently normalized just because they surround an average.

Consider bars whose close always equals 100 but whose high and low are 110 and 90. Their closing-price standard deviation is zero, while true range is 20. After initialization, constant-range ATR is 20. Conversely, a lasting gap that changes subsequent closes can affect closing-price standard deviation too; it is incorrect to say it never responds to gaps.

For positive close, ATR% = 100 × ATR / close supplies one relative measure: ATR 5 on price 100 is 5%; on price 500 it is 1%. A zero or near-zero denominator needs handling. A return standard deviation, normalized band width and ATR% are different metrics, not interchangeable labels for volatility.

ATR questions

ATR smooths true range, including the distance from the previous close to the current high or low. It measures range in the instrument price units, not direction, standard deviation, a guaranteed future range or a maximum loss.

Fourteen is the displayed Wilder-style example and a common default, not an optimal setting established here. Length counts chart bars. RMA retains a decaying contribution from earlier history, so length 14 is not a hard cutoff after fourteen observations.

Not necessarily. A doji can have a wide high-low range or follow a gap. For an initialized Wilder ATR, the value rises exactly when the current true range exceeds the previous ATR, and falls when it is smaller. Candle body size alone does not decide this.

Their new-observation weights differ. At length 14, RMA uses 1/14 while EMA uses 2/15. RMA gives the new observation less weight. SMA uses a finite equally weighted window, so its next change also depends on the observation leaving that window.

Only in a simplified calculation that assumes the specified fill prices and costs. Gap fills, slippage, fees, contract multipliers and currency conversion can change the loss. ATR supplies a distance; an order and an execution model are separate requirements.

No. The displayed call fixes length 14 and RMA smoothing. The helper contains other MA branches, but choosing one requires a source edit. The script plots a line and contains no strategy orders, stops or custom alert conditions.

Specify an ATR adaptation in Pineify

Ask for a positive length input, an explicit smoothing choice and completed-bar values for any signal. If requesting a strategy, specify the entry, initial stop, ratchet state, reset rule and costs separately. Inspect and compile the returned source, then compare its values and order timing. Account access and usage depend on the current plan.

Explore the coding agent