Slope
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
| Name | Type | Default | Description |
|---|---|---|---|
| period | number | 20 | Rolling window size. |
Inputs & Outputs
| Port | Type | Description |
|---|---|---|
| Inputs | ||
| input | number[] | Source numeric array |
| Outputs | ||
| values | number | null | Computed value at each bar; null before the warmup period completes |
| timestamps | number[] | Bar timestamps (UNIX ms), aligned 1-to-1 with values |
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.