ta.tr()True Range (Function)
True Range function with an explicit missing-previous-close policy. Calculates the true range of the current bar.
Syntax
ta.tr(handle_na) → series floatArguments
| Parameter | Type | Description |
|---|---|---|
| handle_na | simple bool | Required simple bool. If the previous close is na, true uses current high - low and false returns na. With a valid previous close, both use the true-range formula. |
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
Measure range beyond the previous close; TR alone does not identify gap direction
Use as input for custom volatility indicators
Frequently Asked Questions
Generate ta.tr() Code with AI
Draft Pine Script using ta.tr() with Pineify's AI Coding Agent, then review the arguments and test the result on your chart. Usage depends on your plan and available credits.
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() - Wilder 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.