Skip to content

EA Doctor rule · Volume and money

Calculated lot not checked against the minimum and maximum

A calculated lot is sent without checking the symbol's minimum and maximum volume, so small accounts and large multipliers get 10014.

Why it matters

Each symbol has a smallest and a largest volume per order: SYMBOL_VOLUME_MIN and SYMBOL_VOLUME_MAX. A risk formula on a small balance easily lands below the minimum, and a martingale or grid multiplier above the maximum after a few steps.

Both are refused with 10014 (invalid volume). Below the minimum the right answer is usually to skip the trade, not to round up and take more risk than planned.

When the rule fires

The EA trades and a lot or volume variable is assigned the result of arithmetic (as in the volume step rule), and SYMBOL_VOLUME_MIN or SYMBOL_VOLUME_MAX (or CSymbolInfo::LotsMin() / LotsMax()) is missing from the file. The finding names the one that is missing.

When it stays quiet

Both limits are read anywhere in the file, or the lots are fixed inputs passed on unchanged.

How to fix it

  1. Read SYMBOL_VOLUME_MIN and SYMBOL_VOLUME_MAX next to the step.
  2. After rounding to the step: below the minimum, skip the trade (or say so); above the maximum, cap it, or split it into several orders if the strategy allows.
  3. SYMBOL_VOLUME_LIMIT is the most the account may hold in one direction on the symbol; check it too for grids.

Code that fires it

MQL5 · fires this rule
double SizedLots(const double balanceShare)
  {
   const double step = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);
   double lots = AccountInfoDouble(ACCOUNT_BALANCE) * balanceShare / 10000.0;
   return(MathFloor(lots / step) * step);
  }

void OpenBuy()
  {
   if(!trade.Buy(SizedLots(0.5), _Symbol))
      Print("Buy failed: ", trade.ResultRetcodeDescription());
  }

Fixed code

MQL5 · fixed
double SizedLots(const double balanceShare)
  {
   const double step = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);
   const double minV = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);
   const double maxV = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX);
   if(step <= 0.0)
      return(0.0);
   double lots = AccountInfoDouble(ACCOUNT_BALANCE) * balanceShare / 10000.0;
   lots = MathFloor(lots / step) * step;
   if(lots < minV)
      return(0.0);
   return(MathMin(lots, maxV));
  }

void OpenBuy()
  {
   const double lots = SizedLots(0.5);
   if(lots <= 0.0)
     {
      Print("The calculated lot is below the minimum volume of ", _Symbol);
      return;
     }
   if(!trade.Buy(lots, _Symbol))
      Print("Buy failed: ", trade.ResultRetcodeDescription());
  }

The fixed code shows this rule’s fix and compiles in MetaEditor for MetaTrader 5 (with CTrade trade, InpLots and InpMagic declared, as in a typical EA). Other rules may still apply to it as a fragment: check your whole EA.

More rules on volume and money

Sources

Get your EA fixed

Check a whole EA for this and 29 other mistakes with EA Doctor, free and in your browser. Or send it to us: we confirm the price in writing, then fix it.