VolatilityPine Script v6

ta.tr()True Range (Function)

True Range function with an explicit missing-previous-close policy. Calculates the true range of the current bar.

TradingView language reference

Syntax

Syntax
ta.tr(handle_na) → series float

Arguments

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

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

Measure range beyond the previous close; TR alone does not identify gap direction

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. Pass the required handle_na argument to choose how to treat a missing prior close.

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; in v6, the variable is equivalent to ta.tr(false). This does not imply a no-argument function call is valid.

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.