Divergence Trader
This EA trades based on the divergence between a fast and slow Simple Moving Average. It opens buy positions when divergence is positive within a defined range and sell positions when divergence is negative within a mirrored range. It includes trailing stop, breakeven, basket profit/loss closing, and multi-lot position scaling features.
Open the interactive view (equity curve, symbol switch)Key facts
Backtest results (H1, about 1 year)
| Symbol | P&L | Annual | Max DD | Trades | Win rate | Sharpe | Recovery | Losing streak | Per trade | Status |
|---|---|---|---|---|---|---|---|---|---|---|
| EURUSD | 0.00% | 0.00% | 0.00% | 0 | — | — | — | — | — | Not convertible yet |
| GBPUSD | 0.00% | 0.00% | 0.00% | 0 | — | — | — | — | — | Not convertible yet |
| USDJPY | 0.00% | 0.00% | 0.00% | 0 | — | — | — | — | — | Not convertible yet |
| XAUUSD | 0.00% | 0.00% | 0.00% | 0 | — | — | — | — | — | Not convertible yet |
Why this EA never traded: no entry rule survived the conversion.
Converted from MQL5 to Python and run with the same rules for every EA. Positions use MT5 lot sizes (100,000 units per FX lot, 100 oz per gold lot) with 1:100 leverage, one order at a time, and a stop-out below 10% of the starting balance. Sharpe is computed from the equity curve. Results marked as unreliable are shown for completeness only.
Blow-up risk: No blow-up pattern found
None of the usual blow-up patterns were found in the code, and the account was not stopped out in our backtests. That is not a guarantee: any EA can lose money.
High: stopped out in our backtest, or martingale/grid sizing without a stop loss. Elevated: martingale or grid sizing with a stop loss, or several positions at once without a stop loss. What the label means and what we found →
Strategy analysis
The strategy concept is based on the divergence between two SMAs of different periods (default 7 and 88), calculating the change rate of current divergence versus the previous bar's divergence to detect momentum deceleration, which follows a mean-reversion logic. Entry conditions: buy signals require divergence between DVBuySell (0.0011) and DVStayOut (0.0079), sell signals require divergence between negative DVStayOut and negative DVBuySell, meaning positions are only opened at moderate divergence levels while excessive divergence triggers a stay-out zone. Exit conditions rely on fixed stop loss and take profit (default 550 points each), with optional trailing stop and breakeven functionality, but SignalCloseBuy and SignalCloseSell always return false, lacking active closing signals based on strategy logic. Position sizing uses fixed lots (default 0.1), with MultyOpen allowing additional positions in the same direction capped by MaxVolume (0.5 lots). Money management includes basket profit/loss closing functionality that can close all account positions when a specified profit or loss threshold is reached.
Strengths
- Well-designed divergence zone with stay-out threshold (DVStayOut) prevents entering during extreme divergence conditions
- Complete stop loss and take profit validation ensures orders comply with exchange minimum stop level requirements
- Basket profit/loss protection prevents excessive drawdown and locks in overall account profits during extreme market conditions
- Clean code structure with clear function separation makes the EA easy to understand and modify
- Uses MQL5 standard library classes (CTrade, CSymbolInfo, etc.) following modern MQL5 programming conventions
Weaknesses
- SignalCloseBuy and SignalCloseSell always return false, lacking strategy-based active closing signals and relying entirely on stop loss/take profit for exits
- Divergence calculation is unintuitive — dv1-dv2 simplifies to maF2[0]-maS2[0] (previous bar's fast-slow MA difference), which may not be the author's intended logic
- Fixed lot sizing without dynamic adjustment based on account balance or risk percentage lacks proper position management
- No spread filter means frequent signals in high-spread environments can lead to unnecessary losses
- SolveBuySL and SolveBuyTP use Sym.Ask() which may be stale if called after Sym.RefreshRates() timing is not synchronized
Possible improvements
- Implement strategy-based active closing signals, such as closing buy positions when divergence reverses from positive to negative
- Fix the Divergence() function calculation logic so it truly reflects the rate of divergence change, and add comments explaining the calculation
- Add dynamic position sizing that automatically calculates lot size based on account balance and risk percentage
- Add a spread filter to pause opening new positions when the spread is too wide, avoiding slippage losses
Risk assessment
Overall risk: Medium
- Divergence calculation logic may be incorrect, causing signals to behave differently than intended
- Lack of active closing signals may lead to significant drawdowns during trend reversals when relying solely on stop loss
- Fixed lot sizing does not adapt to account changes, preventing dynamic risk-based position adjustment
- DVBuySell and DVStayOut are absolute values requiring significant recalibration across different instruments and volatility environments
Evaluation scores
Parameters
| Parameter | Default | Description |
|---|---|---|
Lots | 0.1 | Fixed trading lot size |
MultyOpen | false | Allow same-direction position adding |
MaxVolume | 0.5 | Maximum position lot size limit |
StopLoss | 550 | Stop loss in points |
TakeProfit | 550 | Take profit in points |
Trailing | 0 | Trailing stop in points, 0 to disable |
BreakEven | 0 | Break-even trigger in points, 0 to disable |
Fast_Period | 7 | Fast SMA period |
Fast_Price | PRICE_OPEN | Fast SMA applied price |
Slow_Period | 88 | Slow SMA period |
Slow_Price | PRICE_OPEN | Slow SMA applied price |
DVBuySell | 0.0011 | Min divergence threshold to open position |
DVStayOut | 0.0079 | Max divergence threshold, no entry above |
BasketProfitON | false | Enable account profit closing |
BasketProfit | 75 | Close all positions at this account profit |
BasketLossON | false | Enable account loss closing |
BasketLoss | 9999 | Close all positions at this account loss |
Similar Mean Reversion EAs
Backtests are historical simulations and do not guarantee future results. Not financial advice.