Auto Trend Lines Indicator: Swing-Anchored Support Lines

Written by Dominic Walsh · Published · Last updated

The auto trend lines indicator draws two sloped lines and nothing else. Resistance anchors to the two most recent swing highs and Support to the two most recent swing lows. Both project forward at the slope those anchors define.

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: Resistance, Support
Alerts popup, push notification, email, sound
Inputs 9

What the Auto Trend Lines Indicator draws on the chart

Resistance (tomato) runs through the two newest qualifying swing highs.

Support (sea green) does the same across the two newest swing lows.

No markers of any kind appear. This build declares two line plots and stops there.

  • Resistance: line, tomato, width 2
  • Support: line, medium sea green, width 2
EURUSD H1: the auto trend lines indicator projecting Resistance and Support from recent swings.
EURUSD H1: the auto trend lines indicator projecting Resistance and Support from recent swings.

How the Auto Trend Lines Indicator calculates its values

Qualifying a swing

A helper checks whether a bar beats every neighbour within SwingDepth on both sides. Only bars passing that test enter the search.

The scan walks back from the newest bar and stops as soon as it has two highs and two lows, so it always works from the freshest structure available.

Slope and intercept

For each side the code divides the price difference between the two anchors by the bar distance between them. That gives the slope.

An intercept follows from the newer anchor and its bar position. Together they define a line value for any bar on the chart, including bars ahead of both anchors.

How far back the search runs

MaxLookback caps the search at 400 bars by default, trimmed further if the chart holds less history than that.

That cap keeps the lines anchored to recent structure. Without it the scan could reach back to swings that stopped mattering long ago.

How to read the signals

Both lines describe recent structure rather than predicting anything. They move whenever a fresher swing qualifies.

Converging lines mean the recent highs and lows are closing in on each other.

A line far from price usually means its two anchors sit close together in time, which makes the projected slope steep.

Nothing appears until two qualifying swings exist on that side.

Alert channels in this build: popup, push notification, email and sound.

Alerts cover popup, push, email and sound. This build carries no once-per-bar guard, so a condition can alert more than once while a bar is still forming.

Every Auto Trend Lines Indicator input

Core settings

Setting What it does Default
SwingDepth SwingDepth is how many bars either side a swing point has to beat. It defaults to 5, and larger values pick out bigger structure. 5
MaxLookback MaxLookback caps how far back the search runs, 400 bars by default. 400

Display settings

Setting What it does Default
ArrowOffsetPoints (see inputs panel) 30

Alert settings

Setting What it does Default
EnableAlerts EnableAlerts gates the message block and defaults to true. on
EnablePopup EnablePopup shows the MT4 dialog and defaults to true, making it the one channel active out of the box. on
EnablePushNotify (see inputs panel) off
EnableEmail (see inputs panel) off
EnableSound (see inputs panel) off
SoundFile (see inputs panel) alert.wav
Inputs panel for the auto trend lines indicator showing SwingDepth and MaxLookback.
Inputs panel for the auto trend lines indicator showing SwingDepth and MaxLookback.

Settings that fit your chart

The screenshot uses EURUSD H1. Four hundred bars on H1 covers a few weeks, which anchors the lines to structure a swing trader would recognise. On H4 and daily the same lookback reaches back months. Below M15 a SwingDepth of 5 qualifies bars inside ordinary noise, so raising it helps.

When the Auto Trend Lines Indicator fails

Two anchors define a straight line whether or not those two swings belong together. Nothing here judges that.

Both lines redraw as soon as a fresher swing qualifies, so a level you were watching can move without warning.

A projected line drifts a long way from price once it extends well past its anchors.

ArrowOffsetPoints appears among the inputs, but this build declares no marker buffers, so changing it does nothing visible.

Copy the compiled Auto Trend Lines 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.

Background reading on the method behind the Auto Trend Lines Indicator: Chande Trend Meter Ctm at StockCharts ChartSchool, Flag and pennant patterns on Wikipedia.

Download the Auto Trend Lines Indicator for MT4 and MT5

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

How does SwingDepth decide a bar is a swing high?

It checks whether that bar beats every neighbour within SwingDepth on both sides. At the default of 5 a bar has to be the highest across eleven bars in total. Only bars passing the test can anchor the Resistance line.

What does MaxLookback 400 limit?

It caps how far back the search for anchors runs. The scan walks from the newest bar and stops once it has two highs and two lows, so the cap mainly matters on quiet charts where qualifying swings are sparse. It also trims itself on short histories.

Does the Support line ever stop moving?

Only while no fresher swing low qualifies. As soon as one does, it replaces the newer anchor and the slope changes from that bar onward. On a trending chart that happens regularly, so treat the line as a description of current structure.

Why does ArrowOffsetPoints have no effect?

This build declares two line plots and no marker buffers at all, so there is nothing for that input to position. It sits in the input list without a job. Only SwingDepth and MaxLookback change what you actually see.

Are results guaranteed?

No. Trading involves risk. Results are not guaranteed; past performance is not indicative of future results. Use the Auto Trend Lines 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

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