VolatilityPine Script v6

ta.tr()True Range (Function)

True Range function with optional NaN handling. Calculates the true range of the current bar.

Syntax

Syntax
ta.tr(handle_na) → series float

Arguments

ParameterTypeDescription
handle_nasimple boolHow 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

Pine Script v6 Example
//@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

Related Functions

Frequently Asked Questions

ta.tr() is the function that returns true range for the current bar: the greatest of the bar range and the two gaps versus the previous close. It can optionally treat missing prior close differently via handle_na.

When handle_na is true and the previous close is na, true range falls back to high − low. When handle_na is false, the result is na in that situation instead of substituting the bar range.

Pine exposes true range both as a series value and via the ta.tr() function with explicit na-handling. Use the function when you need to control behavior when the prior close is missing; consult current Pine documentation for exact equivalence on your version.

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.