Rolling Slope¶
Math · Rolling
Least-squares linear-regression SLOPE over the trailing N bars — the per-bar rate of change of the fitted line (trend strength & direction). Positive = rising trend, negative = falling. NaN during warmup.
Rolling Slope fits a straight line through the last N bars of a series and hands back its slope — the per-bar rate of change of that fitted trend. Positive means the series is climbing, negative means it's falling, and the magnitude tells you how fast. It's a clean, single-number read on trend direction and strength.
How it works¶
Each bar the block runs a least-squares linear regression over the trailing window values and returns the slope of the best-fit line (change in value per bar). Because it fits the whole window rather than comparing two endpoints, it's far less jumpy than a naïve "now minus N bars ago." The first window − 1 bars are NaN during warmup. Lookahead-free.
When to use it¶
Use it as a trend gauge: is price (or an indicator) genuinely trending, and which way? A slope crossing zero is a smoother trend-change signal than a moving-average cross. It also makes a good regime filter — only take breakouts when the slope agrees with the direction — and a momentum input for scoring.
Example¶
Trend-agreement filter: wire close into Rolling Slope (window = 20), test it against 0 with GreaterThan for "uptrend," and feed that into an And with your entry trigger so longs only fire while the fitted trend is rising. Backtest in the Tester.
Tips & gotchas¶
- Slope is in value-units per bar — its scale depends on the input's scale, so tune thresholds per series (0 as the sign boundary is scale-free and safest).
- Whole-window fit — steadier than endpoint-to-endpoint change, but still lags at sharp turns.
- First
window − 1bars are NaN.
Related blocks¶
Inputs¶
| Socket | Type | What to wire in |
|---|---|---|
| In | series / bars |
Source series. BARS input uses close. |
Outputs¶
| Output | Type | Plots as | Description |
|---|---|---|---|
| slope | series |
Line · sub-pane | Linear-regression slope over the window (price units per bar). |
Parameters¶
| Parameter | Type | Default | What it does |
|---|---|---|---|
| Window (bars) | number · 2–500 | 14 |
Bars in the rolling window. |
Reference auto-generated from the block catalog · category Math.