
Linear Regression and Trend Quantification
Linear regression turns a chart full of noise into a single line that quantifies trend. Learn the math, the slope, and R-squared, and how traders use them.
Linear Regression and Trend Quantification
A trendline drawn by hand is an opinion. A regression line is a fact.
Traders draw trendlines subjectively — and every analyst draws a different one. Linear regression replaces that guesswork with a best-fit line that minimizes error and gives you objective slope and strength numbers.
The model
Linear regression fits a line to a series of (x, y) points:
y = β0 + β1·x + ε
Where β1 is the slope (rate of change) and β0 the intercept. The method of ordinary least squares finds the line that minimizes the sum of squared errors:
Minimize: Σ (yi − ŷi)²
The slope formula is:
β1 = Σ((xi − x̄)(yi − ȳ)) ÷ Σ((xi − x̄)²)
In trading, x is time (bar index) and y is price. The slope then tells you how fast price is trending per bar.
R-squared: how well does the line fit?
R² measures the fraction of variance explained by the trend:
R² = 1 − (SS_res ÷ SS_tot)
Ranging from 0 to 1:
- R² near 1 → tight, clean trend
- R² near 0 → no linear trend; price is ranging or random-walking
Many platforms plot this as a coefficient of determination channel. A high R² means the trend line is trustworthy; a low R² means you're fooling yourself.
Trading applications
- Trend strength filter: only trade trend systems when R² > 0.5
- Regression channel / standard error bands: enter when price reverts to the line, exit at ±2σ
- Slope as momentum: a falling slope on rising prices warns of momentum loss even before price turns
- Cointegration tests: regress one asset on another to find the spread used in pairs trading
The danger: curve fitting and nonlinearity
- Markets are rarely linear for long; a regression line will fit beautifully right up until a break
- Extending the line into the future assumes the trend continues — dangerous
- Outliers (gaps) distort the slope badly. Use robust regression or trim outliers when noise is high
A practical workflow
- Pick a window (e.g., 50 bars)
- Run OLS of price vs bar index
- Check the slope sign and R²
- Combine with volatility (σ) to set channel width
- Trade reversals to the mean only when R² is high; trade breakouts when R² is collapsing
Summary
Linear regression gives you an objective trend: slope for direction and speed, R² for strength. It won't predict the future, but it tells you — without bias — whether a trend actually exists right now and how clean it is. That objectivity is its real value.
Live Chart
Open full chart →Related market data, powered by TradingView.
My Notes
Log in to save notes on this article and share them with the community.
Read next
Standard Deviation, Volatility, and Beta Calculations
Calculate standard deviation, annualized volatility, and Beta correctly for trading, with the common errors and the right windows for each measure.
Read more →Smart Recommendations