Blog / Fix MT5 errors · MQL5 Market · Trade errors · MQL5

Part 2: Passing the Automatic Tester (No Trades, Invalid Volumes, Insufficient Margin)

Why an EA fails the MQL5 Market automatic tester with no trades, invalid volume (10014) or insufficient margin (10019), and how to fix each.

· 6 min read

An Expert Advisor can compile successfully and still fail the MQL5 Market automatic tester.

Three common problems are:

  1. The EA completes a test without opening any trades.
  2. The tester reports invalid volume.
  3. A trade is rejected because of insufficient margin.

These problems require different solutions. The key is to identify the actual cause rather than changing settings just to make the EA produce a successful test.

This is Part 2. Part 1 covers runtime errors, closed sessions, missing history and the other reasons the validator rejects an EA.

1. No trading operations

An EA may complete a test without opening a single position. This can happen even when the code compiles and the indicator calculations are correct.

The first thing to investigate is the EA's default input configuration.

Check your default filters

Several settings can prevent trades during validation:

  • Trading-session restrictions.
  • Daily trade limits.
  • Candlestick confirmation.
  • Maximum spread filters.
  • One-trade-at-a-time limits.
  • Minimum historical-data requirements.

For example, an EA that defaults to the New York session from 9:30 to 16:00 may not trade during a test period outside that session.

A strategy with several confirmation requirements may also produce no signals under certain market conditions.

Do not automatically remove these filters. Check whether the defaults allow the EA to operate under the validator's test conditions while preserving the intended strategy.

Check the default confirmation mode

A particularly dangerous mistake is assuming that a default input works correctly simply because the EA compiles.

Consider a simplified buy/sell confirmation branch:

MQL5
if(confirmationMode == CONFIRM_NONE)
{
   if(buyCondition)
      buySignal = true;

   if(sellCondition)
      sellSignal = true;
}

Both conditions must be checked independently. If the second branch accidentally sets buySignal = true instead of sellSignal = true, the EA will never generate a sell signal in this mode.

This kind of copy-and-paste error can remain unnoticed when testing only bullish conditions.

Log the entry conditions

If the EA still produces no trades, log each condition separately:

MQL5
PrintFormat(
   "Buy: %s | Sell: %s | Spread OK: %s | Session OK: %s",
   buySignal ? "TRUE" : "FALSE",
   sellSignal ? "TRUE" : "FALSE",
   spreadOK ? "TRUE" : "FALSE",
   sessionOK ? "TRUE" : "FALSE"
);

Use the actual variables from your EA. Remove or reduce diagnostic logging after identifying the problem.

Never force a trade simply to satisfy the validator. The EA must trade only when its strategy conditions are met.

2. Invalid volume (10014)

The TRADE_RETCODE_INVALID_VOLUME error means the requested volume does not comply with the symbol's trading rules.

Three properties determine the permitted volume:

Property Meaning
SYMBOL_VOLUME_MIN Minimum permitted volume
SYMBOL_VOLUME_MAX Maximum permitted volume
SYMBOL_VOLUME_STEP Permitted volume increment

For example, a symbol may allow a minimum of 0.01 lots, a maximum of 100 lots, and increments of 0.01.

A request for 0.015 lots would not follow that volume step.

Do not rely on NormalizeDouble(volume, 2)

This is a common mistake:

MQL5
volume = NormalizeDouble(volume, 2);

It assumes two decimal places are sufficient for every instrument.

That fails on symbols with a volume step such as 0.001.

Retrieve the actual volume properties:

MQL5
double minVolume = SymbolInfoDouble(
   _Symbol, SYMBOL_VOLUME_MIN
);

double maxVolume = SymbolInfoDouble(
   _Symbol, SYMBOL_VOLUME_MAX
);

double volumeStep = SymbolInfoDouble(
   _Symbol, SYMBOL_VOLUME_STEP
);

Use the actual volume step

A normalisation function should respect the minimum, maximum, and permitted increment. Lot Size Normalization in MT5 goes through the rounding in detail.

MQL5
bool NormalizeVolume(
   const string symbol,
   const double requested,
   double &normalized
)
{
   double minVolume = SymbolInfoDouble(
      symbol, SYMBOL_VOLUME_MIN
   );

   double maxVolume = SymbolInfoDouble(
      symbol, SYMBOL_VOLUME_MAX
   );

   double step = SymbolInfoDouble(
      symbol, SYMBOL_VOLUME_STEP
   );

   if(minVolume <= 0.0 ||
      maxVolume < minVolume ||
      step <= 0.0 ||
      requested < minVolume ||
      requested > maxVolume)
      return false;

   double steps = MathFloor(
      (requested - minVolume) / step + 1e-9
   );

   normalized = NormalizeDouble(
      minVolume + steps * step,
      8
   );

   return normalized >= minVolume &&
          normalized <= maxVolume;
}

Call the function before submitting the trade. Writing a correct normalisation function is not enough if the EA continues using the original, unnormalised volume.

Also check SYMBOL_VOLUME_LIMIT.

This property represents the maximum aggregate volume allowed in one direction, including relevant open positions and pending orders. It is not the maximum volume of an individual order.

