StatisticalPine Script v6

ta.percentrank()Percent Rank

ta.percentrank() returns the percentage of values in the lookback window that are less than or equal to the current source value, producing a comparable 0–100 rank.

Pine Script v6 reference verified: · TradingView reference

Syntax

Syntax
ta.percentrank(source, length) → series float

Arguments

ParameterTypeDescription
sourceseries int/floatSeries of values to process.
lengthseries intNumber of bars in the rolling window.

Returns

A series float representing the current source value’s percent rank over the requested lookback window.

Remarks

na values in the source series are included in the calculation and produce an na result.

Code Examples

Pine Script v6 Example
//@version=6
indicator("ta.percentrank")
plot(ta.percentrank(close, 50))

Trading Applications

Rank current value relative to historical values

Identify extreme readings for mean reversion

Build percentile-based trading signals

Normalize indicators across different securities

Frequently Asked Questions

It measures where the current bar value sits within the distribution of the last length values, expressed as a percentile-style rank useful for spotting extremes.

High rank means the current value is large versus recent history; low rank means it is small. Traders often watch thresholds (e.g. above 90 or below 10) for stretched conditions.

It normalizes price or indicator levels into a comparable 0-100 scale over a window, which helps compare symbols and build mean-reversion or breakout rules.

na values are included in the calculation rather than skipped. If the source window contains an na value needed by the calculation, the function produces an na result.

ta.percentrank() ranks the current source value within its recent window. ta.percentile_nearest_rank() and ta.percentile_linear_interpolation() instead return the source value at a requested percentile.

Generate ta.percentrank() Code with AI

Skip the manual coding. Use Pineify's AI Coding Agent to generate Pine Script code using ta.percentrank() and other built-in functions instantly.