Advertisement
OrderSend Error 131 in MT4/MQL4: Invalid Trade Volume Fix

OrderSend Error 131 in MT4/MQL4 means that the trade volume is invalid. In most cases, this error occurs when the lot size does not match the broker’s trading conditions.
For example, the lot size may be smaller than the minimum lot, larger than the maximum lot, or not aligned with the required lot step.
Quick answer:
OrderSend Error 131 is ERR_INVALID_TRADE_VOLUME. Check
OrderSend Error 131 is ERR_INVALID_TRADE_VOLUME. Check
MODE_MINLOT, MODE_LOTSTEP, and MODE_MAXLOT, then adjust the lot size before calling OrderSend().What Does OrderSend Error 131 Mean?
In MQL4, Error 131 is known as:
- Error code: 131
- Error name: ERR_INVALID_TRADE_VOLUME
- Meaning: Invalid trade volume
This means that the lot size passed to OrderSend() is not accepted by the broker.
The problem is not usually the entry signal itself, but the value of the Lots parameter.
OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLoss, TakeProfit, "buy order", Magic, 0, clrBlue); If Lots does not follow the broker’s rules, MT4 may return Error 131 and the order will not be placed.
Common Causes of OrderSend Error 131
| Cause | Example | How to Fix |
|---|---|---|
| Lot size is smaller than the minimum lot | Sending 0.001 when the minimum lot is 0.01 | Check MODE_MINLOT and use at least the minimum lot |
| Lot size does not match the lot step | Sending 0.015 when the lot step is 0.01 | Round the lot size according to MODE_LOTSTEP |
| Lot size is larger than the maximum lot | Sending 100.0 when the maximum lot is 50.0 | Check MODE_MAXLOT and limit the lot size |
| Lot value is calculated dynamically but not adjusted | A risk-based lot calculation returns an invalid decimal value | Normalize and adjust the calculated lot before using OrderSend() |
How to Check Broker Lot Conditions in MQL4
The first step is to check the broker’s lot conditions for the current symbol.
You can get these values with MarketInfo().
double minLot = MarketInfo(Symbol(), MODE_MINLOT);
double lotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
double maxLot = MarketInfo(Symbol(), MODE_MAXLOT);
Print("Minimum lot: ", minLot);
Print("Lot step: ", lotStep);
Print("Maximum lot: ", maxLot);These values can differ depending on the broker, account type, and symbol. Even if the EA works on one broker, it may return Error 131 on another broker if the lot rules are different.
Important:
Do not assume that all brokers use the same lot settings. Always check
Do not assume that all brokers use the same lot settings. Always check
MODE_MINLOT, MODE_LOTSTEP, and MODE_MAXLOT for the symbol used by the EA.MQL4 Code Example: Adjust Lot Size Automatically
The safest approach is to adjust the lot size before calling OrderSend().
The function below checks the minimum lot, lot step, and maximum lot, then returns a valid lot size.
//+------------------------------------------------------------------+
//| Get the number of decimal digits required for the lot step |
//+------------------------------------------------------------------+
int LotDigitsByStep(double lotStep)
{
int digits = 0;
while(lotStep < 1.0 && digits < 8)
{
lotStep *= 10.0;
digits++;
}
return digits;
}
//+------------------------------------------------------------------+
//| Adjust lot size to match broker conditions |
//+------------------------------------------------------------------+
double AdjustLot(double lot)
{
double minLot = MarketInfo(Symbol(), MODE_MINLOT);
double lotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
double maxLot = MarketInfo(Symbol(), MODE_MAXLOT);
if(lotStep <= 0)
lotStep = 0.01;
// Limit the lot size between minimum and maximum values
if(lot < minLot)
lot = minLot;
if(lot > maxLot)
lot = maxLot;
// Round down to the nearest valid lot step
lot = MathFloor((lot + 0.00000001) / lotStep) * lotStep;
return NormalizeDouble(lot, LotDigitsByStep(lotStep));
}You can use this function before sending an order.
double inputLot = 0.037;
double lots = AdjustLot(inputLot);
RefreshRates();
int ticket = OrderSend(
Symbol(),
OP_BUY,
lots,
Ask,
Slippage,
0,
0,
"buy order",
Magic,
0,
clrBlue
);
if(ticket < 0)
{
int err = GetLastError();
Print("OrderSend failed. Error: ", err, " Lots: ", lots);
} If the broker accepts only 0.01 lot steps, a value like 0.037 will be adjusted to a valid value before the order is sent.
How to Debug OrderSend Error 131
When Error 131 occurs, print the lot conditions and the actual lot value used by the EA. This makes it much easier to identify the cause.
double minLot = MarketInfo(Symbol(), MODE_MINLOT);
double lotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
double maxLot = MarketInfo(Symbol(), MODE_MAXLOT);
Print("Lots before adjustment: ", Lots);
Print("Minimum lot: ", minLot);
Print("Lot step: ", lotStep);
Print("Maximum lot: ", maxLot);
double adjustedLots = AdjustLot(Lots);
Print("Lots after adjustment: ", adjustedLots);Then check the Experts tab or the Journal tab in MT4. If the printed lot value is smaller than the minimum lot or does not match the lot step, that is likely the reason for Error 131.
Error 131 in Strategy Tester
OrderSend Error 131 can also occur in the MT4 Strategy Tester. This often happens when the lot size used in the test does not match the symbol settings in the selected testing environment.
For example, the EA may use a fixed lot value or a risk-based lot calculation that produces an invalid value. In that case, the order may fail even though the entry condition itself is correct.
Note:
Error 131 is about invalid trade volume. If the account does not have enough margin, MT4 usually returns Error 134, not Error 131.
Error 131 is about invalid trade volume. If the account does not have enough margin, MT4 usually returns Error 134, not Error 131.
When testing an EA, check the following:
- The fixed lot value set in the EA inputs
- The minimum lot of the selected symbol
- The lot step of the selected symbol
- The maximum lot of the selected symbol
- The value returned by any automatic lot calculation
Related MQL4 Errors
OrderSend Error 131 is only one of several common order errors in MT4. The table below shows related errors that are often confused with Error 131.
| Error Code | Error Name | Main Cause |
|---|---|---|
| 129 | ERR_INVALID_PRICE | The order price is invalid |
| 130 | ERR_INVALID_STOPS | Stop loss, take profit, or pending order price is too close to the current price |
| 131 | ERR_INVALID_TRADE_VOLUME | The lot size is invalid |
| 134 | ERR_NOT_ENOUGH_MONEY | The account does not have enough margin |
FAQ About OrderSend Error 131
What does OrderSend Error 131 mean in MT4?
OrderSend Error 131 means ERR_INVALID_TRADE_VOLUME. It occurs when the lot size used in OrderSend() does not match the broker’s trading conditions.
Why does Error 131 occur even when the entry signal is correct?
Error 131 is usually caused by the lot size, not by the entry signal. Even if the buy or sell condition is correct, the order will fail if the lot size is smaller than the minimum lot, larger than the maximum lot, or not aligned with the lot step.
How can I check the minimum lot in MQL4?
You can check the minimum lot by using MarketInfo(Symbol(), MODE_MINLOT). You should also check MODE_LOTSTEP and MODE_MAXLOT before sending an order.
Can automatic lot calculation cause Error 131?
Yes. A risk-based lot calculation may return an invalid decimal value. The calculated lot should be adjusted according to the broker’s minimum lot, lot step, and maximum lot before calling OrderSend().
Is Error 131 the same as not enough money?
No. Error 131 means invalid trade volume. If the account does not have enough margin, MT4 usually returns Error 134, which means ERR_NOT_ENOUGH_MONEY.
How do I fix OrderSend Error 131?
Check the broker’s minimum lot, lot step, and maximum lot. Then adjust the lot size before using OrderSend(). Printing the lot value and broker conditions in the Experts tab is also helpful for debugging.
Summary
OrderSend Error 131 in MT4/MQL4 means that the trade volume is invalid. In most cases, the problem is caused by an incorrect lot size.
- Error 131 is ERR_INVALID_TRADE_VOLUME.
- Check
MODE_MINLOT,MODE_LOTSTEP, andMODE_MAXLOT. - Adjust the lot size before calling
OrderSend(). - Use
Print()logs to confirm the actual lot value used by the EA. - If the problem is margin-related, check Error 134 instead.
If your EA returns Error 131, start by printing the lot size and the broker’s lot conditions. Understanding why the order failed is the fastest way to fix the EA and avoid the same error in future tests.
Related: OrderSend Error 129 in MT4/MQL4
Related: OrderSend Error 130 in MT4/MQL4
