How lot size is calculated
How the EA calculates lot size from account balance, risk percentage, and stop-loss distance at the moment of execution.
Lot size is computed by the EA at the moment of execution using MT5's native OrderCalcProfit:
lots = (balance × risk%) / monetaryLossPerLotAtSLThis means the actual risk in account currency is exact: there is no broker-dependent pip-value table to maintain. Symbol contract size, currency conversion and tick value are all handled by MT5.
What goes into the calculation
Four inputs, resolved per account at execution time:
| Input | Where it comes from |
|---|---|
| Balance | The account balance reported by that MT5 terminal when the signal arrives |
| Risk % | The account card, unless the payload overrides it |
| Stop-loss distance | The sl in the payload, either a price or a distance in pips |
| Loss per lot at that stop | OrderCalcProfit, asked of the broker for that exact symbol |
Only the first two differ between accounts receiving the same signal. That is the whole mechanism behind sending one alert to several accounts and having each take a position sized to itself.
Why the same signal produces a different lot size on each account
Balance and risk % are per account, so a single alert routed to three accounts resolves three different sizes. A challenge account and a funded account can take the same setup without the challenge account inheriting the funded account's exposure.
Nothing about the signal changes. The payload carries the stop distance; the account supplies everything else.
A worked example
An alert arrives for EURUSD with a stop 20 pips below entry. Two accounts are connected.
Account A has a balance of 10,000 and risk of 1%:
riskAmount = 10,000 × 1% = 100
oneLotLoss = OrderCalcProfit(...) = 200 (20 pips on 1.00 lot)
lots = 100 / 200 = 0.50Account B has a balance of 25,000 and risk of 0.5%:
riskAmount = 25,000 × 0.5% = 125
oneLotLoss = 200
lots = 125 / 200 = 0.625 → 0.62 after the broker's lot stepBoth accounts took the same trade. Neither risked the other's money.
Where the payload can override the account
A webhook payload can carry risk= to replace the account card's risk percentage for that one trade. It applies to that signal only and does not change the account card.
The manual trade form has no risk override field, so manual trades always use the account's configured risk.
Whatever the source, the EA caps the value at its MAX_RISK_PER_TRADE input, which ships at 5%. A payload asking for more is clamped and the cap is written to the Experts log.
How the result is adjusted before the order is sent
The raw number is rarely a valid order size, so the EA applies the broker's own constraints in order:
- Rounded to the symbol's lot step. A result of 0.625 becomes 0.62 or 0.63 depending on the step.
- Clamped to the symbol's minimum and maximum volume. A calculation below the minimum is raised to it, which means very small balances can risk more than the configured percentage. There is no way around this: the broker will not accept a smaller order.
- Reduced if margin is tight. If the order would consume more than 80% of free margin, the size is cut to fit that ceiling and rounded down rather than to nearest.
When the size comes back at the minimum
The EA returns the symbol's minimum volume when it cannot compute a meaningful size. That happens when the entry or stop price is zero or missing, when the stop distance works out to zero, or when the broker reports no usable tick value for the symbol.
If a position is much smaller than expected, that fallback is the first thing to check. Enable logging on the EA and the Experts tab prints the target risk amount, the one-lot loss it obtained, and the final size, which is enough to tell a rounding effect from a failed calculation.
If OrderCalcProfit itself fails, the EA falls back to computing the loss from tick size and tick value directly. The result is the same for most symbols and only diverges on instruments where the broker's own profit calculation accounts for something the tick values do not.