Docs

ta.percentrank

Rank the current value against its recent history on a 0 to 100 scale.

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

Percent rank in [0, 100]: 100 * (how many of the previous length observations are less than or equal to the current one) / length. The current bar is ranked against its history and is not counted in its own window. Ties count as "at or below", so a flat series ranks 100.

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 + 1 bars. Names in the warm-up are this operator’s parameters.
Missing values
Returns na until length + 1 consecutive non-na observations have been seen (the current one plus the length it is ranked against). An na resets the accumulation. With min=, an na is skipped and the rank is taken against the valid observations among the length before the bar, once there are at least min of them. A bar whose own value is na has no rank.

Example

itm
ta.percentrank(close, 20)
itm
plot(ta.percentrank(close, 100), "Rank 100")