A statistical best-fit straight line through the price points over the lookback window. The endpoint of that line is the indicator's primary output; the slope tells you the trend's steepness; R-squared tells you how well the line actually fits the data — i.e., whether there's a real trend or just noise.
What it measures
- The statistical "best fit" trend. Where price should be if it continues the current straight-line trajectory.
- Trend slope. The steepness of the fitted line across the whole lookback. Positive = the window is rising, negative = falling. Magnitude indicates steepness.
- Trend quality (R-squared). Bounded 0-100. High R² means price is following the line closely (clean trend). Low R² means price is scattered around the line (chop).
Formula
Inputs in AlgoLift
| Setting | Default | Range | Notes |
|---|---|---|---|
| Period | 14 | 2–500 | Lookback for fitting the regression line. |
Recommended periods
- 9–14: Short-to-medium-term trend analysis.
- 14 (default): Standard.
- 20–30: Slower, smoother fit for swing setups.
- 50+: Long-horizon regime classification.
Outputs in AlgoLift
| Handle | Type | Plotted | Notes |
|---|---|---|---|
| Regression Line | Numeric | Always | The endpoint value — where price "should" be according to the fit. |
| Fit Slope | Numeric | On select | The fitted line's steepness over the last N bars, in price per bar. Not the change from the prior bar (see below). |
| R-Squared | Numeric | On select | 0-100. The line's goodness of fit. Above 70 = clean trend; below 30 = noise. |
How to read it
- Price above the regression line: Above-trend reading. May indicate overextension in a range, or trend strength in a real trend (R² tells you which).
- Price below the regression line: Below-trend reading. Same caveat.
- Fit Slope positive: Uptrend in the lookback window.
- Fit Slope negative: Downtrend in the lookback window.
- R² > 70: The fit is good — the trend is real and consistent. Trend-following strategies favored.
- R² < 30: The fit is poor — price is mostly noise around the line. Mean-reversion strategies favored, or pause trading entirely.
- R² between 30 and 70: Transitional. Neither extreme is reliable.
Fit Slope is not the line's turn
On most indicators in AlgoLift, a Slope output is the change since the prior bar. Fit Slope is different: it is the steepness of one line fitted through all N bars of the window. When a rally rolls over, the Regression Line turns down within a bar or two, because its endpoint follows the newest bars closely. Fit Slope stays positive until enough falling bars have entered the window to outweigh the rally, which can take many bars. On the chart, Fit Slope peaks about where the line turns, then falls toward zero.
To act on the bar the line itself turns, compare the Regression Line with its own earlier values: use Bars Ago Modifier for the line one and two bars back, and a Comparison for each step. The line turned up when it is higher than one bar ago, and one bar ago was at or below two bars ago. Turning down is the mirror.
R-squared is the differentiating output. Most indicators give you direction; Linear Regression gives you direction plus confidence in that direction. Strategies that gate their entries on R² > 70 dramatically improve their signal-to-noise ratio.
Best in / worst in
Best in instruments and timeframes that produce clear linear trends — equity indices in established regimes, momentum-driven currencies during macro moves. R² lets you objectively classify "is this a real trend?" without subjective interpretation.
Worst in instruments with exponential-style growth (where a linear fit systematically underestimates the trend), and in markets with frequent gaps (the regression line is sensitive to single outlier bars).
Three setups
1. R-squared as a regime filter
The signature Linear Regression pattern — use R² to gate other strategies.
- Trend-following strategies allowed when: R² > 70.
- Mean-reversion strategies allowed when: R² < 30.
- No trades when: R² between 30 and 70.
A simple, single-output regime classifier that maps directly to strategy-type selection.
2. Slope + R² combined entry
Trade when slope and R² both confirm a strong trend.
- Long: Fit Slope > 0 AND R² > 70 AND price > Regression Line.
- Short: Fit Slope < 0 AND R² > 70 AND price < Regression Line.
The slope gives direction; R² confirms the slope is meaningful; the price-vs-line check ensures price is moving in the slope's direction.
3. Regression Line as a dynamic support/resistance
Use the regression line value as a pullback target in trends.
- Long pullback: Fit Slope > 0 AND R² > 60 AND price touches within 0.5× ATR of the Regression Line value.
- Short pullback: Symmetric.
Combined with a fixed-distance stop below the line, this captures pullbacks-to-trend efficiently.
Advanced patterns in AlgoLift
R² for position sizing. Scale position size by R²: size = base × R² / 100. Strong, clean trends get full size; noisy environments get small or no positions. Combined with fixed-fractional risk math, this produces an objective volatility/quality-adjusted sizing scheme.
R² + ADX dual confirmation. Both indicators measure trend strength via different methods. Require R² > 70 AND ADX/DMI > 25 before allowing any trend-following entry. The dual filter eliminates almost all noise-trend false signals — and trades become rare but high-conviction.
Regression Line as the trailing exit reference. In a long position, exit when price closes below the Regression Line. Acts as a dynamic, statistically-anchored trailing stop. Wire via Set Exit Condition.
Regression Slope for scale-in triggers. Use the initial entry to take a starter position. Use Scale-In Entry to add when the Fit Slope reaches a higher threshold (trend accelerating). The objective slope reading prevents arbitrary "trend looks strong" judgment calls.
Common mistakes
- Trading direction without R² confirmation. A negative slope with R² = 15 means the line is fitting noise — the "downtrend" isn't real. Always gate trend signals on R² > 60 minimum.
- Using on exponentially-growing instruments. Stock indices during long bull runs have exponential price action — linear regression systematically underestimates the slope. Use a log-scale linear regression instead, or switch to a moving-average-based trend tool.
- Waiting for Fit Slope to cross zero to catch a turn. By then the Regression Line has usually been falling (or rising) for many bars. For the turn itself, compare the line with its own earlier values (see "Fit Slope is not the line's turn" above).
- Tuning the period to maximize R². A short period will always have high R² because there's less data to fit poorly. R² is informative within a fixed period — comparing R² across different periods is meaningless.