VolatilityPine Script v6

ta.atr()

Average True Range

Function atr (average true range) returns the RMA of true range. True range is max(high - low, abs(high - close[1]), abs(low - close[1])).

Syntax

Syntax
ta.atr(length) → series float

Arguments

ParameterTypeDescription
lengthsimple intLength (number of bars back).

Returns

Average true range.

Remarks

na values in the source series are ignored; the function calculates on the length quantity of non-na values.

Code Examples

Pine Script v6 Example
//@version=6
indicator("ta.atr")
plot(ta.atr(14))

//the same on pine
pine_atr(length) =>
    trueRange = na(high[1])? high-low : math.max(math.max(high - low, math.abs(high - close[1])), math.abs(low - close[1]))
    //true range can be also calculated with ta.tr(true)
    ta.rma(trueRange, length)

plot(pine_atr(14))

Trading Applications

Set dynamic stop-loss levels based on market volatility

Calculate position sizes adjusted for current volatility

Identify volatility expansion and contraction phases

Use as a trailing stop distance multiplier

Related Functions

Frequently Asked Questions

Generate ta.atr() Code with AI

Skip the manual coding. Use Pineify's AI Coding Agent to generate Pine Script code using ta.atr() and other built-in functions instantly.