Returns the value at a given percentage of the sorted numbers, interpolating between neighbouring items.
The numbers are sorted and the position is percentage / 100 x (count - 1). When that lands between two items, the answer is blended in proportion, so 50 on an even count gives the mean of the two middle values.
Percentages below 0 or above 100 are clamped. Items that are na are skipped, and with nothing left the result is na.
Syntax
array.percentile_linear_interpolation(id: array<int/float>, percentage: series int/float) -> series float
array.percentile_linear_interpolation(id: array<int>, percentage: series int/float) -> series int
array.percentile_linear_interpolation(percentage: series int/float) -> series float
array.percentile_linear_interpolation(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 interpolated value at that percentage.
Example
//@version=6
indicator("array.percentile_linear_interpolation: quartiles", overlay = true)
var win = array.new_float()
array.push(win, close)
if array.size(win) > 40
array.shift(win)
plot(array.percentile_linear_interpolation(win, 25), "25th", color.red)
plot(array.percentile_linear_interpolation(win, 75), "75th", color.green)See also
Runs on Sidechair