Overview
Free Supertrend Expert Advisor: enters on confirmed Supertrend flips, places the stop at the Supertrend line and can exit or trail on the line.
FXN Supertrend EA is a free, open-source Expert Advisor for MetaTrader 4 and MetaTrader 5 that trades Supertrend flips. It calculates the Supertrend itself, enters when the direction flips on a closed bar and uses the line as the stop, with no extra indicator files needed.
How it works
- Bands:
mid = (high + low) / 2,upper/lower = mid +/- multiplier x ATR; each band only tightens while price stays inside it. - The trend turns up when a bar closes above the upper band and down when a bar closes below the lower band. The EA rebuilds this from the last 300 closed bars at every new bar.
- Buy when the last closed bar flipped the trend up; sell when it flipped down.
- Stop loss at the Supertrend line of the signal bar. If the line is closer than
Min stop distance x ATR, the stop is placed that far from entry instead. - Exit: optional close on the opposite flip (the EA can then reverse on the same bar), optional stop trailing on the line, optional R target.
- Lot size (risk mode):
balance x risk % / money lost per lot at the stop, rounded down to the lot step.
Inputs
| Input | Default | What it does |
|---|---|---|
| Supertrend ATR period | 10 | ATR period of the Supertrend bands. |
| Supertrend multiplier | 3.0 | Band distance from the bar midpoint in ATRs. |
| Min stop distance (x ATR) | 0.5 | If the line is closer than this, the stop goes this far from entry. |
| Take profit (R) | 0.0 | Target = stop distance times this; 0 = no take profit. |
| Exit on opposite flip | true | Closes the trade when the Supertrend flips against it. |
| Trail stop on the line | false | Moves the stop to the Supertrend line at each new bar. |
| Use risk % sizing | true | true = lot from risk %; false = fixed lot. |
| Risk per trade (% of balance) | 1.0 | Balance share lost if the stop is hit. |
| Fixed lot | 0.10 | Lot used when risk sizing is off. |
| Magic number | 410103 | Identifies this EA's trades. |
| Max spread (points) | 30 | No entry above this spread; 0 = off. |
| Max slippage (points) | 10 | Allowed fill deviation. |
| Order comment | FXN SupertrendEA | Text saved on each order. |
| Use trading hours | false | Entries only inside the window; exits any time. |
| Start hour (0-23) | 7 | First hour with entries. |
| End hour (0-23) | 20 | Entries stop at this hour; may wrap past midnight. |
How to use it
- Copy
FXN_SupertrendEA.mq4toMQL4/Experts(MT4) orFXN_SupertrendEA.mq5toMQL5/Experts(MT5); File > Open Data Folder shows where. - Refresh the Navigator, drag the EA onto a chart and turn on AutoTrading (MT4) or Algo Trading (MT5).
- Suggested start: H1 or H4 on trending FX pairs, gold or indices, ATR 10, multiplier 3, exit on flip on, no fixed target, risk 0.5-1 %.
- Test in the Strategy Tester and on a demo account first.
Good to know
- It uses the platform's standard ATR (simple average), so values can differ slightly from Wilder-smoothed Supertrend versions.
- In ranges Supertrend flips back and forth and gives losing trades.
- After a strong move the line, and so the stop, can be far away; risk sizing then lowers the lot.
- Closed-bar signals that do not repaint; one entry per bar and one trade per symbol and magic number. No martingale, grid or averaging down.
- Stops respect broker stop and freeze levels. If risk sizing gives less than the minimum lot, the trade is skipped and logged. On MT5 netting accounts it will not trade a symbol that already has another position.
Trading carries risk. Test on a demo account first; past results do not predict future results.
At a glance
- What it is
- A free Expert Advisor for MetaTrader 4, written in MQL4.
- What it does
- Free Supertrend Expert Advisor: enters on confirmed Supertrend flips, places the stop at the Supertrend line and can exit or trail on the line.
- Shared by
- Alex
- Licence
- MIT
- Version
- 1.0 (1 Dec 2026)
- Settings
- 21 inputs
- Lab check
- Compiled with MetaEditor build 2425 for MT4 on 1 Dec 2026: 0 errors, 0 warnings.
- Price
- Free to download
Settings read from the code
| Input | Type | Default | Note |
|---|---|---|---|
| InpSep1 | string | ===== Supertrend ===== | |
| InpStAtrPeriod | int | 10 | Supertrend ATR period |
| InpStMultiplier | double | 3.0 | Supertrend multiplier |
| InpSep2 | string | ===== Stop, target and exit ===== | |
| InpMinStopAtr | double | 0.5 | Min stop distance (x ATR) |
| InpTargetR | double | 0.0 | Take profit (R) |
| InpExitOnFlip | bool | true | Exit on opposite flip |
| InpTrailOnLine | bool | false | Trail stop on the line |
| InpSep3 | string | ===== Lot size and risk ===== | |
| InpUseRiskPercent | bool | true | Use risk % sizing |
| InpRiskPercent | double | 1.0 | Risk per trade (% of balance) |
| InpFixedLot | double | 0.10 | Fixed lot |
| InpSep4 | string | ===== Orders and filters ===== | |
| InpMagic | int | 410103 | Magic number |
| InpMaxSpreadPoints | int | 30 | Max spread (points) |
| InpSlippagePoints | int | 10 | Max slippage (points) |
| InpOrderComment | string | FXN SupertrendEA | Order comment |
| InpSep5 | string | ===== Trading hours (server time) ===== | |
| InpUseTradingHours | bool | false | Use trading hours |
| InpStartHour | int | 7 | Start hour (0-23) |
| InpEndHour | int | 20 | End hour (0-23) |
How to use it
- Download the compiled file (or the source and compile it in MetaEditor).
- Put it in MetaTrader: File → Open Data Folder → MQL4 → Experts, then refresh the Navigator.
- Test it on a demo account before any real money.
- Want changes? Open a copy in your Lab and ask for them in plain words.