Free tool
EA Doctor: MQL5 code checker
Paste your MetaTrader 5 Expert Advisor and check it against 30 rules for what fails on a live account: unchecked trade results, lots off the volume step, stops and freeze levels, repainting signals, loops that skip positions. Each finding has its line and a fix. Your code stays in your browser.
Report
Paste your EA's source (or load an example) and press “Check the code”. The report shows here.
The 30 rules
Each rule looks for one mistake that makes orders fail or an EA lose track of its trades, and stays quiet when the code handles it. “High” can stop orders or close the wrong trades; “Medium” works on one account and fails on another; “Low” is housekeeping. Every rule has a page with the reason, exactly when it fires and fixed MQL5 code.
Trade requests
| Rule | Severity | What it finds |
|---|---|---|
| OrderSend() result not checked | High | OrderSend() is called as a plain statement, so a refused or requoted order goes unnoticed and the EA carries on as if it traded. |
| CTrade call result not checked | High | A CTrade method such as Buy(), Sell() or PositionClose() is called as a plain statement, so its failure is never seen. |
| Pending orders judged by TRADE_RETCODE_DONE only | Medium | The EA places pending orders but treats every answer except TRADE_RETCODE_DONE as a failure, and an accepted pending order answers TRADE_RETCODE_PLACED. |
| Trade request not cleared before use | Medium | A local MqlTradeRequest is declared without an initializer and never cleared, so the fields the code does not set hold leftover values. |
| Filling mode not taken from the symbol | Medium | Raw trade requests go out with a fixed filling type, or the default Fill or Kill, instead of one the symbol allows, which brokers refuse with 10030. |
Volume and money
| Rule | Severity | What it finds |
|---|---|---|
| Calculated lot not rounded to the volume step | High | A lot calculated from risk, balance or a multiplier is sent without rounding it to the symbol's volume step, which the server refuses with 10014. |
| Calculated lot not checked against the minimum and maximum | High | A calculated lot is sent without checking the symbol's minimum and maximum volume, so small accounts and large multipliers get 10014. |
| No margin check before a new trade | Medium | The EA opens trades without asking whether the free margin covers them, so it keeps sending orders that the server refuses with 10019. |
| Division by the tick value without a zero check | High | A lot formula divides by the tick value or tick size, which is 0 until the symbol's data arrive, and the EA stops with a zero divide error. |
Prices and stops
| Rule | Severity | What it finds |
|---|---|---|
| Stops set without the stops level check | High | The EA sets a stop loss or take profit without reading the broker's minimum stop distance, which is refused with 10016 when it is too close. |
| Changes near the price without the freeze level check | Medium | The EA modifies stops or deletes orders without reading the freeze level, inside which the broker refuses changes with 10029. |
| Prices not rounded to the symbol's digits | Medium | A price, stop loss or take profit is computed with _Point arithmetic and sent without NormalizeDouble() or rounding to the tick size. |
| Hard-coded point size or digits | Medium | The code writes 0.0001 for a pip or rounds prices to a fixed number of digits, which is wrong on JPY pairs, gold, indices and crypto. |
Positions and orders
| Rule | Severity | What it finds |
|---|---|---|
| No magic number on the EA's trades | Medium | The EA opens trades without a magic number, so it cannot tell its own positions from manual trades or another EA's. |
| New entries without reading the open positions | Medium | OnTick() opens trades but nothing in the EA reads its open positions or orders, so it keeps entering again on every signal and after every restart. |
| Positions closed in a loop that counts up | High | A loop from 0 to PositionsTotal() closes positions, so every close shifts the list and the loop skips the next position. |
| Position loop without a magic number filter | Medium | The EA stamps its trades with a magic number, but a loop over the open positions never compares it, so it also handles other trades. |
| Position loop without a symbol filter | Medium | The EA trades its chart's symbol, but a loop over the open positions never checks the symbol, so it also handles positions on other symbols. |
OnTick and performance
| Rule | Severity | What it finds |
|---|---|---|
| Indicator handle created on every tick | High | An indicator function such as iMA() or iCustom() is called in OnTick(), so a handle is requested on every tick instead of once in OnInit(). |
| Bar-based logic runs on every tick | Medium | OnTick() copies bar data and makes entry decisions on every tick, with no check for a new bar anywhere in the EA. |
| Sleep() inside OnTick() | Low | OnTick() pauses with Sleep(), which holds up every other event of the EA and leaves it working with old prices. |
| The whole trade history loaded on every tick | Medium | HistorySelect(0, …) is called from OnTick(), so every deal and order of the account is loaded again on each tick. |
Signals and data
| Rule | Severity | What it finds |
|---|---|---|
| Signal read from the bar that is still forming | Medium | The EA compares indicator values of bar 0, which change with every tick until the bar closes, so its entries differ from what the chart shows later. |
| CopyBuffer() or CopyRates() result not checked | Medium | A Copy function is called as a plain statement, so the code reads the array even when nothing was copied. |
| Indicator handle not checked for INVALID_HANDLE | Medium | An indicator handle is stored without checking for INVALID_HANDLE, so a missing custom indicator goes unnoticed and every read fails. |
Environment and lifecycle
| Rule | Severity | What it finds |
|---|---|---|
| Algo trading permission not checked | Low | The EA sends orders without checking that algo trading is allowed in the terminal, for the EA and on the account, so every order fails when one is off. |
| Timer started but never stopped | Low | The EA starts a timer with EventSetTimer() but never calls EventKillTimer(), which the MQL5 reference pairs with it in OnDeinit(). |
| Chart objects created but never removed | Low | The EA draws chart objects but never deletes them, so lines and labels stay on the chart after it is removed. |
Portability
| Rule | Severity | What it finds |
|---|---|---|
| Hard-coded symbol name | Medium | The code names a symbol such as "EURUSD" or "XAUUSD", which breaks on brokers that use another name or a suffix. |
| MQL4 functions in an MQL5 file | High | The file uses MQL4's order functions and variables (OP_BUY, OrderSelect by position, Bid, Ask, Close[]), which MQL5 does not have. |
What it does not do
- It does not run your EA. It reads the source, the way a reviewer does, so it cannot see the broker’s settings, the market or your strategy’s logic.
- It looks for known mistakes, not for every bug. No finding does not prove an EA is right: test it on a demo account before it trades real money.
- It does not upload your code. The check runs in this browser tab; only the optional compile check sends the code, when you ask, and it is deleted after the compile.
When an order still fails
- The journal’s return code says why: look it up in the MQL5 error library.
- Rules about OnTick() need the EA’s event handlers in the same file; an include file alone is checked for the rest.
- MQL4 code (MetaTrader 4) is recognised and reported as such: EA Doctor checks MQL5.