Docs

ta.rank

Rank the current value among the last n values, with 1 as the lowest.

itm
ta.rank(source, length, min=length)

Rank of the current observation among the last length observations including itself, counted ascending from 1: 1 is the lowest in the window and length the highest. Ties count as at-or-below, so a flat window ranks length. This is not ta.percentrank, which excludes the current bar from its own window and divides by length to give a percentage.

Parameters

A series parameter takes a value on every bar. A constant parameter must be known before the first bar, such as a number or an input.

NameKindTypeDefaultRangeDescription
sourceSeriesnumber--The series to read.
lengthConstantnumber-1 to 10000Window in observed bars.
minConstantnumber-1 to 10000Valid values the window must hold before it reports (an option, written min=15). An na is skipped. Absent = length: the window must be full and gap-free.

Output

NameType
valuenumber

Warm-up and missing values

Warm-up
length bars. Names in the warm-up are this operator’s parameters.
Missing values
Returns na until length consecutive non-na observations are in the window. An na resets the accumulation. With min=, an na is skipped and the rank is taken among the valid observations once there are at least min of them. A bar whose own value is na has no rank.

Example

itm
ta.rank(close, 20)
itm
plot(ta.rank(close, 20), "Rank 20")