Returns the value at a given percentage of the sorted numbers, always one of the items in the array.
The numbers are ranked from smallest to largest and the item at position ceil(percentage / 100 x count) is returned. The 50th percentile of five numbers is the third, and 100 returns the largest.
A percentage outside 0 to 100 is clamped to that range. na items are skipped, and an empty set returns na.
Syntax
array.percentile_nearest_rank(id: array<int/float>, percentage: series int/float) -> series float
array.percentile_nearest_rank(id: array<int>, percentage: series int/float) -> series int
array.percentile_nearest_rank(percentage: series int/float) -> series float
array.percentile_nearest_rank(percentage: series int/float) -> series intArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | array<int/ | required | The numeric array to rank. na items are skipped. |
| percentage | series int/ | required | A percentage from 0 to 100. |
Returns
series float or series int: The item found at that rank.
Remarks
- For a smoother answer that can fall between two items, use
array.percentile_linear_interpolation().
Example
//@version=6
indicator("array.percentile_nearest_rank: busy level", overlay = false)
var vol = array.new_float()
array.push(vol, volume)
if array.size(vol) > 50
array.shift(vol)
plot(volume, "Volume", style = plot.style_columns)
plot(array.percentile_nearest_rank(vol, 90), "90th percentile", color.red)See also
Runs on Sidechair