SuperTrend Follower EA
SuperTrend is a widely used trend-following overlay that most platforms ship as a native indicator. MQL4 does not, so this EA computes it by hand from Average True Range using the standard textbook recurrence: an upper and lower band scaled by ATR, each of which is only allowed to move in the direction that favours the current trend, with a flip triggered the moment price closes through the band on the wrong side. The recurrence needs a run of prior bars to settle before its output means anything - the very first band value in a short history is just a guess. Rather than cache state across ticks and risk it going stale after a terminal reconnect or a history reload, the EA recomputes the whole recurrence from InpLookbackBars closed bars every time a new bar forms. That is more arithmetic than strictly necessary, but it is simple, it cannot drift out of sync with the chart, and the extra cost is invisible next to network latency. Like the SAR-flip reference EA in this catalogue, the exit is the next flip, not a fixed take profit - the band is the whole risk-management mechanism this system is built around. Position sizing can run as a fixed lot or, with InpUseRiskSizing on, as a percentage of equity risked to the band-derived stop distance, using MODE_TICKVALUE and MODE_TICKSIZE rather than a hardcoded contract size so it prices correctly on gold, indices and JPY crosses as well as plain FX pairs. Notes and limitations - No trend or volatility filter beyond the band itself. In a ranging market it will flip repeatedly and pay the spread each time - that is the well-documented weakness of trading raw SuperTrend, not a bug in this implementation. - Signals are evaluated once per closed bar, not on every tick, so the chart period you attach it to controls how often it can react. - The recurrence is recomputed from InpLookbackBars on every closed bar. If the chart does not have that many bars of history yet, the EA waits silently rather than trading on an unsettled band. - One position at a time, tracked by InpMagicNumber. It will not manage or interfere with trades opened manually or by another EA. - On the MQL5 build, entries refuse on a netting account if the chart symbol already carries a position under a different magic number - see MQL4 VERSUS MQL5 DIFFERENCES above.
Expert advisor · MT4 · v1.0 · Free
About SuperTrend Follower EA
SuperTrend Follower EA is an expert advisor (trading robot) for MetaTrader 4 based on ATR. It increases the lot size after a losing trade (martingale) and can size trades from your balance and risk percent. It has 10 settings, such as Atr period, Multiplier and Lookback bars. MQL source code included.
Files in the download: SuperTrendEa.ex4, SuperTrendEa.mq4, SuperTrendEa.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Atr period | 10 | ATR period used to size the bands |
| Multiplier | 3.0 | Band distance, in ATR multiples |
| Lookback bars | 150 | Bars walked forward to let the recurrence settle |
| Use risk sizing | false | Size by percent risk instead of a fixed lot |
| Risk percent | 1.0 | Percent of equity risked per trade, when risk sizing is on |
| Fixed lots | 0.10 | Lot size when risk sizing is off, or as a fallback |
| Magic number | 20260602 | Magic number for orders opened by this EA |
| Slippage pips | 3 | Slippage tolerance, in pips |
| Max retries | 5 | Attempts per trade action before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Experts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: ATR · Trend · Martingale · Risk & Lot Size · MT4 Expert Advisor · MQL4 Source Code