Sidechair

ta.range()

Browse the reference

Returns the difference between the highest and lowest value of source over the last length bars.

Try it in the editor

ta.range is ta.highest(source, length) - ta.lowest(source, length). It measures the spread of a series over a rolling window, in the units of source.

The first value appears on bar number length, and an na in the window gives na.

Syntax

Pine Script
ta.range(source: series int/float, length: series int) -> series float
ta.range(source: series int, length: series int) -> series int

Arguments

NameTypeDefaultDescription
sourceseries int/float or series intrequiredThe series whose highest and lowest values over length bars are subtracted.
lengthseries intrequiredNumber of bars in the window. A whole number of 1 or more.

Returns

series float or series int: highest minus lowest value in the window.

Remarks

  • ta.range(close, n) uses closes only; use ta.highest(high, n) - ta.lowest(low, n) for the full price range.

Example

Pine ScriptRolling close rangeOpen in editor
//@version=6
indicator("Rolling range")
plot(ta.range(close, 20), "20-bar close range", color = color.purple)

See also

Runs on Sidechair