Sidechair

array.percentrank()

Browse the reference

Returns the share of the other items that are at or below the item at a given index, as a percentage.

Try it in the editor

A result of 100 means the item sits at or above every other item; 0 means every other item is higher. The item at the index is not counted against itself.

A single-item array, an item that is na, or non-numeric data returns na. The index can be negative to count back from the end.

Syntax

Pine Script
array.percentrank(id: array<int/float>, index: series int) -> series float
array.percentrank(id: array<int>, index: series int) -> series int
array.percentrank(index: series int) -> series float
array.percentrank(index: series int) -> series int

Arguments

NameTypeDefaultDescription
idarray<int/float> or array<int>requiredThe numeric array that holds the item to rank and the items it is ranked against.
indexseries intrequiredPosition of the item. Counts from 0; a negative index counts back from the end, so -1 is the last item.

Returns

series float or series int: A percentage from 0 to 100.

Example

Pine ScriptWhere today's close ranksOpen in editor
//@version=6
indicator("array.percentrank: close rank", overlay = false)
var win = array.new_float()
array.push(win, close)
if array.size(win) > 50
    array.shift(win)
plot(array.percentrank(win, -1), "Percent rank of latest close")
hline(50)

See also

Runs on Sidechair