← All projects

Multi-Timeframe EMA/SuperTrend EA for MT4 and MT5

An EA for MT4 and MT5 that chains an H1 EMA cross, an M5 pullback and an M1 SuperTrend entry, and manages up to 20 trade sequences.

Client
FX trader with a written strategy spec
Year
2026
Category
Trading Systems
Stack
  • MQL5
  • MQL4
  • MetaTrader 5
  • MetaTrader 4
  • Pine Script

The problem

The client had a 20-page strategy document and wanted it automated on both MetaTrader 4 and MetaTrader 5, with identical behaviour on each. The SuperTrend used by the strategy had to match the TradingView version exactly.

What I built

  • SuperTrend indicator for MT4 and MT5, ported from the Pine Script reference. It exposes trend direction and signal buffers to the EA, with Wilder or simple ATR to match TradingView’s two modes.
  • Four-step setup pipeline: H1 EMA 13/62 crossover → H1 touch of the fast EMA → M5 SuperTrend counter-signal (the pullback) → M1 SuperTrend entry. All timeframes are inputs.
  • Pivot-flip engine: once a trade is open, a pivot line is placed. The position reverses whenever the entry-timeframe fast EMA crosses the pivot, until the target is hit.
  • Sequence manager: up to 20 concurrent sequences, each moving from pending to active to completed, with its own magic number.
  • Lot progression: linear add-up after N flips by default, with a multiplier mode as an option. Caps on max flips, max lot and max drawdown per sequence, and a daily stop after N targets.
  • Targets: fixed pips or an ATR multiple.
  • Weekend management: a Friday close hour, a P&L check hours before the close, and a wait-for-breakeven window.
  • Chart dashboard with sequence status, and a visuals-off switch for fast backtests.

Details

  • Porting between platforms: MQL4 uses series indexing (0 = newest bar) and MQL5 in this port uses chronological indexing (0 = oldest). Every [i±1] bar reference had to be mirrored between the two versions.
  • ECN brokers: if an order with a target attached is refused, the EA opens it first and then modifies it to add the target.
  • Crash recovery: sequence state (state, pivot, flip count) is persisted in terminal global variables, so a terminal restart doesn’t orphan open sequences.