universe_percentile

Universe Percentile (cross-stock ranking)

universe_percentile(field)

Ranks a stock's value relative to all other stocks in the scanned universe on the target date. Returns a value between 0 and 1.

Unlike percentrank(source, length) which ranks within a single stock's history, universe_percentile ranks across ALL stocks at a single point in time.

Parameters

  • field (field): The data series or indicator to rank across stocks
  • Raw fields: close, volume, turnover, bar_change_pct
  • Indicator outputs: sma(close, 20), rsi(close, 14)

Formula


universe_percentile(X) = (number of stocks with value < X) / (N - 1)

Result ranges from 0.0 to 1.0:

  • 0.0 = lowest value in universe
  • 1.0 = highest value in universe
  • 0.5 = median value

Examples


// top 10% by turnover
universe_percentile(turnover) > 0.90;

// top 5% by volume
universe_percentile(volume) >= 0.95;

// top 25% by bar change %
universe_percentile(bar_change_pct) > 0.75;

// top 20% by 20-day SMA
x = sma(close, 20); universe_percentile(x) > 0.80;

Returns

Float between 0.0 and 1.0 (percentile rank across universe)

Notes

  • Computed across ALL stocks in the scanned universe, not per-stock history
  • Raw-field percentiles are optimized to reduce the universe early, before expensive indicator calculations
  • Indicator-based percentiles (e.g., universe_percentile(rsi(close, 14))) require the indicator to be computed first, so they cannot be placed early
  • Ties share the same rank