How to check an MT5 EA that an AI wrote before it trades
By the PipYard team · 6 min read · Updated
Ask an AI assistant for an MQL5 Expert Advisor and you'll usually get code that looks right and, after a fix or two, compiles. That's where most checking stops, and it's the wrong place to stop. A compiled EA has been tested by no one: not on history it wasn't written for, not against your account's limits, and not for how it fails.
Where AI-written EAs tend to go wrong
- No stop-loss, or one that isn't sent. The code computes a stop and never passes it to the order, or places market orders with none. One bad day on demo can then lose more than any trade in the test.
- Inputs tuned on the dates you test. If you asked the assistant to "optimise" the EA, or ran the MT5 optimiser yourself, a backtest on those same dates mostly measures the fit.
- A result carried by a few trades. A handful of large winners can make a whole test look profitable while every other trade loses.
- Sizing that ignores the account. Lot sizes come from an input or a formula that knows nothing about your daily loss limit or your broker's limits.
- Things an EA shouldn't do. Web requests, DLL imports or files shared between terminals, copied in from examples on the internet.
1. Add limits the EA can't skip
Before the EA runs anywhere, PipYard adds its guard and shows every line it changed. The guard is a small MQL5 include that holds the EA to the limits you set for the account in PipYard: the lot cap per order, the daily loss limit, pause and the kill switch. On every tick the EA checks the guard first, and before every order it asks whether that order is allowed. Nothing else in your code changes.
A typical AI-written EA gets three kinds of change: one include line, one line at the top of OnTick(), and a check around each order. If PipYard can't place one safely (an order sent from an unusual place in the code), it says which line and leaves that one to you. It also refuses EAs that make web requests, import DLLs or write to MT5's shared files folder, and says which line does it.
2. Test it in windows, in your own MT5
One backtest over all your history tells you how the EA did on dates its inputs may have been chosen for. Testing in windows is closer to what will happen next: the same EA, with the same inputs, runs on one stretch of history after another, each from the same starting balance, and each window is judged on its own.
- Pick the symbol and timeframe as your broker spells them in MT5 (EURUSDm, XAUUSD.r and so on).
- Choose a few years of history and a window length; three months gives a dozen windows over three years.
- PipYard compiles the EA on your own MetaEditor and runs each window in your MT5 Strategy Tester through the Connector, with your broker's real ticks where it has them, so spreads, commission and swaps match your account.
PipYard fits nothing between the windows. So the windows only count as unseen if the EA's inputs weren't tuned on those dates, by you or by the AI that wrote it. When in doubt, test a later period that nobody tuned on.
3. Read the verdict, then the weak spots
The windows go through the same release gate as every strategy in PipYard:
| Check | Needs |
|---|---|
| Out-of-sample trades | at least 100 |
| Profit factor | at least 1.25 |
| Sharpe ratio | at least 0.8 |
| Max drawdown | at most 15% |
| Profitable test windows | at least 60% |
| Average result per trade | above 0 R |
Then PipYard says, in plain words, what would likely go wrong on a demo account, from this test alone. For example:
- Too few trades to judge, with how many months a demo test would need at this EA's pace to reach the gate's count.
- One window carries the result: most of the net result came from one stretch of dates, which a demo test may never see again.
- Three trades carry the result: the best three trades make up most of the total, so missing one (a slipped fill, a weekend gap, the PC off) changes the picture.
- Trades without a stop-loss: one trade on demo can then lose far more than any trade in the test.
- The drawdown is deep, with how far 1 run in 20 falls when the same trades come in a random order.
A list like this points at weak spots; it can't tell how the EA will do. A version that passes the gate should still run on a demo account first, as a forward test you start in the PipYard app.
What you need, and what it costs
MetaTrader 5 on a Windows PC with the PipYard Connector, and a PipYard account; the Free plan works. The test runs in your own MT5 Strategy Tester, so it uses no compute credits. Your file isn't changed: PipYard saves the guarded copy as a new strategy, version 1, and keeps every later version.
Simulated results. Past performance does not guarantee future results.