Sidechair

ta.percentrank()

Browse the reference

Returns the percentage of the previous length values of source that are less than or equal to the current value.

Try it in the editor

ta.percentrank looks back over the length bars before the current bar and counts how many of them are at or below the current value. The count is divided by length and scaled to 100.

A reading of 100 means the current value is at least as high as every bar in the window. It needs length earlier bars plus the current one, so output begins on bar number length + 1.

Syntax

Pine Script
ta.percentrank(source: series int/float, length: series int) -> series float

Arguments

NameTypeDefaultDescription
sourceseries int/floatrequiredThe series whose current value is ranked against its last length values.
lengthseries intrequiredNumber of earlier bars compared against. A whole number of 1 or more.

Returns

series float: a value from 0 to 100, or na while there are fewer than length earlier bars.

Remarks

  • The current bar is not part of the window it is compared with.

Example

Pine ScriptVolume rankOpen in editor
//@version=6
indicator("Volume percent rank")
plot(ta.percentrank(volume, 100), "Rank", color = color.blue, style = plot.style_histogram)
hline(90)
hline(10)

See also

Runs on Sidechair