Value ref
rolling_statsA statistic of the last 2..1000 source observations, INCLUDING the current bar.
In addition to mean, std, zscore, sum, count, rank, percentile and ema:
slope is the OLS slope in source units per bar, with oldest x=0 and
newest x=N-1; linreg is that fitted line at the newest bar (no prediction
offset). wma weights oldest1 through newestN. rma is Wilder smoothing
with alpha1/N, SMA-seeded from N consecutive present samples, persistent
thereafter; any absence clears its seed, as for EMA.
highestbars / lowestbars return a nonnegative, unitless bar count
0..N-1 to the most recent tied maximum / minimum; current extremes return0.
These age windows always include the current bar; rolling_max/min make
that choice explicit through include_current.
Finite windows propagate any absence rather than skipping missing samples.
These operators accept custom arithmetic series and compose with offset;
history retains market-only scope. Windows count source-frame bars;
bind routes on leaves or at, and use sample for primary-clock observations.
source accepts ANY value ref, including a nested binary_expr, so
this is the general smoothing and normalisation primitive: an SMA of an
arbitrary expression is stat="mean", and a rolling z-score of a spread
is stat="zscore". Combined with rolling_max/rolling_min it
expresses whole indicator families that have no dedicated type — the %K of
a stochastic over any series is a 3-bar "mean" of the normalised ratio.
Absence propagates: one missing value in a finite window makes its
result absent, and the enclosing compare unknown. Purpose-built indicators that
compact their buffers to finite samples (srsi_k, stochastic_k)
survive undefined stretches that this ref does not, so they are not
redundant with it.
percentile_level is required when stat="percentile" and must be
omitted otherwise.
Composed RSI recipe (reference notation, authored as typed JSON):
delta = close - offset(close, 1);
avg_gain = rolling_stats(rma, max(delta, 0), N);
avg_loss = rolling_stats(rma, max(-delta, 0), N);
select(avg_loss <= 0 -> 100, else=100 - 100/(1 + avg_gain/avg_loss)).
This explicit guard chooses100 even when both averages are zero; native
RSI leaves that initial all-flat case undefined. For stochastics use
inclusive percentile100/0 as hi/lo and
select(hi <= lo -> 0, else=100 * (src-lo)/(hi-lo)). rolling_max/min
select prior bars for breakouts with include_current=false; set
include_current=true for inclusive extrema, including Williams %R.
A stochastic range guard should use hi - lo <= 1e-9 rather than
hi - lo <= 0 to absorb floating-point noise on nearly flat series.
Backing types
RollingStatsValueRef
Required fields
lookback_barsreqinteger-sourcereqanyOf (2 variants)Value or expression to summarize.statreqenum: mean, std, zscore, sum, count, rank, percentile, ema, slope, linreg, wma, rma, highestbars, lowestbars-Optional fields
kindstring-percentile_levelanyOf (2 variants)-Backing types
The IR ValueRef classes this builder field resolves to.