DocsMathStatisticsLin Reg Slope

Lin Reg Slope

Windowed · default period 20Statistics

The Linear Regression Slope node performs OLS linear regression over the rolling window (x = bar index, y = price/indicator value) and outputs the slope at each bar. It expresses the rate of change per bar in the same units as the input, making it easy to compare trend velocity across lookback periods. This is the canonical trend-direction node for slope-crossover and slope-magnitude strategies.

Algorithm

  • Build pairs (i, v[i]) for non-null v[i] in the window
  • OLS slope β₁ = Σ(x−x̄)(y−ȳ) / Σ(x−x̄)² where x = bar index 0..n−1
  • Returns 0 when denominator is zero (single non-null value)
  • Requires ≥ 2 non-null pairs; returns null otherwise

Parameters

NameTypeDefaultDescription
periodnumber20Rolling window size.

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

Trend Direction Filter

Only take long trades when LinRegSlope > 0 (positive trend) and short trades when it is < 0 — a noise-filtered trend direction signal.

Slope Magnitude Filter

Threshold the absolute value of LinRegSlope (e.g., > 0.05) to only trade when the trend is steep enough to overcome typical spread/commission costs.

Slope Crossover

Use Sign(LinRegSlope) to detect zero crossings — equivalent to detecting when the rolling linear trend changes direction.