blog · ~6 min read

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.

T By tradernewbie · Curated for beginners
#statistics#quantitative
이 문서는 영어로 되어 있습니다. 내 언어로 볼까요? Google Translate →

번역 보기에서는 대화형 도구가 작동하지 않을 수 있습니다.

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

  1. Trend strength filter: only trade trend systems when R² > 0.5
  2. Regression channel / standard error bands: enter when price reverts to the line, exit at ±2σ
  3. Slope as momentum: a falling slope on rising prices warns of momentum loss even before price turns
  4. 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

  1. Pick a window (e.g., 50 bars)
  2. Run OLS of price vs bar index
  3. Check the slope sign and R²
  4. Combine with volatility (σ) to set channel width
  5. 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.

Related market data, powered by TradingView.

Educational content · Not financial advice · Trade at your own risk