Learn
AI-Written EA: Twelve Mistakes You Cannot See in the Code
At a glance
An AI-written EA that compiles and runs in the Strategy Tester has passed the easiest check only. In our own tests, a compiled EA from one prompt matched its written rule on all but one of 646 trades (that one is a data difference) and still lost 15.6%, and several of its weak points were invisible in the source: the clock, the account type, the volume floor, unchecked order results, commission, generated spreads and a restart that the tester never performs. This guide lists twelve such mistakes, says how we know each one, and gives the test that exposes it.
On this page
You asked an AI for an Expert Advisor, pasted the answer into MetaEditor and got zero errors. The Strategy Tester runs, and trades appear. That proves the code is valid MQL5. It does not prove the EA does what you meant, on your broker, with your money.
This guide is a review guide. It does not show how to build an EA; our guide to building an MT5 EA with AI does that. Here the EA already exists, and the question is whether to trust it. The twelve mistakes below share one trait: a clean compile and a quick look at the source will not show them. Each one came out through a test, a journal line or the platform documentation.
Everything here concerns code written by an AI. None of it concerns an AI making the trading decisions. The EA in our examples is a fixed MQL5 program with rules; the AI only wrote the source.
What the twelve mistakes are based on
We did not write new code for this guide, and we did not compile anything new for it. The examples come from tests we had already run and published:
- The range-breakout EA. One prompt, sent once on 2 October 2026 to Claude Opus 5.5 in a fresh session. We compiled the answer unchanged in MetaEditor build 6230 (0 errors, 0 warnings) and backtested EURUSD M15 from January 2024 to September 2026 with 646 trades. A separate script recomputed each trade from the written rule. The full run is in the build guide.
- Two AI-written indicators, tested tick by tick in the Strategy Tester (Claude vs GPT).
- Our own EAs and teaching programs, where we say so. These were not written by an AI for this guide.
That is a small sample: one model, one prompt, one EA. Other assistants will make other mistakes. What carries over is the list of places to look.
The table shows all twelve at a glance, with the source of the evidence.
Scroll horizontally if needed
| # | Mistake | How we know |
|---|---|---|
| 1 | Compiles, but reads the wrong point in time | Our test of a crossover function |
| 2 | The prompt left gaps, and the AI filled them silently | AI-written range EA |
| 3 | Time rules written in server time | Own measurement at three brokers |
| 4 | The tester clock differs from the live clock | Our own EA, backtest comparison |
| 5 | Risk-percent volume has a floor | Documented behaviour, AI-written range EA |
| 6 | An order request is treated as a trade | MQL5 documentation, our teaching EA |
| 7 | Only one account type was tested | AI-written range EA |
| 8 | Costs decide the result | AI-written range EA |
| 9 | The spread filter reacts to generated data | AI-written range EA |
| 10 | Indicators stay empty in the tester | Two AI-written indicators |
| 11 | A restart rule that was never run | AI-written range EA |
| 12 | One backtest is treated as proof | AI-written range EA |
Mistakes in the logic: what the code does
1. It compiles, but it reads the wrong point in time
A compiler checks syntax. It cannot know which moment you meant. In a small test project we built a function that compares two moving averages and reports a crossing. Six fixed cases passed on 26 September 2026. Then we swapped the older and the newer values on purpose. The code still compiled, and the function returned −1 where the correct answer was 1.
In MQL5 this is a common trap, because CopyBuffer puts the older value first in a plain array. Source: CopyBuffer. Generated code that reads indicator values must be tested with cases whose answer you know in advance.
Test: write six to ten cases for the decision function, including one with swapped inputs, and run them before the first backtest.
2. The prompt left gaps, and the AI filled them silently
Our prompt had eleven numbered rules and looked complete. The assistant still listed 25 assumptions before it wrote code. Five of them changed what the EA does. Two matter here:
- It may enter on any closed bar outside the range, not only the first breakout bar.
- A skipped entry does not use up the day.
The recomputed rule showed a signal on 28 days where the EA placed no trade, and on 12 days it entered on a later signal than the first. On 18 March 2025 it skipped a sell signal, then 16 buy signals in a row, and bought at 14:45, four hours after the first close above the range. Each choice was reasonable, and none of them is what “buy when a bar closes above the range high” suggests.
This is the one place where the AI helped us: because we had told it to list its assumptions, the gaps were written down. The EA’s behaviour was in the answer all along, but nobody had read the list as a list of decisions about money.
Test: make the AI restate the rule and list every ambiguity. Read that list before the code. Then compare the trade list with the rule, day by day. A report alone never shows a missed signal.
3. Time rules are written in server time
Our range EA defined its hours as broker server time: the range from 00:00 to 08:00, the exit at 21:00. That was our prompt, and the EA did what it was told. Whether it suits your account depends on a clock the source does not contain.
The server clock belongs to the broker, not to your computer or your VPS. Many brokers run at UTC+2 and UTC+3 during US daylight saving time; others follow the EU rule or stay at UTC+0. We measured three brokers in October 2026. On a UTC+0 server, the previous day’s high or low of gold differed on 49% of trading days from 2022 to 2026, because the daily candle starts at another moment. Our MT5 server time guide has the measurements and a checklist.
For our range test, the broker was at GMT+3 on the test day. The same 00:00 to 08:00 slice would cover other hours of the real market at a UTC+0 broker.
Test: read your broker’s offset, write it next to the EA’s time inputs, and check the hours of the first trades in a backtest against the hours you expected.
4. The tester clock is not the live clock
This one hit one of our own EAs, not an AI-written one. The Bitcoin weekend EA reads its trading window in a fixed reference clock live and takes the broker’s offset from our licence server. In the Strategy Tester there is no licence answer, and TimeGMT() returns simulated server time. Version 3.13 therefore read its window in server time, which at a UTC+0 broker moved the window two to three hours later.
The same rules on the same ticks gave +111.7% with the wrong clock and +50.1% with the live-like clock at the Low risk level (10,000 USD, 1 July 2024 to 24 October 2026, backtests). The first number looked better than the EA would ever trade.
Generated code loves TimeGMT() and TimeLocal(), because they look like safe, universal functions. Source: MQL5 testing.
Test: compare the trade times in your backtest with the first trades of a live or demo run. Our server time guide covers the tester case.
Mistakes with money: how an order becomes a trade
5. Risk-percent volume has a floor
Our range EA computes volume from equity, the stop distance, tick value and tick size. We could check it by hand. Equity of 10,000 USD gives a risk of 100 USD. A stop 282 points away costs 282 USD per lot on EURUSD in a USD account. 100 divided by 282 is 0.3546 lots, rounded down to 0.35. The tester journal shows Order SELL 0.35 lots.
The formula is the easy part. The hard part is the edge: what happens when the result is below the broker’s minimum volume? A hypothetical example with a 20-pip stop: at 500 USD, 1% is 5 USD, the volume rounds down to 0.02 lots and the planned loss becomes 0.8%. At 100 USD, 1% is 1 USD, the calculation gives 0.005 lots, and the minimum volume of 0.01 loses 2 USD, which is 2% of the account. An EA can skip the trade, trade the minimum anyway at twice the risk, or send an invalid volume, which the server refuses with return code 10014. Our lot size guide works through the arithmetic.
Our prompt settled this case: below the minimum, skip the trade and log why. That is why the question has an answer here. A prompt that does not say it leaves the choice to the AI, and the minimum volume plays no role in a backtest on a 10,000 USD account. It matters on a small one.
Test: attach the EA to a demo with a small balance, or put a tiny balance into the tester, and read what the log says.
6. An order request is treated as a trade
A true result from the send call says that the request was sent, not that a position exists. MetaQuotes requires checking the return code of every request. Source: OrderSend.
The range EA does this well: it logs the return code of each request and counts only the codes done, partly done and placed as accepted. In its tester journal, all 646 entry orders read like accepted, retcode 10009 (done at 1.13845). But the tester filled every request at the requested price. Rejections, requotes and partly filled volumes never happened in the test, so those branches have not run once.
In our own teaching EA, built without a broker connection (build 6182, synthetic prices, 21 September 2026), an order request returned code 10027 with Algo Trading off. With Algo Trading on, the same request still failed with code 10013, invalid request. Our EA-not-trading guide lists the codes.
One more decision hides here. Our prompt said not to resend a failed request in a loop. The AI made one exception on its own: if the 21:00 close fails, it tries again, at most once per 60 seconds. That is a sensible choice and still a choice nobody asked for. It appears in the list of assumptions, not in the rules you wrote.
Test: search the source for every OrderSend or CTrade call, and for each one find the line that reads the result. Then look for the line that decides what happens after a failure.
7. Only one account type was tested
Our prompt said the EA must work on netting and on hedging accounts. The source checks the account mode and, on a netting account, refuses to enter while a position that is not its own sits on the symbol. Our test account was a hedging account, so that guard never ran.
The difference is not cosmetic. On a netting account there is one position per symbol, and another fill can increase, reduce, close or reverse it. On a hedging account, PositionSelect(symbol) picks the lowest-ticket position and does not find the one belonging to a magic number. CTrade::PositionClose with a symbol does the same. Source: PositionSelect, source: PositionClose. Opening an opposite trade is not the same as closing a selected position; see hedging vs netting.
Test: find your account mode, and run the EA on a demo of the same mode before it touches real money. A claim in the prompt is not a test.
8. Costs decide the result
The range EA followed its rule exactly and lost 15.6%. The tester report shows why, and the code could not: before commission, the 646 trades ended at −7.88 USD. The commission of 7 USD per lot round turn cost 1,554.30 USD. Spread is already inside the first number, because the tester fills buys at the ask and sells at the bid.
An AI cannot know your broker’s commission, your typical spread or your swap. It writes a spread limit as an input and moves on. The break-even cost of a strategy is a figure you have to compute yourself; our cost sensitivity study shows the method.
Test: read the commission line in the report, then rerun the same period with your broker’s real costs. If a rule only works with zero cost, it does not work.
Mistakes the test hides
9. The spread filter reacts to generated data
Our range EA skips an entry when the spread is above 30 points. That filter explains the 28 days without a trade and the 12 days with a late entry from mistake 2. The journal holds 497 lines like Entry skipped: spread 34 points exceeds MaxSpreadPoints 30.
All but six of those lines fall into the part of the test with generated ticks. The report says “History Quality: 18% real ticks”: the demo server supplied real ticks from 1 April 2026 only, and for the 27 months before that the tester generated ticks from minute bars. MetaQuotes documents that the ask price is then the bid plus the spread stored in the minute bar. Source: real and generated ticks.
The filter worked as written. The data it reacted to is the weak point, and no look at the code finds that. See our real ticks definition.
Test: read “History Quality” before the profit. If a filter depends on spread, count how often it fired and in which part of the test.
10. Indicators stay empty in the tester
Two AI-written indicators, one from Claude Opus 5.5 and one from GPT-6 Astra, both added an hourly trend filter. Both matched the written rule on all 438 signals on the chart history. In the Strategy Tester both showed 0 of the 51 signals the rule has. The journal contained no error.
The causes differed. Claude’s version asked whether the hourly EMA was calculated before it requested any hourly value, and MetaQuotes documents that in the tester indicators are calculated only when they are accessed for data. GPT’s version required 50 hourly bars before every chart bar, and in the tester the chart history and the hourly history begin on the same date. Source: MQL5 testing. On a live chart with long history neither defect shows.
The same applies to an EA that loads an indicator and reads its buffers. If the EA depends on one, check that its signals appear in the tester at all.
Test: count the signals in the tester and compare the number with the chart. Zero is an answer, not a quiet result. The method is in Claude vs GPT. For signals that move after the bar closes, see how to check repainting.
11. A restart rule that was never run
Rule 3 of our prompt said: after a restart, find out from the account history whether today’s trade already happened. The AI wrote that search. The tester ran it once, at the start. The Strategy Tester does not restart an EA, so the case the rule exists for never happened.
Terminals restart: updates, power cuts, VPS moves. An EA that opens a second trade after each restart, or loses track of an open position, shows nothing wrong in a backtest.
Test: on a demo, open a trade, stop the terminal, restart it and read what the EA does. Save the logs first, and understand how the EA restores its state before you restart.
12. One backtest is treated as proof
A clean run reads like an answer. Ours ended at 8,437.82 USD from 10,000. Split by year, the same backtest looked like three different strategies:
Scroll horizontally if needed
| Period | Trades | Net after commission |
|---|---|---|
| 2024 | 244 | −2,490.24 USD |
| 2025 | 218 | −54.09 USD |
| 2026 to 29 September | 184 | +982.15 USD |
The 129 trades on real ticks, from 1 April 2026, made 810.75 USD. That is no edge. It is six months of one symbol with inputs nobody had tested beforehand, and the 27 months before it lost 2,372.93 USD. A rule that is negative, flat and positive in three consecutive years has shown no stable behaviour.
This is a historical backtest, not an out-of-sample test, a demo-forward run or a live result. Our guide on backtest vs live trading explains what each stage adds.
Test: split the result by year and by data quality, and keep the stages apart: backtest, out-of-sample, demo forward, live.
A review routine for an AI-written EA
Run these steps in order. Each maps to the mistakes it catches.
Scroll horizontally if needed
| Step | What to do | Catches |
|---|---|---|
| 1 | Make the AI restate the rule and list its assumptions. Read the list as decisions about money | 2, 6 |
| 2 | Compile the answer unchanged and save the log. Fix errors one at a time, quoting the compiler message | 1 |
| 3 | Test the decision function with known cases, including swapped inputs | 1 |
| 4 | Write down your broker’s server offset and compare the first trades’ hours with the plan | 3, 4 |
| 5 | Backtest with real ticks where the broker offers them, and read “History Quality” and the commission line first | 8, 9 |
| 6 | Recompute each trade from the written rule, outside the EA | 2, 10 |
| 7 | Check the number of indicator signals in the tester against the chart | 10 |
| 8 | Test the order path on a demo of your account type, with a small balance: rejection, minimum volume, restart | 5, 6, 7, 11 |
| 9 | Split the result by year before you read the total | 12 |
Our Strategy Tester report guide shows how to read the numbers in steps 5 and 9.
What we did not test
- No new code. We reviewed one AI-written EA and two AI-written indicators from earlier tests. We did not compile or run any new code for this guide.
- One model, one prompt. The range EA came from Claude Opus 5.5 in a single answer. Other models, other prompts and other days produce other code.
- No netting account, no live account. Mistakes 6, 7 and 11 are about paths that no test of ours has run. We name them because the documentation and the missing test point to them, not because we saw them fail.
- Only MT5. MT4 uses MQL4 and different return codes.
- Not a complete list. Twelve checks do not make an EA safe. A review can find a problem. It cannot certify future behaviour.
Download
Download the MQL5 project (ZIP). The AI’s unchanged answer, the MQL5 source, the compile log, the tester journal, the trade list and the Python check behind the examples.
The ZIP contains the prompt, the unchanged AI answer, the source, the compile log, the tester journal, the trade list and the Python check behind most examples above. It contains no executable and no account data. Use a demo account or a separate test installation.


