Percent Rank (PERCENTRANK)
Summary
Percent Rank: where the current value sits inside the distribution of the values that came before it, as a percentage.
Each bar is compared against the optInTimePeriod values immediately preceding it — the current bar is not part of its own comparison set — and the output is the share of them it exceeds. 0 means the current value is at or below every one of them, 100 means it is above all of them, 50 means it is above half.
It is a distribution-relative reading rather than a price-relative one: unlike an oscillator built from ranges or averages, it says nothing about how far the value moved, only how many of its recent predecessors it overtook. That makes it flat-scaled across instruments and directly comparable between them. It is best known as the third leg of Connors' ConnorsRSI, applied there to one-day returns rather than to price.
Formula
For each bar t, over the previous optInTimePeriod values:
count = number of j in [t-optInTimePeriod, t-1] with inReal[j] < inReal[t]
PERCENTRANK[t] = ( count / optInTimePeriod ) * 100
The comparison is strictly less-than, so a value tied with a predecessor does not count that predecessor.
Notes
- Ties are strict: a predecessor equal to the current value is not counted. A constant series therefore reports 0 on every bar. TradingView's
ta.percentrankcounts ties as well (less-than-or-equal), which reports 100 on that same series; Pine parity is a different function, not a variant of this one, and the two agree only on windows with no repeated values. - +0.0 and -0.0 compare equal, so a sign-only difference never contributes to the count.
- Finite input is a precondition. A NaN in the window fails every comparison, so it silently lowers the rank instead of propagating: the output stays finite and no error is reported.
Inputs
inReal— Source price/value series
Outputs
outReal— Percentage of the preceding window strictly below the current value, 0 to 100
Parameters
| Parameter | Type | Default | Accepted values | Description |
|---|---|---|---|---|
optInTimePeriod | integer | 100 | 2–100000 | Number of preceding values the current value is ranked against |
Properties
Numerical Stability: Start-Independent
| ☐ Overlap Input |
| ✅ Independent Y-Axis i |
| ☐ Candlestick |
| ☐ Can Output NaN or ±Inf |
| ☐ Identity at Period 1 |
Implementation
TA-Lib Definition: percentrank.c · percentrank.yaml
| Native | File |
|---|---|
| C | ta_PERCENTRANK.c |
| Rust | percentrank.rs |
| Java | Core_PERCENTRANK.java |
TA-Lib is also available for Python, R and more using a wrapper.