Sidechair

array.percentile_linear_interpolation()

Browse the reference

Returns the value at a given percentage of the sorted numbers, interpolating between neighbouring items.

Try it in the editor

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

Pine Script
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 int

Arguments

NameTypeDefaultDescription
idarray<int/float> or array<int>requiredThe numeric array to rank. na items are skipped.
percentageseries int/floatrequiredA percentage from 0 to 100.

Returns

series float or series int: The interpolated value at that percentage.

Example

Pine ScriptInterquartile band of closesOpen in editor
//@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