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.
Chart
Chart metadata i
Outputs
outReal:line·zero·positive
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–10000 | Number of preceding values the current value is ranked against |
Properties
Numerical Stability: Start-Independent
| ☐ Overlap Input |
| ✅ Independent Y-Axis i |
| ☐ Candlestick |
| ☐ Display Shift |
| ☐ Can Output NaN or ±Inf |
| ☐ Identity at Period 1 |
| ☐ Uses Transcendental |
| ☐ Input Must Be Positive |
Example
#include <stdio.h>
#include <ta_libc.h>
int n = 252;
double series[252]; /* your data, oldest first */
double out[252];
int outBegIdx, outNBElement;
TA_Initialize();
TA_PERCENTRANK( 0, n - 1, series, 100, &outBegIdx, &outNBElement, out );
printf( "%d values from bar %d: [%.4f, ..., %.4f]\n", outNBElement, outBegIdx, out[0], out[outNBElement - 1] );use ta_lib::Core;
let series = vec![0.0; 252]; // your data, oldest first
let mut out = vec![0.0; 252];
let core = Core::new();
let range = core.percentrank(0, series.len() - 1, &series, 100, &mut out)?;
println!("{} values from bar {}: [{:.4}, ..., {:.4}]", range.count, range.beg_idx, out[0], out[range.count - 1]);import io.github.talib.Core;
import io.github.talib.OutRange;
import java.util.Locale;
double[] series = new double[252]; // your data, oldest first
double[] out = new double[252];
Core core = Core.DEFAULT;
OutRange r = core.percentrank(0, series.length - 1, series, 100, out);
System.out.printf(Locale.ROOT, "%d values from bar %d: [%.4f, ..., %.4f]%n", r.count(), r.begIdx(), out[0], out[r.count() - 1]);using System;
using TALib;
var series = new double[252]; // your data, oldest first
var outReal = new double[252];
var core = Core.Default;
OutRange r = core.Percentrank(0, series.Length - 1, series, 100, outReal);
Console.WriteLine(FormattableString.Invariant($"{r.Count} values from bar {r.BegIdx}: [{outReal[0]:F4}, ..., {outReal[r.Count - 1]:F4}]"));import { percentrank } from 'ta-lib';
const series = new Float64Array(252); // your data, oldest first
const { begIdx, values } = percentrank(series, { timePeriod: 100 });
console.log(values.length + ' values from bar ' + begIdx + ': [' + values[0].toFixed(4) + ', ..., ' + values[values.length - 1].toFixed(4) + ']');import (
"fmt"
"log"
talib "ta-lib.github.io/go"
)
series := make([]float64, 252) // your data, oldest first
out := make([]float64, 252)
core := talib.NewCore()
r, err := core.PERCENTRANK(0, len(series)-1, series, 100, out)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%d values from bar %d: [%.4f, ..., %.4f]\n", r.NBElement, r.BegIdx, out[0], out[r.NBElement-1])Implementation
Added in 0.8.1 (ta-lib-python 0.8.1).
TA-Lib Definition: percentrank.c · percentrank.yaml
| Native | File |
|---|---|
| C | ta_PERCENTRANK.c |
| Rust | percentrank.rs |
| Java | Core_PERCENTRANK.java |
| C# | Core_PERCENTRANK.cs |
| TypeScript | percentrank.ts |
| Go | percentrank.go |
Python: talib.PERCENTRANK (ta-lib-python 0.8.1 or later), see ta-lib-python.
TA-Lib is also available for R and more using a wrapper.