スポンサーリンク
OrderSend Error 131 in MT4/MQL4: Invalid Trade Volume Fix

OrderSend Error 131 in MT4/MQL4 means that the trade volume passed to OrderSend() is invalid.
The MQL4 error name is ERR_INVALID_TRADE_VOLUME.
In most cases, the lot size is smaller than the broker’s minimum lot, larger than the maximum lot, or does not match the allowed lot step. This often appears when an EA calculates the lot size automatically.
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 for the symbol, then adjust the calculated lot size to a valid lot step before calling OrderSend().What Does OrderSend Error 131 Mean?
- Error code: 131
- Error name: ERR_INVALID_TRADE_VOLUME
- Meaning: Invalid trade volume
Error 131 means that MT4 or the trade server rejected the requested lot size.
The relevant parameter is the trade volume supplied to OrderSend().
int ticket = OrderSend(
Symbol(),
OP_BUY,
Lots,
Ask,
Slippage,
StopLoss,
TakeProfit,
"buy order",
Magic,
0,
clrBlue
); Even when the entry signal, price, SL, and TP are valid, the order can still fail if Lots does not satisfy the symbol’s volume rules.
Common Causes of OrderSend Error 131
| Cause | Example | Typical Fix |
|---|---|---|
| Lot size is below the minimum | 0.001 when MODE_MINLOT is 0.01 | Use at least the minimum allowed lot |
| Lot size does not match the lot step | 0.015 when MODE_LOTSTEP is 0.01 | Adjust the volume to the allowed step |
| Lot size is above the maximum | 60.0 when MODE_MAXLOT is 50.0 | Limit the requested volume to the maximum |
| Risk-based calculation returns an unusual decimal | A calculation produces 0.03746 | Align the result with MODE_LOTSTEP |
| The EA assumes every symbol has the same lot rules | FX settings are reused for metals or CFDs | Read the volume conditions for the actual symbol |
| An invalid calculation returns zero or a negative value | Risk calculation fails and returns 0 | Stop the order process instead of automatically opening the minimum lot |
Check MINLOT, LOTSTEP and MAXLOT
The first step is to read the trading-volume rules for the symbol.
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);| MQL4 Value | Meaning |
|---|---|
MODE_MINLOT | Minimum trade volume allowed for the symbol |
MODE_LOTSTEP | Allowed increment between lot sizes |
MODE_MAXLOT | Maximum trade volume allowed for the symbol |
These values are symbol-specific and can differ between brokers and account types. They can also differ between FX pairs, metals, indices, and other instruments.
Do not hard-code lot rules:
An EA that works with a
An EA that works with a
0.01 minimum lot and 0.01 lot step in one environment may fail in another.
Reading the current symbol conditions makes the order logic more portable.Lot Step Is Often the Real Cause of Error 131
A lot size can be between the minimum and maximum values and still be invalid.
It must also match the allowed MODE_LOTSTEP.
For example, suppose the symbol uses:
MODE_MINLOT = 0.01
MODE_LOTSTEP = 0.01
MODE_MAXLOT = 50.00 The following volumes fit the 0.01 step:
0.01
0.02
0.03
0.10
1.25But a calculated value such as:
0.037 is not aligned with a 0.01 lot step and should be adjusted before the trade request is sent.
NormalizeDouble Alone Does Not Fix LotStep
A common mistake is to use only:
lots = NormalizeDouble(lots, 2); This changes the number of decimal places, but it does not guarantee that the value is a valid multiple of MODE_LOTSTEP.
For example, if:
MODE_LOTSTEP = 0.25 a value such as 0.30 can have valid decimal precision while still not matching the required lot increment.
Key point:
First align the volume with
First align the volume with
MODE_LOTSTEP.
Then use NormalizeDouble() to clean up floating-point precision.MQL4 Code Example: Adjust Lot Size Automatically
The following helper functions adjust a positive lot value to the symbol’s minimum, step, and maximum conditions.
If the original calculation returns zero or a negative value, the function returns 0 instead of automatically forcing a minimum-size trade.
//+------------------------------------------------------------------+
//| Return decimal digits needed 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 the symbol's volume rules |
//+------------------------------------------------------------------+
double AdjustLot(double lot)
{
if(lot <= 0)
return 0;
double minLot =
MarketInfo(Symbol(), MODE_MINLOT);
double lotStep =
MarketInfo(Symbol(), MODE_LOTSTEP);
double maxLot =
MarketInfo(Symbol(), MODE_MAXLOT);
if(minLot <= 0 ||
lotStep <= 0 ||
maxLot <= 0)
{
Print("Invalid symbol lot settings.",
" MinLot=", minLot,
" LotStep=", lotStep,
" MaxLot=", maxLot);
return 0;
}
// Limit the requested volume to the broker range.
if(lot > maxLot)
lot = maxLot;
// Align downward to the allowed lot step.
lot =
MathFloor((lot + 0.000000001) / lotStep)
* lotStep;
// If the adjusted value is below the minimum,
// use the minimum lot only when the original
// requested lot was positive.
if(lot < minLot)
lot = minLot;
int lotDigits =
LotDigitsByStep(lotStep);
lot =
NormalizeDouble(lot, lotDigits);
return lot;
}Usage example:
double calculatedLot = 0.037;
double lots =
AdjustLot(calculatedLot);
if(lots <= 0)
{
Print("Lot calculation is invalid.");
return;
}
RefreshRates();
double price =
NormalizeDouble(Ask, Digits);
ResetLastError();
int ticket = OrderSend(
Symbol(),
OP_BUY,
lots,
price,
Slippage,
0,
0,
"buy order",
Magic,
0,
clrBlue
);
if(ticket < 0)
{
int err = GetLastError();
Print("OrderSend failed. Error=", err,
" Lots=", lots);
} Be careful with automatic correction:
If a risk calculation unexpectedly returns
If a risk calculation unexpectedly returns
0 or a negative value, automatically replacing it with the minimum lot can create an unintended trade.
Treat an invalid calculation as an error and stop the entry process.Risk-Based Lot Calculations Can Cause Error 131
Error 131 often appears in EAs that calculate trade volume from account risk.
For example:
double lots =
riskMoney / estimatedLossPerLot;The mathematical result may be:
0.0374628That number may be correct from a risk-calculation perspective but invalid as an MT4 trade volume.
The normal workflow is:
- Calculate the raw risk-based volume.
- Confirm that the calculation produced a positive value.
- Read
MODE_MINLOT,MODE_LOTSTEP, andMODE_MAXLOT. - Align the volume to the allowed lot step.
- Check available margin.
- Send the order.
Valid Lot Size but Not Enough Margin Is Error 134
A lot size can be structurally valid but still be too large for the account’s available margin. That is a different problem from Error 131.
| Error | Meaning | Main Check |
|---|---|---|
| 131 | Invalid trade volume | MINLOT, LOTSTEP, MAXLOT |
| 134 | Not enough money | Available free margin |
You can perform an additional margin check after the volume itself has been validated.
double marginAfterTrade =
AccountFreeMarginCheck(
Symbol(),
OP_BUY,
lots
);
if(marginAfterTrade <= 0)
{
Print("Not enough free margin for Lots=", lots);
return;
}How to Debug OrderSend Error 131
When Error 131 occurs, print both the requested lot size and the symbol’s volume conditions.
double minLot =
MarketInfo(Symbol(), MODE_MINLOT);
double lotStep =
MarketInfo(Symbol(), MODE_LOTSTEP);
double maxLot =
MarketInfo(Symbol(), MODE_MAXLOT);
Print("RequestedLots=", Lots);
Print("MinLot=", minLot);
Print("LotStep=", lotStep);
Print("MaxLot=", maxLot);
double adjustedLots =
AdjustLot(Lots);
Print("AdjustedLots=", adjustedLots);Then inspect the Experts and Journal tabs in MT4.
A practical troubleshooting order is:
- Confirm that the actual error is 131.
- Print the requested lot value.
- Check
MODE_MINLOT. - Check
MODE_LOTSTEP. - Check
MODE_MAXLOT. - Check the raw value returned by automatic lot calculations.
- Align the volume to the lot step.
- After volume validation, check margin separately.
Error 131 in MT4 Strategy Tester
OrderSend Error 131 can also occur during an MT4 Strategy Tester backtest.
The entry logic may be working correctly while the tester rejects the volume produced by the EA. This is especially common with automatic lot sizing.
Check:
- The fixed lot value in the EA inputs.
- The lot value calculated during the test.
MODE_MINLOTfor the test symbol.MODE_LOTSTEPfor the test symbol.MODE_MAXLOTfor the test symbol.- Whether the calculated lot becomes zero, negative, or unusually large.
Strategy Tester tip:
Add a temporary
Add a temporary
Print() immediately before OrderSend().
Seeing the exact lot value used at the moment of failure is usually much more useful than inspecting the EA input value alone.Error 129 vs 130 vs 131 vs 134
These common OrderSend errors refer to different parts of the trade request.
| Error | Meaning | Main Area to Check |
|---|---|---|
| 129 | Invalid price | Execution price |
| 130 | Invalid stops | SL, TP, pending-order distance |
| 131 | Invalid trade volume | Minimum lot, lot step, maximum lot |
| 134 | Not enough money | Free margin and requested trade size |
Related MQL4 OrderSend Guides
FAQ About OrderSend Error 131
Q. What does OrderSend Error 131 mean in MT4?
OrderSend Error 131 is ERR_INVALID_TRADE_VOLUME. It means that the lot size passed to OrderSend() does not satisfy the trading-volume rules for the symbol.
Q. How do I check the minimum lot in MQL4?
Use MarketInfo(Symbol(), MODE_MINLOT). You should also check MODE_LOTSTEP and MODE_MAXLOT because a volume can be above the minimum and still be invalid.
Q. Why does 0.015 lots cause Error 131?
If MODE_LOTSTEP is 0.01, a volume such as 0.015 does not align with the allowed lot increment. Adjust the calculated volume to the broker’s lot step before sending the order.
Q. Does NormalizeDouble() fix Error 131?
Not by itself. NormalizeDouble() adjusts decimal precision, but the lot value must also match MODE_LOTSTEP and remain between MODE_MINLOT and MODE_MAXLOT.
Q. Can automatic lot calculation cause Error 131?
Yes. A risk-based lot calculation can return a mathematically valid number that does not match the symbol’s lot step. Validate and adjust the calculated volume before calling OrderSend().
Q. Is Error 131 the same as not enough money?
No. Error 131 means the trade volume itself is invalid. If the volume is valid but the account does not have enough free margin to open the trade, MT4 normally reports Error 134, ERR_NOT_ENOUGH_MONEY.
Q. Should an invalid lot calculation automatically use the minimum lot?
Not when the calculation itself returned zero or a negative value. In that situation, it is safer to treat the lot calculation as invalid and stop the order process instead of automatically opening a minimum-size trade.
Q. How do I fix OrderSend Error 131?
Print the requested lot size, check MODE_MINLOT, MODE_LOTSTEP, and MODE_MAXLOT, align the lot to the allowed step, and verify that the resulting value is positive before calling OrderSend(). Check free margin separately after the volume is valid.
Summary
OrderSend Error 131 in MT4/MQL4 is ERR_INVALID_TRADE_VOLUME.
The fastest way to diagnose it is to compare the lot value actually passed to OrderSend() with the symbol’s minimum lot, lot step, and maximum lot.
- Error 131 means Invalid Trade Volume.
- Check
MODE_MINLOT,MODE_LOTSTEP, andMODE_MAXLOT. - A lot size can be inside the min/max range and still fail if it does not match
MODE_LOTSTEP. NormalizeDouble()alone does not guarantee a valid lot step.- Validate automatic risk-based lot calculations before trading.
- Do not automatically convert a failed zero/negative lot calculation into a minimum-lot trade.
- Error 131 concerns volume rules; Error 134 concerns insufficient margin.
- Print the actual lot value immediately before
OrderSend()when debugging.
