Slope

Windowed · default period 20Statistics

The Slope node computes the OLS slope of the rolling window by treating bar index as x and input values as y. The result is the rate of change per bar in the same units as the input. A positive slope indicates an upward trend; negative indicates downward; near zero indicates flat. The Slope node is the core directional tool for trend detection, slope-crossover strategies, and regression channel construction.

Algorithm

  • Build pairs (i, v[i]) for non-null values in the window (x = bar index 0..n−1)
  • OLS: β₁ = Σ(x−x̄)(y−ȳ) / Σ(x−x̄)²
  • Returns 0 when denominator is zero
  • 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 Signal

Sign(Slope) gives +1 in uptrend and −1 in downtrend — a clean, regression-based trend direction indicator that is less noisy than price vs. MA crossovers.

Trend Velocity

Compare the Slope magnitude across different period lengths: short-period slope accelerating beyond long-period slope signals a momentum surge.

Regression Channel

Combine Slope and Intercept to reconstruct the OLS regression line at each bar — the foundation for regression channel trading strategies.