Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mt5-ea-framework

A risk-managed Expert Advisor framework for MetaTrader 5, built around a hard separation between what triggers a trade and how much gets risked on it. Ships with three interchangeable entry strategies (EMA cross, Donchian breakout, RSI mean-reversion) over one shared risk engine.

Problem

Most EA requests on freelance boards fall into one of two buckets: a finished strategy with no risk framework around it (fixed lot size, no volatility adjustment, no trailing logic), or a risk framework so tangled into one specific signal that swapping the signal means rewriting the EA. Clients end up paying twice — once for the signal, again when they want a second one and the "EA" turns out to be one file that has to be gutted.

Solution

RiskManager.mqh owns position sizing, open-position tracking, and ATR trailing. EntrySignals.mqh owns exactly one thing — producing SIGNAL_BUY / SIGNAL_SELL / SIGNAL_NONE for the current closed bar. Neither file imports anything from the other's concern. Adding a fourth entry strategy is a new method on CEntrySignals; changing how risk is sized is a change to CRiskManager that every entry strategy gets for free.

Architecture

flowchart LR
    subgraph EA["MultiStrategyEA.mq5"]
        direction TB
        OnTick["OnTick()"] --> Trail["riskManager.ApplyTrailing()"]
        Trail --> HasPos{"riskManager.\nHasOpenPosition()?"}
        HasPos -- no --> Eval["entrySignals.Evaluate()"]
        HasPos -- yes --> Skip["skip -- one position\nper symbol/magic"]
        Eval --> Signal{signal}
        Signal -- BUY/SELL --> Size["riskManager.LotByRisk(atr * slMult)"]
        Size --> Order["trade.Buy() / trade.Sell()"]
        Signal -- NONE --> Skip
    end

    subgraph Entry["EntrySignals.mqh"]
        EmaCross["ENTRY_EMA_CROSS"]
        Breakout["ENTRY_BREAKOUT"]
        RsiRev["ENTRY_RSI_REVERSION"]
    end

    Eval -.selected by InpEntryMode.-> Entry
Loading

The EA itself (Source/MultiStrategyEA.mq5) is under 150 lines because it only wires the two modules together — bar-close detection, spread filter, and the input declarations.

Installation

  1. Copy Include/RiskManager.mqh and Include/EntrySignals.mqh into MQL5/Include/ (or keep the repo's relative layout — the EA includes them via ..\Include\...).
  2. Copy Source/MultiStrategyEA.mq5 into MQL5/Experts/.
  3. Open it in MetaEditor and compile (F7).
  4. Attach to a chart, or load one of the presets under Examples/ in the Strategy Tester (Inputs tab → Load).

Configuration

Input Group Purpose
InpEntryMode Entry ENTRY_EMA_CROSS / ENTRY_BREAKOUT / ENTRY_RSI_REVERSION
InpFastPeriod, InpSlowPeriod Entry EMA cross periods
InpDonchianPeriod Entry Breakout channel length (bars before the signal bar)
InpRsiPeriod, InpRsiOversold, InpRsiOverbought Entry RSI reversion thresholds
InpRiskPercent Risk % of equity risked per trade
InpAtrMultSL, InpRewardRiskRatio Risk Stop distance and TP as ATR/SL multiples
InpMaxLot, InpMaxSpreadPts Risk Hard caps regardless of the risk calculation
InpUseTrailing, InpTrailAtrMult, InpTrailStepPts Trailing ATR trailing stop, only tightens

Three ready-to-load presets are in Examples/:

File Mode Symbol / TF Notes
EmaCross_EURUSD_H1.set EMA cross EURUSD H1 Baseline settings
Breakout_XAUUSD_H4.set Breakout XAUUSD H4 Wider stop, lower risk % for gold's larger ATR
RsiReversion_GBPUSD_M15.set RSI reversion GBPUSD M15 Tighter spread cap for a faster timeframe

Validating a change

There is no headless MQL5 compiler, so CI (.github/workflows/ci.yml) only runs a static structure check — balanced braces/parens, no stray TODOs. It is not a substitute for compiling in MetaEditor and running the Strategy Tester, which CONTRIBUTING.md covers.

Contributing

See CONTRIBUTING.md.

License

MIT — see LICENSE.

About

Risk-managed MT5 Expert Advisor framework with three swappable entry strategies over one risk engine

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages