Returns the average true range: the running average of each bar's true range, a measure of how far price typically moves per bar.
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
ta.atr(length: simple int) -> series floatArguments
| Name | Type | Default | Description |
|---|---|---|---|
| length | simple int | required | Smoothing 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
//@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