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
ta.atr(length) → series floatArguments
| Parameter | Type | Description |
|---|---|---|
| length | simple int | Length (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
//@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
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.
Related Pine Script Functions
ta.tr - True Range Variable
Learn about ta.tr built-in variable in Pine Script. Quick access to True Range without function call parameters.
ta.tr() - True Range Function
Learn how to use ta.tr() function in Pine Script. Syntax, parameters including handle_na, code examples for True Range.
ta.bb() - Bollinger Bands
Learn how to use ta.bb() in Pine Script. Syntax, parameters, code examples for Bollinger Bands with upper, middle, and lower bands.
ta.kc() - Keltner Channels
Learn how to use ta.kc() in Pine Script. Syntax, parameters, code examples for Keltner Channel volatility bands.
ta.supertrend() - Supertrend
Learn how to use ta.supertrend() in Pine Script. Syntax, parameters, code examples for the ATR-based trend overlay.