An indicator only plots a line or fires an alert — an Expert Advisor (EA) actually sends orders on your behalf. This free EA trades a single, transparent trend-following strategy built entirely around SuperTrend: it enters the moment the SuperTrend line flips sides, sizes its Take Profit and position automatically, and manages one position at a time. Like this site's Parabolic SAR Trend EA, its Stop Loss isn't ATR-based at all — it's the SuperTrend line value itself, for reasons explained below.
How the Strategy Works
SuperTrend plots a single line that sits either below or above price, trailing the current trend — below and green during an uptrend, above and red during a downtrend. A "flip" happens when a closed bar's price crosses through the line and it switches to the other side; this EA treats that flip as its entire entry signal, exactly the way the site's own SuperTrend lesson describes it: a flip from above price to below price suggests the downtrend just ended and a new uptrend is starting, and the mirrored flip suggests the reverse.
There's no built-in SuperTrend function in either MetaTrader 4 or MetaTrader 5, so this EA reconstructs the full recursive band-and-trend calculation internally from High, Low, Close, and ATR — the same sequence covered in the indicator lesson — on every new bar, and checks the two most recently closed bars for a flip. It doesn't add any separate trend-strength filter on top of the flip; the flip itself, plus the risk controls covered below, is the entire signal.
Stop Loss, Take Profit, and Position Sizing
This is the section that matters most for understanding this particular EA. Most other EAs on this site size their Stop Loss from a separate ATRMultiplier × ATR calculation — a volatility-adaptive stop, but one frozen at the moment the trade opens. This EA does not do that, and it's not an oversight: SuperTrend's line is already an ATR-based, ratcheting trail by construction — it's built directly from Multiplier × ATR, and its ratchet logic already only tightens toward price, never widens away from it. Layering a second, separate ATR calculation on top would be redundant, answering a question SuperTrend's own line has already answered as part of the same calculation that produced the entry signal.
So when the EA opens a BUY on a bullish flip, the Stop Loss is placed exactly at the SuperTrend line value that triggered the flip — a level that's already positioned below the entry price by a distance shaped by current volatility. The mirrored logic applies to a SELL: the Stop Loss sits at the SuperTrend line value above the entry price. Take Profit is then set at a multiple of that Stop Loss distance — RiskRewardRatio, default 2.0 — so a 2.0 setting means the target sits twice as far from entry as the stop, keeping every trade's risk and reward in a fixed, known proportion regardless of how wide or narrow that particular SuperTrend-based stop happens to be.
Position size is calculated the same way as every other EA on this site: RiskPercent of account balance (default 1.0%) divided by the Stop Loss distance, converted through the symbol's tick value and normalized to the broker's lot step — the exact worked-example method from Risk Management Basics. A wider SuperTrend-based stop produces a smaller lot size, and a tighter one produces a larger lot size, so the dollar risk per trade stays consistent even though the stop distance itself varies from trade to trade. A UseFixedLot input with a FixedLotSize value is available as an escape hatch for traders who'd rather trade a constant lot size regardless of risk.
Entry Conditions
- BUY — the SuperTrend line flips from above price to below price on a newly completed bar; the Stop Loss is placed at that flipped line value.
- SELL — the SuperTrend line flips from below price to above price on a newly completed bar; the Stop Loss is placed at that flipped line value.
The EA evaluates these conditions once per new bar only (tracked against the time of the current bar's open), never on every tick, so a single flip can't fire multiple trades within the same candle. It opens at most one position at a time, counted and filtered by its own magic number, so it never confuses a position it opened with one you opened manually or one belonging to a different EA on the same account. Before opening anything, it also checks the current spread against MaxSpreadPoints and skips the entry entirely if the market is too illiquid at that moment.
Parameters
- ATRPeriod (default 10) — the lookback ATR is calculated over for the SuperTrend line's band width.
- Multiplier (default 3.0) — how many ATR-widths the SuperTrend line sits from the (High+Low)/2 midpoint before the ratchet logic is applied. A smaller value flips sides more often; a larger value holds a trend longer before flipping.
- RiskRewardRatio (default 2.0) — Take Profit distance = Stop Loss distance (from the SuperTrend line) × this ratio.
- RiskPercent (default 1.0) — percentage of account balance risked per trade, used to calculate lot size against the SuperTrend-based Stop Loss distance. Ignored if
UseFixedLotis enabled. - UseFixedLot (default false) — when enabled, trades a constant lot size instead of calculating one from
RiskPercent. - FixedLotSize (default 0.01) — the lot size used when
UseFixedLotis enabled. - MaxSpreadPoints (default 30) — skips new entries while the spread is wider than this, the same concern covered in Spread and Slippage.
- EnableTrading — a master on/off switch, useful for pausing the EA without removing it from the chart.
- MagicNumber (default 20260727) — tags every order this EA places so its position-counting and management logic never touches trades opened manually or by a different EA.
Notice what's missing compared to most of the site's other EAs: there is no separate ATRMultiplier for the Stop Loss itself. That's not a simplification or an oversight — it's the direct consequence of the design choice explained above and in the next section.
Why This EA Uses the SuperTrend Line Itself as the Stop, Not a Separate ATR Multiple
Most other EAs on this site — ea-trend-following included — calculate their Stop Loss as an independent ATRMultiplier × ATR, a fixed distance recalculated fresh at the moment each trade opens and then left alone for the rest of the trade's life. This EA works differently on purpose, and the difference is worth walking through concretely.
An independent ATR-based stop measures average volatility over a lookback period and gives you one number: how far away, in current market conditions, a stop "should" be at this instant, set once at entry. SuperTrend's own line does something similar but goes a step further — it produces a whole sequence of stop levels, one per bar, that ratchets tighter as the trend matures, since the Final Upper/Lower Band logic only ever moves in the direction that shrinks the trail. That's the entire mechanical idea behind the indicator: a fresh trend gets a band shaped by that moment's volatility, and as the trend runs, the ratchet locks in more of the open profit bar by bar without any separate trailing-stop routine layered on top. Reusing that same line as the Stop Loss means a trader managing the trade manually inherits a tightening stop for free — no extra ATR recalculation to keep in sync, no second indicator disagreeing with the first about how far away the stop should sit.
Installation and Setup
EAs install into a different folder than indicators — this is the step people miss most often.
- Download the file below for your platform.
- Open MetaTrader → click
File→Open Data Folder. - Place the file in
MQL4/Experts(MetaTrader 4) orMQL5/Experts(MetaTrader 5) — not the Indicators folder. - Restart MetaTrader, then drag the EA from the Navigator window onto a chart.
- Enable AutoTrading (MT4) or Algo Trading (MT5) in the toolbar — the EA will not place any trades while this is off, even if it's attached to a chart.
- Review and adjust the input parameters in the EA's settings dialog before confirming.
A Word of Caution
Test on a demo account first, across different market conditions and multiple pairs, before risking real money — a good backtest or demo run never guarantees future results. No strategy, automated or manual, wins every trade, and this EA can and will lose money on individual trades. Like Parabolic SAR, SuperTrend whipsaws badly in ranging or choppy markets: because the line is always positioned on one side of price and always flips when crossed, a sideways market forces it to flip back and forth repeatedly, generating a steady drip of false entries and small losses with no trend-strength filter to sit those periods out on its own. Consider combining it with a read of Trend vs Range or an ADX filter before enabling it on a live account. Both files are source code — open and review them fully, and understand what every parameter does, before using it. This content is general education, not personalized investment advice.
Download the EA
How to Install — MetaTrader 4
- Download the
supertrend-trend-ea.mq4file below. - Open MetaTrader 4 → click
File→Open Data Folder. - Place the file in the
MQL4/Expertsfolder. - Restart MetaTrader 4, then drag the EA from the Navigator window onto the chart.
How to Install — MetaTrader 5
- Download the
supertrend-trend-ea.mq5file below. - Open MetaTrader 5 → click
File→Open Data Folder. - Place the file in the
MQL5/Expertsfolder. - Restart MetaTrader 5, then drag the EA from the Navigator window onto the chart.
Both files are source code — open and review the full code before using it, for your own safety.