Always enforce SYMBOL_VOLUME_MAX separately. A large volume limit does not permit an individual order to exceed the symbol's maximum volume.

Finally, do not use MathMax(volume, minVolume) to silently increase a calculated lot size. If the minimum lot exceeds the amount permitted by your risk calculation, skip the trade rather than taking more risk than intended.

3. Insufficient margin (10019)

An EA can request a valid lot size and still receive TRADE_RETCODE_NO_MONEY (10019).

This happens when the account does not have enough available margin for the proposed trade. “Not Enough Money” in MT5 covers the error in more depth.

The validator may expose this problem by testing the EA with a smaller deposit than the one used during development.

Calculate the required margin

Use OrderCalcMargin() to estimate the margin required for the proposed trade.

MQL5
double requiredMargin = 0.0;

MqlTick tick;

if(!SymbolInfoTick(_Symbol, tick))
   return;

if(!OrderCalcMargin(
      ORDER_TYPE_BUY,
      _Symbol,
      volume,
      tick.ask,
      requiredMargin))
{
   PrintFormat(
      "Margin calculation failed: %d",
      GetLastError()
   );

   return;
}

double freeMargin = AccountInfoDouble(
   ACCOUNT_MARGIN_FREE
);

PrintFormat(
   "Required: %.2f | Available: %.2f",
   requiredMargin,
   freeMargin
);

For a sell order, use ORDER_TYPE_SELL and the appropriate Bid price.

Do not immediately skip every trade that exceeds free margin

If your EA uses risk-based position sizing, a trade may be affordable at a smaller volume.

A better approach is to reduce the requested volume in valid symbol increments and recalculate the required margin.

The process should be:

  1. Calculate the intended risk-based volume.
  2. Normalise it to the symbol's permitted volume step.
  3. Estimate the required margin.
  4. If the margin is insufficient, reduce the volume by one valid step.
  5. Repeat until the trade fits or the minimum volume is reached.
  6. Skip the trade if even the minimum volume cannot be supported.

Do not increase the volume to the minimum if that would exceed the strategy's risk limit.

Also remember that OrderCalcMargin() is an estimate. It does not reserve margin or fully account for every interaction with existing positions and pending orders. Use OrderCheck() to validate the complete request before submission, and still inspect the final trade-server response.

4. Check the actual trade result

A successful call to a trading function does not always mean a deal was executed.

For example, when using CTrade:

MQL5
#include <Trade/Trade.mqh>

CTrade trade;

trade.SetTypeFillingBySymbol(_Symbol);

bool sent = trade.Buy(volume, _Symbol);

if(!sent)
{
   PrintFormat(
      "Buy failed: %u | %s",
      trade.ResultRetcode(),
      trade.ResultRetcodeDescription()
   );

   return;
}

PrintFormat(
   "Buy result: %u | %s",
   trade.ResultRetcode(),
   trade.ResultRetcodeDescription()
);

Inspect the server return code and confirm the resulting deal or position where necessary.

This helps distinguish an invalid request, insufficient margin, closed market, and other execution problems.

5. Quick troubleshooting guide

Tester result Likely cause What to fix
No trades Filters or confirmation conditions Check default inputs and signal logic
No trades Failed indicator data retrieval Check handles, BarsCalculated() and CopyBuffer()
No trades Incorrect buy/sell branch Verify both signal assignments
Invalid volume (10014) Incorrect lot normalisation Use minimum, maximum and volume step
Volume limit (10034) Excessive aggregate exposure Check open positions and pending orders
Insufficient margin (10019) Requested volume requires too much margin Reduce volume within risk limits or skip
Market closed (10018) Trading session is closed Check symbol session information

After each correction, rerun the same test with the same symbol, timeframe, date range, and account settings. Change one thing at a time so you can identify what actually fixed the problem.

Final checklist

Before submitting your EA, confirm that:

  • Default inputs allow the strategy to operate as intended.
  • Buy and sell conditions are assigned correctly.
  • Session and daily-trade filters do not unintentionally block every entry.
  • Indicator data is checked before use.
  • Volume normalisation uses the symbol's actual step.
  • Individual order volume respects SYMBOL_VOLUME_MAX.
  • Aggregate exposure respects SYMBOL_VOLUME_LIMIT.
  • Volume is never increased beyond the calculated risk limit.
  • Margin is checked before submitting trades.
  • Trade-server return codes are inspected.
  • The EA handles small account balances safely.

Conclusion

The MQL5 Market automatic tester can expose problems that ordinary backtesting misses.

If there are no trading operations, inspect the default inputs, filters, and signal logic. If volume is invalid, check the symbol's actual volume rules. If margin is insufficient, reduce the requested volume only when the strategy's risk limits allow it.

Part 3 covers the other symbols and timeframes the validator tests an EA on: symbol properties, history, indicator handles and trading specifications.

EAs built with PositionAlpha's Bot Builder share an MQL5 library that already does these checks: it rounds lots down to the symbol's volume step, respects SYMBOL_VOLUME_LIMIT, shrinks the lot to fit the free margin and never raises it. If even the minimum lot doesn't fit, it skips the trade.

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