Sidechair

ta.atr()

Browse the reference

Returns the average true range: the running average of each bar's true range, a measure of how far price typically moves per bar.

Try it in the editor

ta.atr smooths the true range with ta.rma over length bars. True range on each bar is the largest of high - low, the distance from the previous close to the high, and the distance from the previous close to the low.

The first bar has no previous close, so its true range is high - low. The first ATR value appears on bar number length, then updates recursively.

Syntax

Pine Script
ta.atr(length: simple int) -> series float

Arguments

NameTypeDefaultDescription
lengthsimple intrequiredSmoothing length of the running average. A whole number of 1 or more.

Returns

series float: the average true range in price units, or na for the first length - 1 bars.

Remarks

  • ATR is in price units, so values are not comparable between symbols. Divide by close to compare volatility as a percentage.
  • ta.atr(1) equals the true range with the first bar included.

Example

Pine ScriptATR stop distanceOpen in editor
//@version=6
indicator("ATR bands", overlay = true)
len = input.int(14, "ATR length", minval = 1)
mult = input.float(2.0, "Multiplier", minval = 0.1, step = 0.1)
range_ = ta.atr(len) * mult
plot(close + range_, "Upper", color = color.red)
plot(close - range_, "Lower", color = color.green)

See also

Runs on Sidechair