- Strategy
- Buys when the Supertrend flips from down to up on a closed bar and sells when it flips from up to down. The stop-loss sits at the Supertrend line and can trail along it.
- Risk model
- 1% of balance per trade (configurable), stop-loss on every order, one position at a time
What it does
The Supertrend EA trades the classic ATR-based Supertrend. When the indicator flips from a downtrend to an uptrend it buys, and when it flips the other way it sells. The Supertrend line itself becomes the stop-loss, which gives each trade a logical invalidation point that adapts to volatility.
With trailing on, the stop follows the line as the trend develops.
How it works
The EA rebuilds the Supertrend from the last 300 closed bars each time a new bar opens, using the published formula:
- Midpoint = (high + low) ÷ 2. Lower band = midpoint - multiplier x ATR, upper band = midpoint + multiplier x ATR.
- The lower band only rises while the previous close is above it; the upper band only falls while the previous close is below it.
- The trend turns up on a close above the previous upper band and down on a close below the previous lower band. The line is the lower band in an uptrend, the upper band in a downtrend.
- Entry: trend up on the last closed bar and down on the bar before (or the reverse for a sell).
- Stop-loss: the Supertrend line of the signal bar, plus an optional buffer in points. If that is more than 5 x ATR away, the signal is skipped and logged.
- Trailing: on every tick the stop is raised (or lowered for sells) to the latest closed-bar line, never moved backwards.
- Exit: if the trend turns against the position at a bar close, the position is closed.
How to use it
Supertrend works best in sustained swings, such as major pairs and gold on H1 or H4. With no fixed target by default, results rely on a few long trends offsetting many small losses, so judge it on a large sample of trades.
A lower multiplier reacts faster; a higher one filters more noise.
Settings
| Input | Default | What it changes |
|---|---|---|
| ATR period | 10 | ATR length used to build the Supertrend bands. |
| Supertrend ATR multiplier | 3.0 | Band distance from the bar midpoint, in ATRs. |
| Take-profit (R multiple) | 0.0 | Optional fixed target; 0 lets the trailing line and flips manage the exit. |
| Maximum stop (x ATR) | 5.0 | Skips a flip if the line is unusually far from price. |
| Use trailing stop | true | Moves the stop to the Supertrend line as it advances. |
| Bars used to rebuild the Supertrend | 300 | History used for the recursive calculation. |
| Extra stop buffer (points) | 0 | Places the stop slightly beyond the line. |
| Exit on flip | true | Closes the trade when the Supertrend turns against it. |
| Risk per trade (% of balance) | 1.0 | Share of balance risked between entry and stop. |
| Fixed lots | 0 | Fixed volume instead of risk %; 0 = risk-based. |
| Maximum spread (points) | 20 | Skips signals when the spread is wider; 0 = off. |
| Trading start / end hour | 7 / 20 | Server-time window for new trades; equal values = 24 hours. |
| Move stop to break-even | true | Stop to entry + 20 points once profit reaches 1R. |
| Magic number | 2611002 | Identifies this EA's trades. |
Limitations
- Supertrend is a lagging indicator; flips often happen after a sizeable part of the move.
- In choppy, range-bound markets flips come in quick succession and produce a run of losing trades.
- The stop at the line can be wide after a strong bar, which reduces position size or causes the trade to be skipped.
- MetaTrader's built-in ATR is used, so values can differ slightly from versions with other ATR smoothing.
Before you run it live
Test on a demo account and in the MetaTrader 5 Strategy Tester over several years first. No backtest results are published for this EA, and any test describes the past only.
- Match the spread limit and trading hours to your broker's spreads, stop level and session times, and include commission and swap in tests.
- Start with 1% risk or less and check the lot sizes in the Experts log; the Position Size Calculator is a useful cross-check.
- Use a different magic number on each chart, and keep the terminal (or a VPS) running so stops are managed.
Compare tester runs with trailing on and off.

