MACD Sample
This EA uses MACD histogram crossovers combined with an EMA trend filter to generate buy and sell signals. It implements trailing stop management and take profit targets for position exits. The strategy only enters trades when the MACD signal confirms momentum and the EMA confirms the prevailing trend direction.
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 | +4.96% | +4.30% | 3.36% | 127 | 55.60% | 1.07 | 1.48 | 5 | +$4.21 | Reliable |
| GBPUSD | +5.83% | +5.04% | 2.55% | 124 | 49.60% | 1.06 | 2.29 | 5 | +$4.93 | Reliable |
| USDJPY | -5.73% | -5.00% | 7.71% | 124 | 55.30% | -1.11 | -0.74 | 4 | −$4.72 | Reliable |
| XAUUSD | +49.79% | +39.64% | 63.00% | 127 | 54.00% | 0.83 | 0.79 | 6 | +$41.49 | Reliable |
Profitable on 3 of 4 markets with reliable results.
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.
Against the other Momentum EAs with a reliable result on the same market: EURUSD: better than 85% of 68 · GBPUSD: better than 94% of 66 · USDJPY: better than 12% of 68 · XAUUSD: better than 77% of 75
Month by month
| Market | Months with a gain | Best month | Worst month |
|---|---|---|---|
| EURUSD | 69% | +3.11% 2026-04 | -2.01% 2026-03 |
| GBPUSD | 62% | +2.60% 2025-12 | -1.61% 2026-01 |
| USDJPY | 31% | +2.42% 2025-12 | -2.50% 2026-01 |
| XAUUSD | 54% | +55.05% 2026-02 | -20.28% 2026-04 |
From the backtest equity curve, sampled about every two days; only reliable results.
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 core strategy of this EA is based on MACD signal line crossovers for trade entries, with an EMA acting as a trend direction filter. Long entry conditions require: MACD main line below zero, MACD main line crossing above signal line from below, MACD absolute value exceeding the open level threshold, and current EMA greater than previous EMA (confirming uptrend). Short entry conditions are symmetrically opposite: MACD main line above zero, MACD main line crossing below signal line from above, MACD value exceeding the open level threshold, and current EMA less than previous EMA (confirming downtrend). For exits, long positions close when MACD bearish crossover occurs above zero with MACD value above close level; short positions close when MACD bullish crossover occurs below zero with MACD absolute value above close level. Position sizing uses a fixed lot size (InpLots=0.1) with no scaling or position accumulation logic. Money management includes only a free margin check before opening positions, with no maximum drawdown limit or equity protection mechanism. The trailing stop moves the stop loss to follow price once profit exceeds the trailing stop threshold, but no initial stop loss is set on position open.
Strengths
- Clear strategy logic using the classic MACD crossover with EMA trend filter combination, easy to understand and verify
- Implements trailing stop functionality to lock in partial profits on winning positions and reduce drawdown risk
- Includes comprehensive parameter validation (lot size range, take profit/trailing stop vs StopsLevel) preventing abnormal trades from misconfigured inputs
- Well-structured OOP encapsulation makes the code maintainable and extensible
Weaknesses
- No initial stop loss is set on position open (SL=0.0), relying solely on trailing stop which can lead to catastrophic losses during sharp market reversals
- Fixed lot sizing without equity-based or volatility-based position adjustment lacks dynamic money management
- No new bar detection mechanism; trade logic can trigger on every tick, potentially causing repeated entries or frequent modifications during fast markets
- No spread filter; in high-spread environments the MACD threshold values may be consumed by spread costs leading to losing trades
- Positions can be reopened immediately after closing without directional confirmation protection, potentially causing repeated losses in choppy markets
Possible improvements
- Set an initial stop loss on position open instead of relying solely on trailing stop, to limit maximum per-trade loss
- Add new bar detection logic to prevent multiple signal triggers within the same bar, reducing unnecessary trading costs
- Introduce ATR-based dynamic position sizing and threshold settings to adapt the strategy to different market volatility environments
Risk assessment
Overall risk: Medium
- No initial stop loss on position open exposes unlimited risk in extreme market conditions
- Fixed lot size without equity adjustment causes risk ratio to increase progressively during consecutive losses
- Lack of new bar detection and spread filter may lead to frequent trading under unfavorable conditions
Evaluation scores
Parameters
| Parameter | Default | Description |
|---|---|---|
InpLots | 0.1 | Fixed lot size |
InpTakeProfit | 50 | Take profit in points |
InpTrailingStop | 30 | Trailing stop in points |
InpMACDOpenLevel | 3 | MACD open signal threshold (points) |
InpMACDCloseLevel | 2 | MACD close signal threshold (points) |
InpMATrendPeriod | 26 | EMA trend detection period |
Similar Momentum EAs
Backtests are historical simulations and do not guarantee future results. Not financial advice.