Blog / Fix MT5 errors · MQL5 · Expert Advisors · Trade errors
Lot Size Normalization in MT5: Min Lot, Lot Step and Max Lot
Learn how MT5 lot size normalization works, including minimum volume, maximum volume and lot step, with practical MQL5 code examples.
· 6 min read
An Expert Advisor can calculate a position size correctly according to its risk settings and still have the broker reject the order.
One common reason is that the requested volume does not comply with the symbol's trading restrictions.
For example, an EA might calculate a volume of 0.037 lots, while the broker only accepts increments of 0.01. The requested volume does not align with the permitted volume step, potentially resulting in an invalid-volume error.
To prevent this, an EA must check three symbol properties before submitting an order:
- Minimum volume: The smallest permitted trade size.
- Maximum volume: The largest permitted volume for a single deal.
- Volume step: The permitted increment between valid volume sizes.
These restrictions vary between brokers and instruments. An EA should retrieve them dynamically rather than assume that every symbol accepts the same lot sizes.
1. Understanding Minimum Volume, Maximum Volume and Volume Step
These three properties determine which trade volumes a broker accepts for a particular symbol.
Minimum volume
The minimum volume is the smallest trade size permitted by the broker.
For example, if the minimum is 0.01 lots, an EA requesting 0.005 lots is below the permitted limit.
Maximum volume
The maximum volume is the largest volume permitted for an individual trade deal.
For example, if the maximum is 50 lots, an EA attempting to submit a 60-lot order exceeds the symbol's limit.
This is different from the aggregate volume limit, which can restrict the combined volume of open positions and pending orders in one direction.
Volume step
The volume step determines the increments in which trade size can increase.
For example, with a minimum volume of 0.01 and a volume step of 0.01, valid volumes include:
| Volume | Explanation |
|---|---|
| 0.01 | Minimum volume |
| 0.02 | One step above minimum |
| 0.03 | Two steps above minimum |
| 0.10 | Ten steps above minimum |
| 1.00 | One hundred steps above minimum |
A requested volume of 0.037 does not align with these increments.
The EA must adjust the volume to a permitted value or reject the request.
These properties are symbol-specific. A broker may use different volume restrictions for forex pairs, indices, commodities and other instruments.
2. How to Retrieve Volume Restrictions in MQL5
MQL5 provides built-in symbol properties that allow an EA to retrieve the broker's volume requirements.
The three main properties are:
SYMBOL_VOLUME_MINSYMBOL_VOLUME_MAXSYMBOL_VOLUME_STEP
Use SymbolInfoDouble() to retrieve them:
double min_volume;
double max_volume;
double volume_step;
if(!SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN, min_volume) ||
!SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX, max_volume) ||
!SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP, volume_step))
{
Print("Unable to retrieve symbol volume restrictions.");
return;
}
Print("Minimum volume: ", min_volume);
Print("Maximum volume: ", max_volume);
Print("Volume step: ", volume_step);The code retrieves the restrictions for the instrument attached to the chart.
Using _Symbol means the EA does not have to assume that every instrument follows the same volume rules.
There is another property worth checking when managing total exposure:
SYMBOL_VOLUME_LIMIT specifies the maximum aggregate volume allowed in one direction, including relevant open positions and pending orders.
A volume can therefore satisfy the minimum, maximum and step requirements but still exceed the broker's aggregate directional limit.
3. How to Normalize Lot Size Correctly
Retrieving the broker's restrictions is only the first step. The EA must also ensure that its calculated volume aligns with the permitted volume step.
A common mistake is relying on NormalizeDouble() alone.
For example:
double lot_size = NormalizeDouble(0.037, 2);This produces 0.04, but it does not establish that 0.04 is a valid volume for the symbol.
NormalizeDouble() controls decimal precision. It does not automatically align a volume with the broker's permitted increments.
For risk-based position sizing, rounding upwards can also increase the intended exposure.
A safer approach is to round down to the nearest permitted volume and reject requests outside the broker's minimum and maximum limits.
MQL5 volume normalization function
bool NormalizeVolume(const string symbol,
const double requested_volume,
double &normalized_volume)
{
double min_volume;
double max_volume;
double volume_step;
normalized_volume = 0.0;
if(!MathIsValidNumber(requested_volume) ||
requested_volume <= 0.0)
return false;
if(!SymbolInfoDouble(symbol, SYMBOL_VOLUME_MIN, min_volume) ||
!SymbolInfoDouble(symbol, SYMBOL_VOLUME_MAX, max_volume) ||
!SymbolInfoDouble(symbol, SYMBOL_VOLUME_STEP, volume_step))
return false;
if(volume_step <= 0.0)
return false;
if(requested_volume < min_volume ||
requested_volume > max_volume)
return false;
double steps = MathFloor(
(requested_volume - min_volume) / volume_step + 1e-8
);
normalized_volume = NormalizeDouble(
min_volume + steps * volume_step, 8
);
if(normalized_volume < min_volume ||
normalized_volume > max_volume ||
normalized_volume > requested_volume + 1e-10)
{
normalized_volume = 0.0;
return false;
}
return true;
}The function performs four checks:
- Validates the input: It rejects invalid or non-positive requested volumes.
- Retrieves broker restrictions: It obtains the minimum, maximum and volume step for the specified symbol.
- Checks the permitted range: It rejects requests below the minimum or above the maximum rather than silently changing the intended trade size.
- Aligns the volume with the step:
MathFloor()ensures the result is rounded down to the nearest permitted increment.
The final check ensures that the resulting volume does not exceed the original request or the broker's limits.
Example
Assume the broker specifies:
| Property | Value |
|---|---|
| Minimum volume | 0.01 |
| Maximum volume | 50.00 |
| Volume step | 0.01 |
| Requested volume | 0.037 |
| Normalized volume | 0.03 |
The function returns 0.03 rather than 0.04.
This prevents the EA from increasing the requested trade size simply to meet the broker's volume requirements.
If the requested volume is below the minimum or above the maximum, the function rejects it. This is preferable to automatically forcing an unsuitable trade size.
4. Using Normalized Volume Before Sending an Order
After normalizing the requested volume, the EA must use the returned value when preparing its trade.
For example:
double requested_lot = 0.037;
double valid_lot = 0.0;
if(NormalizeVolume(_Symbol, requested_lot, valid_lot))
{
Print("Normalized volume: ", valid_lot);
if(!trade.Buy(valid_lot, _Symbol))
{
Print("Buy request failed: ",
trade.ResultRetcodeDescription());
}
}
else
{
Print("Requested volume is outside permitted limits.");
return;
}This example uses the normalized volume when submitting a Buy request through the MQL5 CTrade class.
The normalization function does not guarantee that the broker will accept the order. Other conditions can still cause rejection, including insufficient margin, trading restrictions, invalid prices and unsupported filling policies.
For additional pre-trade validation, developers can use OrderCheck() with a properly constructed trade request (see validating lot size and margin before sending an order). The EA should also inspect the trade server's response after submitting an order.
A valid volume is necessary, but it does not guarantee successful execution.
5. How to Retrieve Volume Restrictions in MQL4
MQL4 uses a different set of identifiers to retrieve the same basic volume restrictions.
Instead of the MQL5 symbol properties, an EA can use MarketInfo():
double min_lot = MarketInfo(Symbol(), MODE_MINLOT);
double max_lot = MarketInfo(Symbol(), MODE_MAXLOT);
double lot_step = MarketInfo(Symbol(), MODE_LOTSTEP);
Print("Minimum lot: ", min_lot);
Print("Maximum lot: ", max_lot);
Print("Lot step: ", lot_step);These values allow an MQL4 EA to determine the permitted trading volume for the current symbol.
The EA should apply the same validation principle before calling OrderSend():
- Reject volumes below the minimum.
- Reject volumes above the maximum.
- Align accepted volumes with the broker's lot step.
Developers porting an EA from MT4 to MT5 should pay attention to this difference. Although the underlying volume restrictions are similar, the functions and symbol properties used to retrieve them are not identical.
6. Common Lot Size Normalization Mistakes
Even when an EA retrieves the correct broker settings, poor volume-handling logic can still cause problems.
Watch out for these mistakes:
- Relying only on decimal rounding:
NormalizeDouble()does not guarantee that a volume aligns with the broker's permitted step. - Always rounding upwards: Increasing a calculated volume can exceed the trader's intended risk.
- Ignoring the minimum volume: The EA may attempt to submit a position smaller than the broker permits.
- Ignoring the maximum volume: Large calculated positions may exceed the symbol's individual deal limit.
- Using fixed lot assumptions: Hardcoding a 0.01 minimum or step can cause problems when the EA is used with another broker or instrument.
- Ignoring aggregate volume restrictions: A trade can satisfy
SYMBOL_VOLUME_MAXbut still exceedSYMBOL_VOLUME_LIMITwhen existing positions and pending orders are considered.
A reliable EA should retrieve the relevant symbol properties dynamically, validate the requested volume and account for existing exposure before every order submission.
Conclusion
MT5 lot size normalization helps prevent trade requests from failing because of invalid volume.
The minimum volume, maximum volume and volume step determine which trade sizes a broker accepts. An EA that ignores these restrictions can encounter invalid-volume errors even when its position-sizing calculations are otherwise correct.
By retrieving symbol properties dynamically, rounding down to valid increments and rejecting requests outside permitted limits, developers can make their trading systems more adaptable across brokers and instruments.
Build a bot from your idea
Describe your trading idea and the AI writes MT4 or MT5 code for you to review and test, with a plain-English explanation and setup steps. Your first bot is free.