Trade server return code
10019 TRADE_ RETCODE_ NO_ MONEY
Not enough money: the free margin does not cover the order
What it means
The account's free margin is smaller than the margin the new order needs. Margin depends on the lot, the price, the contract size and the leverage, so an order that fits at one moment can fail later on the same account.
Common causes
- A grid or martingale EA multiplying the lot at each step until the next order needs more margin than is free.
- Several EAs on one account, each sizing its trades as if it were alone.
- Floating losses that have reduced the free margin since the lot was chosen.
- A lower leverage on a symbol than the EA assumes (many brokers set lower leverage on metals, indices and crypto).
A real scenario
A grid EA doubles the lot on each level on a small account. At level 7 the next order is 0.64 lots and needs more margin than the account has free: 10019. The EA resent it on every tick, so the journal filled with failures while the basket kept losing. The grid and martingale calculator shows in advance at which level this happens.
How to fix it
- Compute the margin with
OrderCalcMargin()and compare it withACCOUNT_MARGIN_FREEbefore sending. - Reduce the lot or skip the trade when it does not fit, and log the numbers.
- In grid and recovery EAs, cap the number of levels so the last one still fits with room for the floating loss.
- This check is the first one MetaQuotes lists for Market products ("Insufficient funds to perform trade operation").
Fixed MQL5 code
bool EnoughMargin(const ENUM_ORDER_TYPE type, const double lots)
{
MqlTick t;
if(!SymbolInfoTick(_Symbol, t))
return false;
double price = (type == ORDER_TYPE_BUY) ? t.ask : t.bid;
double margin = 0.0;
if(!OrderCalcMargin(type, _Symbol, lots, price, margin))
return false;
double freeMargin = AccountInfoDouble(ACCOUNT_MARGIN_FREE);
if(margin > freeMargin)
{
PrintFormat("Need %.2f margin for %.2f lots, free margin is %.2f: trade skipped", margin, lots, freeMargin);
return false;
}
return true;
}
A focused example for MetaTrader 5: adapt names, magic number and limits to your EA, and test it on a demo account first.
Related codes
- 10014Invalid VolumeTRADE_RETCODE_INVALID_VOLUMEInvalid volume: the lot breaks the symbol's minimum, maximum or step
- 10040Position LimitTRADE_RETCODE_LIMIT_POSITIONSPosition limit reached: the account holds as many positions as the server allows
EA Doctor rules that catch it
- 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.
Sources
Get your EA fixed
Still failing with 10019? Send us the EA and the journal lines: we find the cause in the code and fix it. Or check it yourself first with the EA Doctor.