Returns the value at the given percentile of the last length bars using the nearest-rank method, always an actual value from the window.
ta.percentile_nearest_rank sorts the window and picks the value at rank ceil(percentage / 100 * length). A percentage of 0 gives the smallest value and 100 the largest, and the result is always one of the window's own values.
Output is na until the window holds length values.
Syntax
ta.percentile_nearest_rank(source: series int/float, length: series int, percentage: simple int/float) -> series floatArguments
| Name | Type | Default | Description |
|---|---|---|---|
| source | series int/ | required | The series whose last length values are ranked; the result is one of them. |
| length | series int | required | Number of bars in the window. A whole number of 1 or more. |
| percentage | simple int/ | required | Percentile to find, from 0 to 100. |
Returns
series float: the window value at the requested percentile, or na while the window is not full.
Remarks
- Percentile 50 is close to
ta.medianbut never averages two values.
Example
//@version=6
indicator("90th percentile", overlay = true)
plot(ta.percentile_nearest_rank(high, 50, 90), "P90 of highs", color = color.red)
plot(ta.percentile_nearest_rank(low, 50, 10), "P10 of lows", color = color.green)See also
Runs on Sidechair