Skip to content

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.

An Expert Advisor, indicator or script for MetaTrader 5. The check runs in your browser: the code is not uploaded or stored. Ctrl + Enter checks it.

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

RuleSeverityWhat it finds
OrderSend() result not checkedHighOrderSend() 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 checkedHighA 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 onlyMediumThe 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 useMediumA 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 symbolMediumRaw 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

RuleSeverityWhat it finds
Calculated lot not rounded to the volume stepHighA 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 maximumHighA 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 tradeMediumThe 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 checkHighA 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

RuleSeverityWhat it finds
Stops set without the stops level checkHighThe 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 checkMediumThe 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 digitsMediumA 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 digitsMediumThe 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

RuleSeverityWhat it finds
No magic number on the EA's tradesMediumThe 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 positionsMediumOnTick() 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 upHighA 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 filterMediumThe 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 filterMediumThe 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

RuleSeverityWhat it finds
Indicator handle created on every tickHighAn 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 tickMediumOnTick() copies bar data and makes entry decisions on every tick, with no check for a new bar anywhere in the EA.
Sleep() inside OnTick()LowOnTick() 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 tickMediumHistorySelect(0, …) is called from OnTick(), so every deal and order of the account is loaded again on each tick.

Signals and data

RuleSeverityWhat it finds
Signal read from the bar that is still formingMediumThe 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 checkedMediumA 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_HANDLEMediumAn indicator handle is stored without checking for INVALID_HANDLE, so a missing custom indicator goes unnoticed and every read fails.

Environment and lifecycle

RuleSeverityWhat it finds
Algo trading permission not checkedLowThe 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 stoppedLowThe EA starts a timer with EventSetTimer() but never calls EventKillTimer(), which the MQL5 reference pairs with it in OnDeinit().
Chart objects created but never removedLowThe EA draws chart objects but never deletes them, so lines and labels stay on the chart after it is removed.

Portability

RuleSeverityWhat it finds
Hard-coded symbol nameMediumThe 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 fileHighThe 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.