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

MT4 and MQL4 technical notes eyecatch image with a degu mascot, code panel, and trading chart background
スポンサーリンク

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 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

CauseExampleTypical Fix
Lot size is below the minimum0.001 when MODE_MINLOT is 0.01Use at least the minimum allowed lot
Lot size does not match the lot step0.015 when MODE_LOTSTEP is 0.01Adjust the volume to the allowed step
Lot size is above the maximum60.0 when MODE_MAXLOT is 50.0Limit the requested volume to the maximum
Risk-based calculation returns an unusual decimalA calculation produces 0.03746Align the result with MODE_LOTSTEP
The EA assumes every symbol has the same lot rulesFX settings are reused for metals or CFDsRead the volume conditions for the actual symbol
An invalid calculation returns zero or a negative valueRisk calculation fails and returns 0Stop 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 ValueMeaning
MODE_MINLOTMinimum trade volume allowed for the symbol
MODE_LOTSTEPAllowed increment between lot sizes
MODE_MAXLOTMaximum 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 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.25

But 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 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 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.0374628

That number may be correct from a risk-calculation perspective but invalid as an MT4 trade volume.

The normal workflow is:

  1. Calculate the raw risk-based volume.
  2. Confirm that the calculation produced a positive value.
  3. Read MODE_MINLOT, MODE_LOTSTEP, and MODE_MAXLOT.
  4. Align the volume to the allowed lot step.
  5. Check available margin.
  6. 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.

ErrorMeaningMain Check
131Invalid trade volumeMINLOT, LOTSTEP, MAXLOT
134 Not enough moneyAvailable 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:

  1. Confirm that the actual error is 131.
  2. Print the requested lot value.
  3. Check MODE_MINLOT.
  4. Check MODE_LOTSTEP.
  5. Check MODE_MAXLOT.
  6. Check the raw value returned by automatic lot calculations.
  7. Align the volume to the lot step.
  8. 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_MINLOT for the test symbol.
  • MODE_LOTSTEP for the test symbol.
  • MODE_MAXLOT for the test symbol.
  • Whether the calculated lot becomes zero, negative, or unusually large.
Strategy Tester tip:
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.

ErrorMeaningMain Area to Check
129 Invalid priceExecution price
130 Invalid stopsSL, TP, pending-order distance
131Invalid trade volumeMinimum lot, lot step, maximum lot
134 Not enough moneyFree 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, and MODE_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.

Back to MT4/MQL4 Technical Notes

タイトルとURLをコピーしました