percentrank

Percent Rank

percentrank(source, length)

Parameters

Name Type Description
source field The data series to calculate rank on
length int Number of periods for the lookback window

Formula

```
Percent Rank = (Count of values < current value) / (length - 1) * 100

Where:
- Count includes all values in the window except current
- Result ranges from 0 to 100
- 0 = current value is lowest in window
- 100 = current value is highest in window
- 50 = current value is at median
```

Examples

percentrank(close, 100);  # 100-period percent rank
percentrank(volume, 20);  # Volume percentile rank
percentrank(close, 252) > 90;  # Price in top 10% of yearly range
percentrank(rsi(close, 14), 50) < 10;  # RSI in bottom 10% of recent values

Returns

Percent rank value between 0 and 100 ## References - TradingView: `ta.percentrank()` - Similar to percentile but calculates current value's position - Related to stochastic oscillator concept ## Notes - Returns 0 when current value is the minimum in the window - Returns 100 when current value is the maximum in the window - Returns 50 when current value is at the median - Useful for identifying overbought/oversold conditions - Can be applied to any indicator output (RSI, volume, etc.) - More robust than simple price comparisons - Returns NULL when insufficient data (< length bars)