ta.tr() - Pine Script Function
ta.tr()
Section titled “ta.tr()”Overview
Section titled “Overview”Calculates the current bar’s true range. Unlike a bar’s actual range (high - low), true range accounts for potential gaps by taking the maximum of the current bar’s actual range and the absolute distances from the previous bar’s close to the current bar’s high and low. The formula is: math.max(high - low, math.abs(high - close[1]), math.abs(low - close[1])).
Syntax
Section titled “Syntax”ta.tr(handle_na) → series floatParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| handle_na | simple bool | Defines how the function calculates the result when the previous bar’s close is na. If true |
| the | — | function returns the bar’s high - low value. If false |
| it | — | returns na. |
Returns
Section titled “Returns”True range. It is math.max(high - low, math.abs(high - close[1]), math.abs(low - close[1])).
Remarks
Section titled “Remarks”- ta.tr(false) is exactly the same as ta.tr.