Returns the share of the other items that are at or below the item at a given index, as a percentage.
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
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 intArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | array<int/ | required | The numeric array that holds the item to rank and the items it is ranked against. |
| index | series int | required | Position 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
//@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