Blog / Fix MT5 errors · MQL5 Market · Expert Advisors · MQL5

Part 1: Why EAs Get Rejected by MQL5 Market Validation

Learn why Expert Advisors fail MQL5 Market validation, including runtime errors, closed trading sessions, missing history, and unsupported dependencies.

· 6 min read

Your Expert Advisor works in your local MT5 Strategy Tester, but fails when submitted to the MQL5 Market.

The problem may not appear during your usual tests. The Market validator can run an EA under different symbols, account conditions, and historical-data availability.

A successful backtest does not guarantee that your EA will pass these checks.

Here are common reasons EAs fail validation and what to investigate.

1. Runtime errors that only appear during validation

An EA can compile successfully and still crash during execution.

Common errors include:

Consider this example:

MQL5
double lows[];

int copied = CopyLow(
   _Symbol,
   _Period,
   0,
   2,
   lows
);

if(copied != 2)
{
   Print("Could not copy low prices.");
   return;
}

if(lows[1] < lows[0])
{
   Print("Previous low is lower.");
}

The important part is the check after CopyLow(). If the function fails or returns fewer elements than requested, the EA must not continue reading the array.

The same principle applies to CopyBuffer(), CopyRates(), and other functions that retrieve historical data.

What to check:

  • Confirm that the requested number of elements was copied.
  • Check array sizes before accessing elements.
  • Verify indicator handles before using them.
  • Protect calculations against zero denominators.
  • Confirm array indexing and series orientation.

A particularly easy mistake is forgetting ArraySetAsSeries() on an array that is being indexed as a time series. This can cause the EA to use the wrong candle values even when no runtime error occurs.

2. The EA receives a Market Closed error (10018)

The validator may test symbols with trading sessions that differ from ordinary Forex pairs.

Metals and indices, for example, can have scheduled breaks. An EA that assumes the market is always open may repeatedly send orders during a closed session.

The trade server then returns TRADE_RETCODE_MARKET_CLOSED (10018).

What to check:

Retrieve the symbol's trading mode and session information instead of assuming every instrument trades continuously.

MQL5 provides:

  • SYMBOL_TRADE_MODE to check whether trading is enabled for the symbol.
  • SymbolInfoSessionTrade() to retrieve the trading sessions for a particular day.

Use the session information to determine whether a new order can be placed at the current server time.

Do not assume that checking the weekday is enough. Some instruments have multiple sessions, daily breaks, and different weekend schedules.

Also, do not automatically assume that a cryptocurrency symbol trades 24/7. Follow the trading sessions reported for the actual symbol.

A large third-party session-management function is not always necessary. Start with the symbol's own trading properties and session information.

3. The validator starts with insufficient historical data

An EA may work on your usual chart because MT5 has already downloaded the required history.

The validator may start with a symbol that has little or no history available.

A common mistake is checking SERIES_SYNCHRONIZED once in OnInit() and assuming that the required data will remain available.

That check alone does not guarantee that a particular indicator has calculated the requested values.

What to check:

Use Bars() to verify that enough price history is available and BarsCalculated() to check indicator readiness.

For example:

MQL5
int requiredBars = 100;

if(Bars(_Symbol, timeframe) < requiredBars)
{
   Print("Not enough historical bars.");
   return;
}

if(BarsCalculated(indicatorHandle) < requiredBars)
{
   Print("Indicator data is not ready.");
   return;
}

Perform these checks before requesting indicator values with CopyBuffer().

Use the actual timeframes required by your EA. Checking M1 and M5 history is pointless if the strategy only uses another configurable timeframe and D1.

4. Your EA uses invalid stop or modification prices

An EA may calculate a stop-loss correctly according to its strategy but still receive an invalid-stops rejection.

Two symbol properties are important:

  • SYMBOL_TRADE_STOPS_LEVEL: minimum stop distance.
  • SYMBOL_TRADE_FREEZE_LEVEL: distance within which certain trade operations are restricted.

Check both when placing or modifying stops.

Also, do not assume that normalising a price with _Digits makes it valid.

Some instruments have tick sizes that do not match their displayed decimal precision. For example, an index may trade in increments of 0.25.

Use SYMBOL_TRADE_TICK_SIZE when aligning prices to the instrument's permitted price increments.

Finally, check whether the proposed modification actually changes the existing stop. Sending an unchanged stop price can produce TRADE_RETCODE_NO_CHANGES (10025).

