Skip to content
FXNook HubBeta

Alex / Supertrend EA for MT5

MetaTrader 5Expert AdvisorMITCompiled · build 6333
AlexFirst version.build 6333v1.05 hours ago1 version
  • FXN_SupertrendEA.mq5First version.22 KB
  • FXN_SupertrendEA.ex5Compiled by the Lab with MetaEditor build 633342 KB
README

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

InputDefaultWhat it does
Supertrend ATR period10ATR period of the Supertrend bands.
Supertrend multiplier3.0Band distance from the bar midpoint in ATRs.
Min stop distance (x ATR)0.5If the line is closer than this, the stop goes this far from entry.
Take profit (R)0.0Target = stop distance times this; 0 = no take profit.
Exit on opposite fliptrueCloses the trade when the Supertrend flips against it.
Trail stop on the linefalseMoves the stop to the Supertrend line at each new bar.
Use risk % sizingtruetrue = lot from risk %; false = fixed lot.
Risk per trade (% of balance)1.0Balance share lost if the stop is hit.
Fixed lot0.10Lot used when risk sizing is off.
Magic number410103Identifies this EA's trades.
Max spread (points)30No entry above this spread; 0 = off.
Max slippage (points)10Allowed fill deviation.
Order commentFXN SupertrendEAText saved on each order.
Use trading hoursfalseEntries only inside the window; exits any time.
Start hour (0-23)7First hour with entries.
End hour (0-23)20Entries stop at this hour; may wrap past midnight.

How to use it

  1. Copy FXN_SupertrendEA.mq4 to MQL4/Experts (MT4) or FXN_SupertrendEA.mq5 to MQL5/Experts (MT5); File > Open Data Folder shows where.
  2. Refresh the Navigator, drag the EA onto a chart and turn on AutoTrading (MT4) or Algo Trading (MT5).
  3. 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 %.
  4. 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 5, written in MQL5.
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
16 inputs
Lab check
Compiled with MetaEditor build 6333 for MT5 on 1 Dec 2026: 0 errors, 0 warnings.
Price
Free to download

Settings read from the code

InputTypeDefaultNote
InpStAtrPeriodint10Supertrend ATR period
InpStMultiplierdouble3.0Supertrend multiplier
InpMinStopAtrdouble0.5Min stop distance (x ATR)
InpTargetRdouble0.0Take profit (R)
InpExitOnFlipbooltrueExit on opposite flip
InpTrailOnLineboolfalseTrail stop on the line
InpUseRiskPercentbooltrueUse risk % sizing
InpRiskPercentdouble1.0Risk per trade (% of balance)
InpFixedLotdouble0.10Fixed lot
InpMagiculong410103Magic number
InpMaxSpreadPointsint30Max spread (points)
InpSlippagePointsint10Max slippage (points)
InpOrderCommentstringFXN SupertrendEAOrder comment
InpUseTradingHoursboolfalseUse trading hours
InpStartHourint7Start hour (0-23)
InpEndHourint20End hour (0-23)

How to use it

  1. Download the compiled file (or the source and compile it in MetaEditor).
  2. Put it in MetaTrader: File → Open Data Folder → MQL5 → Experts, then refresh the Navigator.
  3. Test it on a demo account before any real money.
  4. Want changes? Open a copy in your Lab and ask for them in plain words.