percentrank

Percent Rank

percentrank(source, length)

Parameters

Percent Rank - percentrank(source, length)

Calculates the percentage of values in the lookback period that are less than

the current value. This provides a relative ranking of the current value within

the historical window, useful for identifying extreme or unusual values.

  • source (field): The data series to calculate rank on
  • Valid inputs: close, open, high, low, volume, or any indicator output
  • length (int): Number of periods for the lookback window
  • Common values: 14, 20, 100
  • Range: 1 to any positive integer

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