5. Your EA depends on unsupported external files

An EA may work on your development computer because it relies on files that are not included in the submitted product.

Examples include:

  • External DLL libraries.
  • Custom indicators.
  • Additional files stored in local folders.
  • Incorrectly referenced resources.

MQL5 Market products must comply with its dependency restrictions. DLL calls are prohibited, and products must be submitted in the required compiled format, such as EX5 or EX4.

If your EA uses a custom indicator, package the dependency using a supported resource mechanism where applicable.

What to check:

  • Remove prohibited DLL calls.
  • Identify all external dependencies.
  • Package required custom indicators and resources correctly.
  • Check resource paths and indicator names.
  • Test the compiled product in a clean MT5 environment.

Do not assume that a file available on your computer will also exist in the validation environment.

6. Excessive CPU usage and logging

An EA can waste resources by repeating expensive calculations or generating excessive log messages.

Common causes include:

  • Recalculating entire indicator histories on every tick.
  • Repeatedly creating and deleting chart objects.
  • Running unnecessarily large loops.
  • Printing diagnostic messages on every tick.

For example:

MQL5
void OnTick()
{
   Print("EA is running.");
}

This writes a message every time the EA receives a tick.

If your strategy only makes decisions once per completed candle, perform those calculations once per new bar.

Use MetaEditor's Profiler to identify expensive functions instead of rewriting code unnecessarily.

7. Your EA makes assumptions about one symbol or timeframe

An EA developed for EURUSD may fail when tested on another instrument.

Look for:

  • Hard-coded symbol names.
  • Fixed pip-to-point conversions.
  • Assumed price precision.
  • Hard-coded contract sizes.
  • Timeframe restrictions.
  • Fixed volume assumptions.

Use symbol properties such as _Symbol, _Period, _Point, and _Digits where appropriate. Retrieve instrument-specific trading requirements rather than assuming every symbol follows the same rules.

If your EA is intended for a particular instrument, describe its intended use clearly. Avoid unnecessary restrictions that prevent it from operating under validation conditions.

8. Some failures are not validator failures

Not every problem that appears during submission is a trading-logic error.

The Market moderator may also review product presentation and compliance.

For example:

  • Your product description should contain the appropriate disclaimer.
  • Copyright information should identify the correct author or rights holder.
  • A unique magic number helps distinguish the EA's trades from manual trades and other EAs.
  • Trailing-stop and position-management functions should not unintentionally modify manual positions.
  • Debug messages should not clutter the log.

A missing magic number does not necessarily cause an automatic validation failure, but it can create serious position-management problems.

How to diagnose a failed validation

Do not rewrite random sections of your EA when validation fails.

  1. Open the validation report.
  2. Identify the error message and test conditions.
  3. Reproduce the relevant conditions in Strategy Tester where possible.
  4. Open the Experts and Journal logs.
  5. Locate the first relevant error.
  6. Trace it to the responsible function.
  7. Fix the underlying problem and repeat the test.

If the report points to an infrastructure problem rather than an EA error, avoid changing working code unnecessarily. Check whether the issue is temporary and contact MQL5 support if it persists.

Final checklist

Before resubmitting, confirm that:

  • Arrays and indicator buffers are accessed safely.
  • Failed data-copy operations are handled correctly.
  • Historical data and indicator readiness are checked.
  • Trading sessions are handled correctly.
  • Stop and freeze-level restrictions are respected.
  • Prices are aligned to the symbol's tick size.
  • External dependencies comply with Market requirements.
  • Unnecessary calculations and logging are avoided.
  • Position management does not interfere with unrelated trades.
  • Product information and copyright details are correct.

Passing a local backtest is only one part of preparing an EA for the MQL5 Market. Your EA must also handle the conditions it encounters during validation.

Part 2 looks at the automatic tester failures that stop EAs from passing validation: no trading operations, invalid volume and insufficient margin.

With PositionAlpha's Fix an EA, you paste or upload the EA and describe the problem. The AI returns the complete updated .mq4 or .mq5 file and explains the problems it found and each change it made. Compile the result in MetaEditor and test it in the Strategy Tester and on a demo account before you rely on it.

Build a bot from your idea

Describe your trading idea and the AI writes MT4 or MT5 code for you to review and test, with a plain-English explanation and setup steps. Your first bot is free.

More from the blog