Linear Regression Indicator: Formula, Slope and Example
Understand the Linear Regression Indicator, its slope and lookback settings, with checked example arithmetic and the limits of using a fitted price trend.
Key Takeaways
- 1.The Linear Regression Indicator plots the latest point of a straight line fitted through recent prices, then repeats the calculation as new bars arrive.
- 2.A positive slope describes a rising fitted line; it does not forecast a profitable trade.
- 3.Lookback, source and offset can change the displayed value.
- 4.Regression curves, slopes and channels are related displays with different meanings.
What the Linear Regression Indicator Actually Plots
The rolling endpoint form of the Linear Regression Indicator fits a straight line through the last N selected prices. It uses least squares, a method that minimises squared gaps between prices and the line. With zero offset, meaning no shift along the fitted line, it plots the latest endpoint. A simple moving average takes the arithmetic mean; other averages use different weights.
A fitted regression endpoint and a simple moving average use different calculations. Their responses to new prices can differ; neither reliably identifies a new trend before it happens.
The endpoint curve, the slope and the regression channel are related tools. A channel adds deviation bands around a fitted line. Check the platform definition rather than assuming all displays named linear regression are identical.
The Least Squares Maths in One Page
For N bars, slope measures how much the fitted line rises or falls per bar. Calculate it as the sum of (x minus mean x) times (y minus mean y), divided by the sum of (x minus mean x) squared. Here x is the bar number (1, 2, 3 and so on) and y is the closing price. The intercept, where the line reaches the vertical axis, is mean y minus slope times mean x. The latest endpoint is intercept plus slope times the last x.
Slope is measured in price units per bar. A positive sign describes an upward fitted direction; a negative sign describes a downward fitted direction. Its magnitude depends on the instrument price scale and bar interval, so it is not a probability or confidence score.
A slope crossing zero records a change in the fitted line. It cannot establish that the next price move will continue in the same direction.
Worked Example: Computing the Slope by Hand
Use this small illustrative dataset to check the arithmetic: bar positions 1, 2 and 3 with closing prices 100, 102 and 104. These are made-up values rather than market history.
| Example bar | Example close |
|---|---|
| 1 | 100 |
| 2 | 102 |
| 3 | 104 |
Mean bar position is 2 and mean close is 102. The slope is ((1-2) x (100-102) + (2-2) x (102-102) + (3-2) x (104-102)) divided by ((1-2) x (1-2) + (2-2) x (2-2) + (3-2) x (3-2)), giving 2 price units per bar. Intercept is 98 and fitted endpoint is 98 + 2 x 3 = 104.
This perfect line is deliberately simple. Actual closes usually do not sit on the fitted line, and an upward historical fit does not make a later pullback a buying opportunity.
A second example with a line that does not fit perfectly
Real prices scatter around the line. Take five made-up closes at bars 1 to 5: 100, 102, 101, 105 and 107. The mean bar position is 3 and the mean close is 103.
| Bar | Made-up close | Fitted value | Gap (close minus fitted) |
|---|---|---|---|
| 1 | 100 | 99.6 | 0.4 |
| 2 | 102 | 101.3 | 0.7 |
| 3 | 101 | 103.0 | -2.0 |
| 4 | 105 | 104.7 | 0.3 |
| 5 | 107 | 106.4 | 0.6 |
The top of the slope formula is (-2 × -3) + (-1 × -1) + (0 × -2) + (1 × 2) + (2 × 4) = 17. The bottom is 4 + 1 + 0 + 1 + 4 = 10. So the slope is 17 ÷ 10 = 1.7 price units per bar. The intercept is 103 - 1.7 × 3 = 97.9, and the fitted endpoint at bar 5 is 97.9 + 1.7 × 5 = 106.4. The actual last close is 107, which is 0.6 above the line. Squaring the five gaps and adding them gives 5.1, so the line misses the closes by that amount.
Reading the Slope: Direction, Strength and the Zero Cross
A positive fitted slope summarises an upward relationship between bar position and price in the selected sample. A slope near zero can occur in a range or during offsetting swings; it does not prove the market is inactive.
- Positive slope: rising fitted direction within the sample.
- Negative slope: falling fitted direction within the sample.
- Near-zero slope: little net fitted direction.
- A changed sign describes the fitted sample, not a confirmed future reversal.
On intraday charts, changing the bar interval changes what a unit of slope means. Compare like-for-like settings before drawing conclusions.
R-squared: how closely prices follow the line
The slope tells you the fitted direction. It does not tell you how well the line describes the prices. A companion measure, Linear Regression R2 (R-squared), does that. StockCharts describes it as an oscillator that moves between zero and one. A reading near zero suggests a lack of trend and a reading near one suggests a strong trend. StockCharts says its default lookback is 14 periods, and adds that the indicator does not measure the direction of the trend, only whether the security is trending.
R-squared is one minus the unexplained spread divided by the total spread around the average price. In the second example, the total spread is 9 + 1 + 4 + 4 + 16 = 34 and the unexplained spread is 5.1, so R-squared is 1 - 5.1 ÷ 34 = 0.85. That says the line captures a large part of the movement in this made-up sample. It says nothing about what the next bar will do.
Lookback, Price Source and Offset Settings
The period controls the number of bars included in the fit. There is no verified best setting for an Indian index or stock. Choose settings for a stated purpose and evaluate them after costs rather than treating a sample setting as advice.
A corporate event or unexpected news can interrupt a trend regardless of the fitted slope. The indicator uses observed prices and cannot account for information that has not arrived.
Linear Regression vs Moving Average vs LSMA
LSMA means Least Squares Moving Average, a rolling regression curve. Check the source price and offset, the shift along the fitted line, when comparing it with another regression endpoint. A simple moving average takes an arithmetic mean.
Regression can overshoot prices or change direction repeatedly in a range. Adding another filter can also delay entries and exclude useful observations; it does not guarantee fewer losing trades.
Why the endpoint reacts faster than a simple average
A simple moving average gives every bar in the window the same weight and so lags in a trend. A regression endpoint extends the fitted line to the latest bar, so in a steady rise it sits closer to the latest price. The cost is that when the sample bends, the line can swing hard. In the first example, the three closes of 100, 102 and 104 average to 102, but the regression endpoint is 104. Both are correct arithmetic; they answer different questions.
Because platforms differ in how they handle offset and the source price, record those settings in your notes before comparing an indicator across charts. See also our moving average envelopes page for another band-style tool.
Comparing Regression With Momentum and Volume
Some traders compare regression direction with momentum and volume. Define any additional filter explicitly. Agreement between indicators is not independent proof of a profitable setup.
Evaluate any filter using a stated dataset and costs. Without that evidence, a claim that a combination removes most false signals would be unsupported.
Using the indicator in a trading journal
If you use a regression indicator in a strategy, your journal should show how it affected decisions. For each trade, note the lookback, the price source, whether the slope was positive or negative at entry, and what you did when the sign changed. After enough trades, you can compare results for entries with a rising fitted line against entries with a flat one.
- Record the indicator settings so a later review compares the same thing.
- Tag entries where the slope sign had just changed.
- Note whether you exited on a slope change or on your written stop.
- Compare results after costs, not before.
- Keep a count of trades, since a handful says very little.
OneTradeJournal is a manual journal: you enter each trade yourself, with the strategy, stop, target and notes. It has no market data and does not draw indicators or give signals. It can show win rate, profit factor and drawdown by strategy once you have logged trades. For related reading, see the trendline glossary entry and the risk per trade calculator.
Limitations, False Signals and Risk Control
A regression fit uses past observations and cannot anticipate unexpected news. It approximates the selected sample with a straight line; this does not mean actual prices must follow that line. In a changing or sideways sample, the fitted slope can change sign repeatedly. Any trading interpretation still needs evaluation after costs.
A price fit does not determine an affordable position. For futures, calculate risk from quantity and the intended stop distance, then allow for charges and worse execution. A stop remains a plan rather than a guaranteed loss cap.
Keep the signal description separate from risk and results. A steep fitted line does not tell you a trade will win.
Related reading: volatility, position sizing, costs.
Common mistakes with regression indicators
- Treating a high R-squared as a forecast. It describes the past sample.
- Comparing slopes across instruments. Slope is in price units per bar, so a stock at a high price will have larger numbers than one at a low price.
- Changing the lookback after seeing results, then trusting the improved fit.
- Using a very short window, where two or three bars can swing the line.
- Mixing channel bands with endpoint values as if they were one indicator.
- Ignoring costs, so a small edge disappears.
To compare slopes across prices, some analysts divide the slope by the average price. That is a choice of method, not a standard, so state it in your notes if you use it.
Sources
- Least Squares Moving Average (checked October 2026)
- Linear Regression channel and inputs (checked October 2026)
Related Topics
Related Articles
Understanding the Flag Pattern in Indian Markets
How to trade bullish and bearish flag patterns on Nifty, Bank Nifty and NSE stocks, with a worked example, costs, taxes and honest reliability data.
Understanding the Vertical Horizontal Filter in Indian Markets
Learn the Vertical Horizontal Filter formula with trending, ranging and zero-net examples, how the lookback changes the value, and what VHF cannot tell you.
Understanding Rights Issue in Indian Markets
What a rights issue is, how it works in India, how it affects the share price, a worked example, rights vs bonus issue, and mistakes shareholders make.
Understanding Stock Market Indices in Indian Markets
Learn what a stock market index is, how indices like Nifty 50 and Sensex are built, SEBI's role, and how traders use an index without common mistakes.
RSI 2 Period Strategy for Indian Markets
The RSI(2) mean reversion strategy for Indian markets: 200 DMA filter, exact entry and exit rules, and worked Reliance and Bank Nifty rupee examples.
Understanding Trading Psychology in Indian Markets
Learn trading psychology for Indian markets with a worked Nifty options example showing how fear and greed turned a Rs 3,120 loss into Rs 14,300.
The trading journal for Nifty, Bank Nifty and Indian F&O. Track your trades, spot patterns, build discipline.
- Log one trade a day by hand, on purpose
- AI mentor finds your repeat mistakes
- Behavioural analytics catch tilt early
- Trading calendar with P&L heatmap
- Pre-trade checklist flags risks
Yearly ₹3,499 · No broker credentials