The linear regression line indicator fits a straight line through the last `LRLength` closes and plots it. What it watches, though, is not the line itself but the direction that line is moving. When today’s slope disagrees with the slope `SlopeChangeBars` bars ago, a marker goes on the chart.
This build ships as a compiled .ex4 for MT4 and .ex5 for MT5; the screenshots below come from EURUSD H1.
| Platforms | MT4 (.ex4) + MT5 (.ex5) |
|---|---|
| Chart window | Main price chart |
| Plots | 2: LR Line, Slope Arrow |
| Alerts | popup, push notification, email, sound |
| Inputs | 17 |
What the Linear Regression Line Indicator draws on the chart
LR Line is the deep sky blue least-squares fit through the window.
Slope Arrow is a single orange marker placed at each slope flip.
The marker sits below the bar for an upward flip and above it for a downward one.
An OBJ_LABEL panel reports the current slope reading in the chart corner.
- LR Line: line, deep sky blue, width 2
- Slope Arrow: arrow, orange, width 1, arrow code 233

How the Linear Regression Line Indicator calculates its values
Solving the fit
LinReg walks the window oldest to newest, accumulating sumXX and sumXY. denom takes n times sumXX minus sumX squared. When that value falls near zero the code returns the close and a slope of zero rather than dividing by nothing.
Measuring the slope twice
curr_slope takes the line value at this bar minus the value one bar back. prev_slope does the same thing `SlopeChangeBars` `3` bars earlier. Comparing two slopes rather than one avoids marking every small wobble in the fit.
One buffer, two placements
Slope Arrow is a single plot. An upward flip writes low minus twelve points, and a downward flip writes high plus twelve. So the marker position tells you the direction, since the symbol itself does not change.
How to read the signals
The blue line is the straight-line summary of the last `LRLength` closes.
A marker below the bar is an upward slope flip.
A marker above the bar is a downward one.
The line refits on every bar, so its whole position shifts as the window rolls.
Alert channels in this build: popup, push notification, email and sound, one message per closed bar.
`EnableAlerts` ships on and `EnablePopup` delivers the text. `EnablePushNotify`, `EnableEmail` and `EnableSound` all start false. `SoundFile` picks the clip. The slope comparison runs on completed bars, and the guard allows one message per closed bar.
Every Linear Regression Line Indicator input
Core settings
| Setting | What it does | Default |
|---|---|---|
LRLength |
regression window (default 100). Bars in the regression window, default `100`. | 100 |
SlopeChangeBars |
bars used to test slope-flip. Bars back the slope is compared against, default `3`. | 3 |
StatsX |
Panel horizontal offset, default `12`. | 12 |
StatsY |
Panel vertical offset, default `22`. | 22 |
Display settings
| Setting | What it does | Default |
|---|---|---|
ShowSlopeArrow |
Draws the flip markers, default `true`. | on |
ShowStatsPanel |
Draws the corner readout, default `true`. | on |
StatsCorner |
0=TL 1=TR 2=BL 3=BR. Panel corner, default `1` for top right. | 1 |
PanelTextColor |
(see inputs panel) | white |
PanelTitleColor |
(see inputs panel) | aqua |
PanelFontSize |
Panel font size, default `9`. | 9 |
PanelFont |
Panel font, default Consolas. | Consolas |
Alert settings
| Setting | What it does | Default |
|---|---|---|
EnableAlerts |
Master switch over the slope-flip alerts, default `true`. | on |
EnablePopup |
Terminal dialog on a slope flip, default `true`. | on |
EnablePushNotify |
Mobile push on a slope flip, default `false`. | off |
EnableEmail |
Mail delivery on a slope flip, default `false`. | off |
EnableSound |
Sound playback on a slope flip, default `false`. | off |
SoundFile |
Wav file the slope alert plays, default `alert.wav`. | alert.wav |

Settings that fit your chart
A straight-line fit describes markets that move in reasonably straight legs. EURUSD H1 is the reference chart, where `LRLength` at `100` covers about four days. On M5 the window spans a few hours and the line reorients constantly. On H4 the same setting describes several weeks of structure.
When the Linear Regression Line Indicator fails
A straight line is a poor model for a market that turns, because the fit averages both legs.
The whole line repositions as the window rolls, so a reading from yesterday no longer applies.
`SlopeChangeBars` `3` is a short comparison, which lets small wobbles register as flips.
Copy the compiled Linear Regression Line Indicator file into your MQL4/Indicators folder, and the MT5 build into MQL5/Indicators, then restart the terminal and drag it onto a chart. The step-by-step guide with screenshots is at how to install MT4 and MT5 indicators.
Download the Linear Regression Line Indicator for MT4 and MT5
The zip holds the compiled Linear Regression Line Indicator build for MT4 and MT5, plus a short README. Compiled files only, no source. Enter your email below and the download link arrives in your inbox.
Download this indicator free
Enter your email and the file is yours. You also get the full MT4 and MT5 library.
FAQ
What does SlopeChangeBars at 3 compare?
Two slope readings three bars apart. curr_slope covers the last bar of the line and prev_slope covers the equivalent step three bars earlier. Requiring those two to disagree filters out the single-bar wobbles a rolling fit produces constantly.
Why does LRLength default to 100?
It is long enough for the fit to describe a real leg and short enough to react within a few days on H1. Shorten it and the line follows price closely, which produces many more slope flips. Lengthen it for a steadier direction reading.
Does the Slope Arrow plot change symbol?
No, there is only one arrow buffer and one symbol. Direction comes from where the marker sits. Below the bar means the slope flipped upward, above it means downward. Turn `ShowSlopeArrow` off if you would rather read the line alone.
What is in the ShowStatsPanel readout?
The current slope reading, drawn in the corner set by `StatsCorner`. It is useful because a slope near zero looks identical to a modest one on the chart. Set `ShowStatsPanel` to false and nothing about the calculation changes.
Are results guaranteed?
No. Trading involves risk. Results are not guaranteed; past performance is not indicative of future results. Use the Linear Regression Line Indicator as one input. Always backtest before trading live.
Category: this is part of our Trend collection. Also, truly, browse more Trend for MetaTrader, or explore every MT4 indicator and MT5 indicator on the site.
External references
- For background on this concept, see Linear Regression Forecast at StockCharts ChartSchool.
- For broader market context, see Green trading on Wikipedia.
