Trend Line Indicator for MT4 and MT5

Written by Dominic Walsh · Published · Last updated

Two lines is the whole output. The trend line indicator connects the last pair of falling highs and the last pair of rising lows, then runs both out to the right edge of the chart. When a close crosses either one, a mark prints. Nothing else competes for your attention.

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: Trend Line Break Up, Trend Line Break Down
Alerts popup, push notification, email, sound
Inputs 13

On screen

Two arrow plots plus two chart lines.

`Trend Line Break Up` uses arrow 233 in dodger blue.

`Trend Line Break Down` uses arrow 234 in orange red.

`UpLineColor` draws the rising line dodger blue.

`DownLineColor` draws the falling one orange red.

`LineWidth` `2` sets both.

  • Trend Line Break Up: arrow, dodger blue, width 2, arrow code 233
  • Trend Line Break Down: arrow, orange red, width 2, arrow code 234
trend line indicator: Both lines extended and a break mark on the EURUSD H1 chart.
Both lines extended and a break mark on the EURUSD H1 chart.

Working through the maths

Fractal pivots

One rule finds them. `FractalDepth` `5` bars either side must stay lower than a high. The same test upside down finds the lows.

One line per side

Only the newest pair counts. Two falling highs give the upper line, two rising lows the lower. `AutoExtend` runs both to the right edge.

The break mark

It compares two bars. A close above the falling line with the bar before below it prints the mark. The range reading at `AtrPeriod` `14` sets how far off the candle it sits.

Using it on a chart

Two lines only, so the chart stays readable.

Both extend forward until new pivots replace them.

A break of the falling line is the upside event.

Line slope tells you how steep the structure is.

`ArrowOffsetATR` `0.6` scales the mark to the range.

The tool draws nothing in a separate pane.

Alert channels in this build: popup, push notification, email and sound, one message per closed bar.

`EnableAlerts` sits over the break alerts and arrives true with `EnablePopup`. Switch `EnablePushNotify` for a phone, `EnableEmail` for mail, or `EnableSound` to play `SoundFile`. Those three arrive off and breaks wait for a close.

Every Trend Line Indicator input

Core settings

Setting What it does Default
FractalDepth bars each side that define a swing pivot. Bars each side of a pivot, `5`. 5
AutoExtend extend both trend lines to the right edge. Run lines to the right edge, `true`. on
AtrPeriod ATR period for arrow offset. Bars behind the range figure, `14`. 14

Display settings

Setting What it does Default
ArrowOffsetATR arrow gap from bar in ATR units. Mark gap in ranges, `0.6`. 0.6
UpLineColor Rising line colour, `clrDodgerBlue`. dodger blue
DownLineColor Falling line colour, `clrOrangeRed`. orange red
LineWidth Line thickness, `2`. 2

Alert settings

Setting What it does Default
EnableAlerts Master switch, `true`. on
EnablePopup (see inputs panel) on
EnablePushNotify (see inputs panel) off
EnableEmail Mail on a break, `false`. off
EnableSound (see inputs panel) off
SoundFile Which clip plays, `”alert.wav”`. alert.wav
trend line indicator: Inputs panel with FractalDepth, AutoExtend and ArrowOffsetATR.
Inputs panel with FractalDepth, AutoExtend and ArrowOffsetATR.

Timeframe and symbol

A five-bar fractal is quick, so lines refresh often. EURUSD H1 is the reference chart. A line there lasts a day or so before new pivots replace it. On M5 they change constantly. On H4 each pair holds for weeks.

When not to trust the output

Only the newest pivot pair counts, so older structure gets dropped.

Each line arrives five bars after its pivot.

A five-bar pivot is a small piece of structure.

A break can reverse straight back through the line.

Copy the compiled Trend 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 Trend Line Indicator for MT4 and MT5

The zip holds the compiled Trend 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.

  • 1,380+ indicators
  • MT4 and MT5 files
  • No spam, unsubscribe any time

FAQ

Why keep only one line per side?

To keep the chart readable. Two lines drawn from the newest pivot pairs describe the current structure, and older lines are dropped rather than accumulated, which is the opposite trade-off from a multi-line tool.

What does AutoExtend true do to a line?

It runs the line out to the right edge of the chart instead of stopping at the second pivot. The prices along it stay the same; only the drawn length changes, which makes an approaching break visible.

How does FractalDepth 5 confirm a pivot?

Five bars either side must stay below the high in question, a ten-bar window in total. That means a pivot is recognised five bars after it printed, and the line built from it appears then too.

Why scale the mark with ArrowOffsetATR?

So arrows stay clear of the candle on any symbol. Six tenths of the current range reading places them further out in a busy market, which a fixed point offset cannot manage.

Are results guaranteed?

No. Trading involves risk. Results are not guaranteed; past performance is not indicative of future results. Use the Trend Line Indicator as one input. Always backtest before trading live.

Category: this is part of our Support and Resistance collection. Browse more Support and Resistance for MetaTrader, or explore every MT4 indicator and MT5 indicator on the site.

External references

Dominic Walsh - Forex trader and MT4/MT5 developer

About the author

Written by Dominic Walsh, a Forex trader and MT4/MT5 indicator, Expert Advisor and script developer. Every tool on forexmt4systems.com is tested on live charts before release and ships with ready-to-use compiled MT4 (.ex4) and MT5 (.ex5) files. Learn more about the trader and developer behind this site.

How we build, test and correct every tool: Editorial & Testing Policy. Trading carries risk; see the disclaimer.

Leave a Comment