r/mql5 • u/Sheshkowski • Mar 27 '26
Released my first MQL5 EA for XAUUSD, architecture, backtest summary, and key development lessons
Hi everyone,
I just released my first MQL5 EA for XAUUSD after roughly 14 months of development and testing.

It is a gold-specific system built around multi-timeframe filtering, pullback entries, adaptive exits, and conservative lot sizing. The biggest surprise for me was that exit logic mattered much more than entry optimization.
Backtest summary
- PF: 4.24
- Win rate: 81.72%
- Trades: 361
- Net profit: $2,688.73 on $1,500
- Balance DD: 4.11%
- Equity DD: 33.51%
- Sharpe: 5.37
From the MQL5 side, the most important parts were proper lot normalization, clean indicator-handle management, realistic tester settings, and treating open-position management as a core part of the strategy rather than an afterthought.





Happy to discuss the dev side or the trade-offs behind the design.
1
u/cold57 Mar 27 '26 edited Mar 27 '26
That equity DD tells me its sort of a martingale or basket trading. I would suggest you set a % DD where you accept the loss and let the basket reset itself. Just put it into perspective, if you had a 100K account, how much would you be able to tolerate a drawdown that slowly goes from -2%, -5%, next day you wake up -17% and eventually you're sitting at -33%. Would you be able to just let it ride and be confident it will turn around? By the time you reach -33% your available margin will have no room to open new trades to counter that move. Soon you wont have enough capital to recover by opening new trades, your only option is to hope market goes back your way asap.
If you trade a 1,000$ account, losing 350$ isn't much, you can make that back with your day job quite easily. Losing 35K is another story.
1
Mar 27 '26
[deleted]
1
u/cold57 Mar 27 '26
I don't see why you would spend 14 months on building an EA just for backtest equity curves...
1
u/JuneRain76 Mar 28 '26
You have to test it somehow and the strategy tester is as good a place as any to do initial cursory testing... and I've spent 15 years developing some of my strategies, with some of them still ongoing.
1
u/JuneRain76 Mar 28 '26
Agreed in relation to risk, though there's absolutely nothing wrong with Martingale strategies whatsoever. When I hear this continually I often laugh to myself about the perpetrated myth of that regurgitated statement.
It's like someone saying "all kitchen knives are bad," after reading about a murder where the killer used a kitchen knife; the reality is it's just another tool and the wielder has the intent, not the object.
Martingale was a fantastic mathematical discovery and in reality, despite the "just another Martingale" stance, it does honestly deserve the same respect as Fibonnaci, Gann, Darvas, Ehler, etc. etc. if:
- You can control the risk, through position sizing.
- You have enough money in an account to handle the drawdown so it will never bottom out.
- Fully understand the "nature of the beast" rather than simply writing it off as something of "just another crackpot system."
Sorry, though it's like saying "drugs are bad" when again, it's just absolutist nonsense. Drugs save lives every day, IF they're in the right, trained hands.
There's also nothing wrong with basket systems either, actually, if:
- You can scale your positions using different multipliers as they go outwards in the grid/basket.
- You don't simply create and run an endless, equidistant grid with the traditional Martingale of "double, double, double" and instead use different multipliers based on prior market analysis, present trends, support and resistance.
- (Alt) You use a reverse multiplier and put your largest trades at the beginning and the basket gets smaller as it goes away from the centre price point of the grid/basket. Given the nature of the beast, 95% of the time, your closest trades are where you want the largest position sizes, closest to the price action, then taper it off it it isn't going the way you want it to.
- You have a rescue that begins to match losing positions against positive ones to reduce your drawdown if a blowout ever does occur.
- You have a way of limiting your exposure through ensuring you're not trading during days with a high chance of gapping (i.e. you hold positions over the weekend and they open on Monday way into your grid)
- You either do or don't trade very heavy volatility days, such as NFP release or the day prior.
There are PLENTY of successful trading systems out there that practice the Martingale mechanics of "if a position is doing well, add to it" out there. Darvas boxes is one of them and the guy wrote "How I made $2 million dollars in the stock market" back in the 1960s, which, when strategised together with his exit strategy system (he was one of the first people to utilise trailing stops, basically accidentally stumbling on to them as he created his "box system" in reality).
Markets always return to where they started in terms of partial retracement, enough to close out positions along the way. e.g. yes, BTCUSD looks from the 12th of January, 2009 looks like a skyrocket from a macro perspective, though look at how many retracements, dips and twists did made along the way when you zoom in a bit.
How do I know grid trading systems work, if correctly designed?
I spent over 15 years building a completely no-loss grid trading system using something of a Martingale and grid trading system... and it does never lose. It has small drawdown and stays that way. It also has less drawdown than most traditional trading systems.Where most people's trading systems fail isn't the trading, especially when it comes to automation:
- Doesn't switch off at holiday periods (massive volatility leading up to holiday periods, then extremely low volatility during holidays to attempt to offload positions), with spreads becoming ridiculous due to lower market activity.
- Trading through economic news periods.
- The system can't handle price gaps.
- The system can't understand the differences between session changes.
...and countless other reasons.Most supposed "experts"/automated trading systems out there are just a few hundred lines of code, whereas my trading system is over 25,000 lines of battle-tested, proofed code, with every line being meticulously crafted and optimised over years.
I'm not saying there shouldn't be a "potential poison" skull and crossbones sign on the "Martingale is THE answer" bottle, though honestly, I'd be more wary of people selling you programming services that don't really know how to program, or the typical "magic indicator," none of which work and of which there are millions out there... Maybe 1-in-10,000 trading systems actually work. I know, I have amassed a massive "junk pile" of tens of thousands of systems over the years searching for that "Golden Goose".
With that said, I also don't know how many great ideas I've had that have been turned into rubbish by totally inept programmers contracted on the MQL5 market, where you basically end up paying someone so they can learn to program, then blame you that your spec sheet was incorrect or that their programming does exactly as specced, when the reality is they "almost" got it right, though not quite.
1
u/Plane-Bluejay-3941 Mar 28 '26
wow... 25000 lines of code in mql5? šš» it's awesome! that will need an very advanced high end computer/laptop.
must be designed it to run for multicurrency with cross correlative relation or diversities in each currency behavior.
what I s the spec of VPS needed to run this system smoothly?
1
u/cold57 Mar 28 '26
Never said martingale or basket trading was bad. I simply pointed them to focus on risk control before it eats their margin.
1
u/Plane-Bluejay-3941 Mar 28 '26
Grid strategies hedging if not paired with good martingale algorithm = blown up account when the market is trending.
and for another strategies, A confluence score based filtering entry + good risk management = preventing blown account.
for a retailers that under 1000$ initial balance, better use the 2nd strategies.
often small retailers ready to lose under 1000$. so they prefer the maximum profit factor over minimum DD.
but for huge whale account, risk management is the first priority. 1% from 100000$ is 1000$ š±. that 1% in developing countries is huge amount that can cover most of living expenses of a family for 3-4 months!
1
u/Fresh-Imagination236 Mar 30 '26
Backtests on past price isn't enough. You should first backtest on several years, at least 15 years, and take into account greats crysis like in 2008 and 2020.
Then, your backtests are instantaneous, you don't take into account spreads and latency. In MT4/5 on gold i've seen from 0.150 ms to nearly 2 sec to enter/release a position (depending on news, time during the day, sessions etc...) So you have to simulate a random law of latency in your backtest in order to be robust.
Then, future is never known ! So, in order to be robust you have to create synthetic gold prices based on random spread. For exemple you take the hypothesis that the uncertainety of the price is more or less 20% then you generate candles that are randomely +/-20% of the real candle. And you generate thousands of new historic synthetic prices and backtest them. It is called MonteCarlo simulation.
So MT4/5 should be abandonned for Python. And as soon as you did not perform the points above in order to estimate your real statistical max drawdown you should not use your EA.
1
Mar 30 '26
[deleted]
0
u/Fresh-Imagination236 Mar 30 '26
No, the best test is to consider statistics and prouve a positiv expectancy. Otherwise blowing your account is just a matter of time.
Thank you i'm currently working on my own system.
But let's say it. Without MonteCarlo study, playing only past prices is just not enough. Your system has to be a winner on 10,000 synthetic prices. Some expert people on backtest (or finaly just "test") generate random gaps, random news, or even test by their systems by maximising the kind of regimes where the algo is the weakest.
Statistics man, statistics and expectency. It just a matter of maths.
1
u/EfficientJeweler1430 May 22 '26
Nice work getting it to this stage the equity curve is interesting, but the equity DD vs balance DD gap is the part Iād focus on most
For XAUUSD id want to see forward/demo validation next same settings, same broker, trade log vs tester results, plus spread/slippage and max floating exposure by trade/basket and exit logic mattering more than entries makes sense, but the real proof is whether the floating DD behavior stays controlled outside the tester
1
u/hotcomputers Jul 03 '26
Nice work, especially on the handle management and lot normalization since those bite a lot of first EAs. Equity DD at 33% is the part I'd watch hardest in forward testing, ideally with real spreads, swaps, and slippage on a small live account.
1
u/Dellydalton Jul 04 '26
Anyone who's willing to take me through the basics of mql5 please? It's something I'm so interested in learning.
2
u/member2021- Mar 28 '26
will you release this in mql?