DocsMathStatisticsAutocorrelation

Autocorrelation

Windowed · default period 20Statistics

The Autocorrelation node measures the Pearson correlation between x[0..n−2] and x[1..n−1] within the rolling window — the lag-1 serial correlation. Output ranges from −1 to +1. Positive values indicate a trending, momentum-driven series; negative values indicate mean-reversion; values near zero indicate noise or randomness. Requires at least 3 non-null values.

Algorithm

  • Split window into lagged pairs: x = vals[0..n−2], y = vals[1..n−1]
  • Compute Pearson correlation: r = cov(x, y) / (std(x) × std(y))
  • Returns 0 when denominator is zero (flat series)
  • Requires ≥ 3 non-null values; otherwise null

Parameters

NameTypeDefaultDescription
periodnumber20Rolling window size. Minimum 3.

Inputs & Outputs

PortTypeDescription
Inputs
inputnumber[]Source numeric array
Outputs
valuesnumber | nullComputed value at each bar; null before the warmup period completes
timestampsnumber[]Bar timestamps (UNIX ms), aligned 1-to-1 with values
Live mode: In live streaming mode the node updates only the last bar in-place rather than recalculating the full array, keeping CPU usage minimal during real-time data feeds.

Use Cases

Regime Classification

Autocorr > 0.3 → trending regime (favor momentum strategies); autocorr < −0.1 → mean-reverting (favor counter-trend entries).

Strategy Mode Switching

Gate trend-following entry signals with a high autocorrelation filter to avoid whipsaws in choppy regimes.

Indicator Quality

Apply Autocorrelation to an RSI or CCI series to measure whether it is moving directionally. High positive autocorrelation on RSI warns of oversold/overbought extremes persisting.