ta.tr()
True Range (Function)
True Range function with optional NaN handling. Calculates the true range of the current bar.
Syntax
ta.tr(handle_na) → series floatArguments
| Parameter | Type | Description |
|---|---|---|
| handle_na | simple bool | How NaN values are handled. If true, and previous close is NaN then tr would be calculated as current high-low. Otherwise, NaN is returned. Default false. |
Returns
True range. It is math.max(high - low, math.abs(high - close[1]), math.abs(low - close[1])).
Remarks
This is the function form ta.tr(). Distinguish from the built-in series variable ta.tr when reading documentation and legacy scripts.
Code Examples
//@version=6
indicator("ta.tr")
plot(ta.tr(false))
plot(ta.tr(true))Trading Applications
Calculate true range for ATR computation
Measure single-bar volatility
Detect gap-up or gap-down bars
Use as input for custom volatility indicators
Frequently Asked Questions
Generate ta.tr() Code with AI
Skip the manual coding. Use Pineify's AI Coding Agent to generate Pine Script code using ta.tr() 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.atr() - Average True Range
Learn how to use ta.atr() in Pine Script. Syntax, parameters, code examples for the Average True Range volatility indicator.
ta.rma() - Relative Moving Average
Learn how to use ta.rma() in Pine Script. Syntax, parameters, code examples for Wilder's smoothing method used in RSI calculation.
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.