Lin Reg Slope
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
| 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 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.