# Percentile Rank

Also known as: quantile analysis.
A Statistics concept (Normalization & distribution) in the LuxAlgo Library, with 2 indicator implementations.

## What is Percentile Rank?

Percentile rank locates the current value of a series within its own recent history: it is the percentage of values in a lookback window that sit at or below the current one. A rank of 100 means nothing in the window exceeds it, a rank near 0 means almost everything does, and 50 sits at the median. Because the calculation uses order alone, it is distribution-free: one monster outlier in the window counts as just another observation above or below, and no normality assumption is required.

That robustness is why it appears wherever raw values are hard to compare. Options traders express [implied volatility](https://www.luxalgo.com/library/concept/implied-volatility/) as a percentile of its past year, systems convert [ATR](https://www.luxalgo.com/library/concept/atr/) or volume into a 0-100 regime dial, and machine-learning pipelines rank-transform features before combining them. The limitation is symmetrical: rank reports rarity within the chosen window, not direction or follow-through, and in a persistent trend a series can keep printing in its top decile for weeks.

The conventions matter more than they look. Implementations differ on whether the current value is included in its own window, whether ties count as 'at or below', and whether ranks interpolate between order statistics; on large windows the differences vanish, on 20-bar windows they visibly move the reading. Serial dependence adds a second subtlety: a strongly trending or [autocorrelated](https://www.luxalgo.com/library/concept/autocorrelation/) series revisits its extremes repeatedly, so top-decile readings arrive in runs rather than as isolated events.

In workflow terms, rank is the nonparametric half of a standardization pair. Where a [z-score](https://www.luxalgo.com/library/concept/z-score/) trusts the mean and deviation, rank trusts only order, which makes it the safer transform exactly where market data misbehaves, in the fat-tailed, skewed distributions that [return profiling](https://www.luxalgo.com/library/concept/distribution-of-returns-profiling/) documents. The price is resolution: rank caps at its window's edges and cannot say how far beyond all previous values a genuinely new extreme has gone.

## How to calculate Percentile Rank

The nearest-rank calculation is counting, which is exactly why it is so robust.

1. Collect the last N values of the series; this window is the reference distribution the current value is judged against.
2. Count how many of those N values are less than or equal to the current value.
3. Divide the count by N and multiply by 100 for a 0-100 reading. Implementations differ slightly (whether the current bar is counted in the window, nearest-rank versus interpolated definitions), which matters mainly on small windows.
4. Fix the conventions once, tie handling, inclusion, interpolation, and keep them constant, so readings remain comparable across time and symbols.
5. Read runs, not prints: on persistent series, extremes arrive in sequences, and the exit from an extreme decile is often the more informative event than the entry.

## How it's calculated

Percentile rank locates the current value inside its own recent history, as the percentage of lookback values at or below it.

```
PR_t = 100 × count(x_(t-i) <= x_t for i = 1 to n) / n
Tie-aware mean-rank variant: PR_t = 100 × (c_below + 0.5 × c_equal) / N
Inverse (percentile, also called quantile): Q(p) = the value in the window below which p percent of the values fall, with linear interpolation between ranks

  x_t: source value at bar t (price or any indicator)
  n: lookback window length (commonly 100)
  i: offset back into the window
  count(): number of offsets satisfying the condition
  PR_t: percentile rank at bar t, 0 to 100
  c_below: count of window values strictly below x_t
  c_equal: count of window values equal to x_t
  N: number of values in the comparison window
  Q(p): percentile (quantile) function of the window
  p: percent level, 0 to 100
  t: bar index
```

Conventions differ on strict < versus <= and on whether the current bar joins the window; TradingView's percentrank compares the current value against the previous n bars using <=.

Nearest-rank and linear-interpolation quantile methods return slightly different values on small windows.

## How traders use it

- As adaptive [overbought/oversold](https://www.luxalgo.com/library/concept/overbought-oversold/) levels: instead of fixed oscillator thresholds, extremes are declared when a reading enters the top or bottom decile of its own history, so the bar for 'extreme' moves with the instrument's behavior.
- As a volatility regime switch: the [volatility percentile](https://www.luxalgo.com/library/concept/volatility-percentile-rank/) of ATR or realized volatility decides which playbook applies, for example favoring range tactics in low percentiles and breakout tactics in high ones.
- As a participation filter: [relative volume](https://www.luxalgo.com/library/concept/relative-volume/) screens rank current volume against comparable history, so 'heavy' means heavy for that symbol at that time of day rather than an absolute number.
- As a cross-sectional ranking: scoring many symbols by the same statistic and trading the top and bottom ranks is the standard construction of rotation and relative-strength baskets, with rank neutralizing each symbol's own scale.
- As an outcome scorecard: expressing a realized move as a percentile of history, or of a [simulated distribution](https://www.luxalgo.com/library/concept/monte-carlo-price-paths/), turns post-trade review into measured statements rather than adjectives.

## Percentile Rank vs related concepts

- **Z-score** (https://www.luxalgo.com/library/concept/z-score/): A z-score measures distance from the mean in standard deviations, so it preserves magnitude and can exceed any bound; percentile rank uses order only and caps at 0 and 100. Ranks are more robust to outliers, z-scores more informative about how extreme an extreme actually is.
- **Min-max Scaling** (https://www.luxalgo.com/library/concept/min-max-scaling/): Min-max scaling places the value proportionally between the window's low and high, so distances matter and one spike rescales everything. Percentile rank only counts how many values sit at or below. The options-market pair IV Rank (min-max) and IV Percentile (rank) shows how far apart the two can drift.
- **Stochastic Oscillator** (https://www.luxalgo.com/library/concept/stochastic-oscillator/): %K is min-max scaling of the close within the recent high-low range, not a count of past values. A stochastic near 100 says price is at the top of its range; a percentile rank near 100 says almost no recent value was higher. Similar look, different arithmetic.

## FAQ

### What is the difference between IV Rank and IV Percentile?

IV Rank is min-max scaling: where current implied volatility sits between its 52-week low and high. IV Percentile is percentile rank: the share of days over the same period with lower implied volatility. One volatility spike inflates the min-max range and depresses IV Rank for months afterward, while the percentile barely moves, so the two frequently disagree.

### What lookback window should percentile rank use?

The window defines what 'unusual' means. Twenty bars measures short-term rarity; a year of data measures rarity within a broad regime, which is the convention in volatility work. Longer windows give stabler thresholds but adapt slowly after a structural shift, so match the window to how far back you believe conditions are still comparable.

### Does a 100th percentile reading signal a reversal?

No. It only says the current value is the highest in the window, and strong trends print new highs repeatedly, re-marking 100 bar after bar. Rank supplies context about rarity; a tradable reversal case still needs structure, a level, or momentum evidence on top of it.

### What is the difference between a percentile and a percentile rank?

Direction of the lookup. A percentile starts from a probability and returns the value (the 90th percentile of returns is a return level); percentile rank starts from a value and returns its standing (today's reading sits at the 90th rank). They are inverse views of the same order statistics, and tools routinely display both without labeling which is which.

### How do ties and repeated values affect the rank?

They pile mass at single values, and the convention decides the outcome: counting 'at or below' pushes tied readings toward higher ranks, 'strictly below' toward lower, and midpoint conventions split the difference. On heavily quantized series (small windows, coarse ticks, long flat stretches) the choice visibly shifts readings, which is why the convention belongs in the tool's documentation and your notes.

### Why does a trending series pin at extreme ranks for so long?

Serial dependence. Rank assumes the window is a fair reference sample, but a trending series keeps producing values beyond its recent past, so the current bar outranks nearly everything for as long as the trend persists. The reading is correct, genuinely nothing recent was higher, and useless as a fade signal, which is the standing argument for pairing rank extremes with structure.

## Implementations in the Library

- Reversal Probability Zone & Levels (LuxAlgo): https://www.luxalgo.com/library/indicator/reversal-probability-zone-levels/
- Percentile Nearest Rank Using Arrays (LuxAlgo): https://www.luxalgo.com/library/indicator/percentile-nearest-rank-using-arrays/

## Related concepts

- Distribution-of-returns Profiling: https://www.luxalgo.com/library/concept/distribution-of-returns-profiling/
- Min-max Scaling: https://www.luxalgo.com/library/concept/min-max-scaling/
- Sigmoid/softmax Transforms: https://www.luxalgo.com/library/concept/sigmoid-softmax-transforms/
- Standard Deviation: https://www.luxalgo.com/library/concept/standard-deviation/
- Z-score: https://www.luxalgo.com/library/concept/z-score/
- Winsorization: https://www.luxalgo.com/library/concept/winsorization/
- Distribution Moments: https://www.luxalgo.com/library/concept/distribution-moments/
- Normality Testing: https://www.luxalgo.com/library/concept/normality-testing/
- Outlier Detection: https://www.luxalgo.com/library/concept/outlier-detection/

---

Source: https://www.luxalgo.com/library/concept/percentile-rank/ (LuxAlgo Library, the encyclopedia of trading & technical analysis). Free to use with attribution: https://www.luxalgo.com/library/license/