Blog
How to Fix “Error 131: Invalid Trade Volume” in MT4/MT5: The Lot Sizing Guide
Author: The Architect (Senior MQL Developer @ Shop Forex EA)
Topic: Execution Troubleshooting
Difficulty: Intermediate
Related: How to Fix Error 130 (Invalid Stops)
You calculated your risk perfectly. You clicked “Buy”. And then… nothing happened. The Journal tab spits out a cold rejection: OrderSend failed, error: 131.
While Error 130 is about Price Distance, Error 131 (ERR_INVALID_TRADE_VOLUME) is strictly about Size Granularity. It means your Expert Advisor (EA) or manual entry is attempting to open a Lot Size that violates the Broker’s mathematical contract constraints.

What Does “Error 131” Technically Mean?
In the MetaTrader architecture, Error 131 indicates that the volume parameter passed to the OrderSend() function fails to match the strict arithmetic progression defined by the server.
Every trading instrument (Forex, Indices, Crypto) has three rigid constraints:
- Minimum Lot (MODE_MINLOT): The absolute floor (e.g., 0.01 for Forex, but often 1.0 for Indices like US30).
- Maximum Lot (MODE_MAXLOT): The ceiling per ticket (e.g., 50.0 or 100.0).
- Lot Step (MODE_LOTSTEP): The valid increment unit (e.g., you can trade 0.1 or 0.2, but not 0.15).
“Error 131 is rarely a broker bug. It is almost always a ‘Rounding Error’ in your Money Management algorithm.”
The 3 Mathematical Causes of Error 131
1. The “Micro-Lot” Misunderstanding (Cent vs. Standard)
This is the most frequent cause for traders migrating from Demo to Real accounts or shifting between Account Types.
- On a Standard account, the minimum lot is typically
0.01. - On Cent accounts, the minimum might display as
0.1(representing 1000 units). - On Institutional ECN accounts, symbols like XAUUSD or BTCUSD often enforce a minimum of
1.0lot.
Scenario: If your risk calculator sets a trade for 0.5 lots on Bitcoin, but the Broker’s minimum is 1.0, Error 131 is inevitable.
2. The “Lot Step” Violation (The Hidden Killer)
This is a subtle error that crashes sophisticated Risk Management EAs. Suppose your algorithm calculates a risk-based lot size of 0.12345.
| Broker Step | Your Calculation | Result | Reason |
|---|---|---|---|
| 0.01 | 0.12 | Accepted | Fits the step |
| 0.10 | 0.15 | Error 131 | 0.15 is not a multiple of 0.1 |
Sending a raw, un-normalized value like 0.15 to a broker with a 0.1 step will result in immediate execution rejection.

Figure 3: The “Hidden Killer”. Sending 0.15 lots to a broker with a 0.1 step will always fail. You must round down
3. Exceeding Maximum Volume (Martingale Death)
This affects high-net-worth traders or aggressive Martingale EAs. If a Martingale strategy doubles the lot size continuously (0.1 → 0.2 → … → 51.2), it will eventually hit the Max Lot limit. The next trade will fail with Error 131, potentially leaving a losing basket of trades unprotected and leading to a Margin Call.
How to Diagnose Error 131 (Manual Fix)
Before blaming the EA code, verify the hard limits of your specific account:
Step 1: Check Contract Specification
- Right-click the symbol in Market Watch.
- Select Specification.
- Scroll down to find Volume min, Volume max, and Volume step.

Step 2: Adjust Your EA Inputs
If your account requires a minimum of 0.1 lots, ensure your EA’s StartLot or RiskPercent settings are sufficiently high to generate at least 0.1 lots. If the math results in 0.04, the trade will fail.
For Developers: MQL4 Code to Normalize Lots (The Right Way)
As an “Architect”, you must sanitize inputs before sending them to the server.
NormalizeDouble() function for Lot Sizing. It rounds to the nearest number, which can round UP to an invalid step or exceeding your risk. Always use MathFloor logic to round DOWN to the safe step.// Robust Function to Normalize Lot Size
double NormalizeLot(string symbol, double lot) {
// 1. Get Dynamic Broker Constraints
double minLot = MarketInfo(symbol, MODE_MINLOT);
double maxLot = MarketInfo(symbol, MODE_MAXLOT);
double lotStep = MarketInfo(symbol, MODE_LOTSTEP);
// 2. Align to Lot Step (MathFloor Logic)
// Example: If Lot=0.15 and Step=0.1 -> Result 0.1 (Safe)
double normalizedLot = MathFloor(lot / lotStep) * lotStep;
// 3. Clamp between Min and Max
if (normalizedLot < minLot) normalizedLot = minLot; // Prevent Underflow if (normalizedLot > maxLot) normalizedLot = maxLot; // Prevent Overflow
return(normalizedLot);
}
Code Logic Breakdown:
- Retrieval: We pull `MODE_MINLOT` dynamically. Never hardcode “0.01” because Indices often use “0.1” or “1.0”.
- Step Alignment: The formula
MathFloor(lot / lotStep) * lotStepis the industry standard for safe volume calculation. - Clamping: Ensures the volume never exceeds the Broker’s ceiling, protecting against Martingale errors.

Figure 4: The “Safety Logic” inside Shop Forex EA products. We sanitize every order volume before sending it to the broker.
Does Your EA Handle Lot Sizing Automatically?
Calculating lot sizes manually or using poorly coded scripts leads to calculation errors, especially when trading Assets like US30, NAS100, or Bitcoin where lot steps vary wildly.
At Shop Forex EA, our bots utilize the Smart Money Management Module. This internal logic automatically scans the broker’s specific requirements (Forex vs Crypto vs Indices) and adjusts your trade volume instantly.
Frequently Asked Questions
Can I get Error 131 on a Demo account?
Yes. Demo accounts simulate real server rules. If you try to trade 0.01 lots on a Demo account that simulates an Institutional feed (Min Lot 1.0), you will get Error 131. This is actually a sign of a good broker simulation.
Is Error 131 related to “Not Enough Money” (Error 134)?
No. Error 134 (ERR_NOT_ENOUGH_MONEY) means you don’t have enough Free Margin. Error 131 means the number format you typed is invalid mathematically, regardless of your account balance.
Technical Conclusion:
Error 131 is a strict gatekeeper of the Broker’s contract. To bypass it, your EA must respect the Lot Step mathematics. Always normalize your volumes using MathFloor logic before sending them to the market.