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
- Read
SYMBOL_VOLUME_MINandSYMBOL_VOLUME_MAXnext to the step. - 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.
SYMBOL_VOLUME_LIMITis the most the account may hold in one direction on the symbol; check it too for grids.
Code that fires it
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
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.
Related MQL5 errors
More rules on volume and money
- HighCalculated lot not rounded to the volume stepA 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.
- MediumNo margin check before a new tradeThe EA opens trades without asking whether the free margin covers them, so it keeps sending orders that the server refuses with 10019.
- HighDivision by the tick value without a zero checkA 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.
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.