pct_change
Percent Change between two values
pct_change(current, base)
Parameters
| Name | Type | Description |
|---|---|---|
current |
field | Current/new value (numerator difference component) |
base |
field | Base/reference value (denominator) |
Formula
```
pct_change = ((current - base) / base) * 100
```
Examples
// Daily change: close vs previous close
pct_change(close, close[1]) > 5; // Up more than 5% from yesterday
// Gap percentage: open vs previous close
pct_change(open, close[1]) > 2; // Gapped up more than 2%
// Intraday range: high vs low
pct_change(high, low) > 3; // Bar range exceeds 3%
// Weekly momentum
pct_change(close, close[5]) > 10; // Up more than 10% over 5 bars
// Compare to moving average
pct_change(close, sma(close, 20)) > 5; // 5%+ above 20-day SMA
// Volume surge vs average
pct_change(volume, sma(volume, 20)) > 100; // Volume 2x+ average
// Find big losers
pct_change(close, close[1]) < -5; // Down more than 5% today
// Compare high to previous high
pct_change(high, high[1]) > 0; // Higher high (any amount)
Returns
Percentage value (e.g., 5.0 means 5% increase, -3.0 means 3% decrease) ## Notes - Returns positive values when current > base - Returns negative values when current < base - Returns NULL when base = 0 (division protected via NULLIF) - Stocks with NULL results are excluded from scan results - Example: pct_change(macd_line(close, 12, 26, 9), macd_line(close, 12, 26, 9)[3]) returns NULL when historical MACD = 0 - Unlike roc(), this function accepts two independent values - For single-series rate of change over N periods, use roc(source, N) ## Related Synthetic Fields For common bar-level percentage calculations, these convenience fields are available: - `bar_change_pct` = pct_change(close, open) - bar body as % of open - `bar_range_pct` = pct_change(high, low) - bar range as % of low For other denominator choices, use pct_change() directly: - pct_change(high - low, close) - range as % of close - pct_change(high - low, hl2) - range as % of midpoint - pct_change(close - open, close) - body as % of close