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

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.