Explore the latest free tools from the MQL5 community. Here's a new indicator, expert advisor, or script for MetaTrader.

Gold Breakout EA for XAUUSD H4: +90% in a 2020-2026 Backtest
Things I tested that are not the default
All three exits were tested year by year with buys and sells and no trend filter, each year starting from 10,000. Total over the seven years:
| Exit | Total | Losing years |
|---|---|---|
| A. ATR trail (3 ATR) | +2,554 | 2 |
| B. Turtle 10-bar channel | +3,393 | 3 |
| C. Fixed 2R target | +4,579 | 3 |
The fixed target won, and adding the 200 EMA filter to it raised the total to +4,777 while cutting the worst single-year drawdown from 13.98% to 10.21%. The same filter made exit B worse, so exits A and B stay available as inputs but they are not the default.
I also ran the defaults on EURUSD H1, the pair MQL5 uses for its automatic check: it runs without errors (164 trades, profit factor 1.03, January 2025 to September 2026). It is not built for forex, and I don't trade it there.
Recover from drawdowns intelligently with the Auto Recovery Expert Advisor for MT4/MT5. Perfect for hedging strategies. Learn more.
Inputs
| Input | Default | What it does |
|---|---|---|
| InpEntryBars | 20 | Entry channel length in bars |
| InpATRPeriod | 20 | ATR period |
| InpStopATR | 2.0 | Stop distance, ATR multiples |
| InpUseTrend | true | Only trade on the side of the 200 EMA |
| InpTrendEMA | 200 | Trend EMA period |
| InpAllowLong | true | Take buy breakouts |
| InpAllowShort | false | Take sell breakouts |
| InpExitMode | C. Fixed target | Exit method (A ATR trail, B Turtle channel, C fixed target) |
| InpTargetR | 2.0 | Take profit for exit C, R multiples |
| InpTrailATR | 3.0 | Trail distance for exit A, ATR multiples |
| InpExitBars | 10 | Channel length for exit B |
| InpRiskPercent | 1.0 | Risk per trade, % of balance |
| InpMaxSpreadToRisk | 0.10 | Skip if the spread is more than this share of the stop |
| InpSlippagePoints | 50 | Allowed slippage in points |
| InpCloseFriday | false | Close the position before the weekend |
| InpFridayHour | 20 | Friday server hour for that close |
| InpMagic | 555001 | Magic number |
Before you run it
Attach it to an XAUUSD H4 chart. Run it on a demo account for a while before you use real money, and check your broker's spread, swap and commission first. MetaQuotes-Demo charges no commission, so a broker that does will take a slice of the 45.60 average per trade. Weekend gaps can fill a stop far from where it was set. That didn't cause a big loss in this test: the largest loss, -174.89 in February 2026, was an ordinary stop at about 0.9% of the balance, which had grown to 18,922 by then. Everything above is one broker's data over one period, most of which was a gold bull market.
Ali Rajput
Complement community code with advanced automation from RobotFX.
77691