Page 1 of 1
Lot size from risk percent using tick value in MQL5
Posted: Fri Oct 23, 2026 12:58 am
by Fairman
Lot size from risk percent using tick value in MQL5
Here's the sizing function I use, with the reasoning, because a lot of EAs get this wrong on crosses and metals.
The inputs are account equity, risk percent and stop distance in price. The key value is how much one lot gains or loses per point of movement. MQL5 gives it in two pieces:
SYMBOL_TRADE_TICK_VALUE is the value of one tick for one lot, in account currency.
SYMBOL_TRADE_TICK_SIZE is the size of one tick in price.
So the value of a one-unit price move per lot is tick value divided by tick size. Multiply by the stop distance in price and you get the loss per lot.
lossPerLot = stopDistance * tickValue / tickSize
lots = riskMoney / lossPerLot
Worked example: $10,000 equity, 0.5% risk, so $50. EURUSD, five digits, tick size 0.00001, tick value $1. Stop distance 0.00080, which is 8 pips. Loss per lot is 0.00080 times 1 divided by 0.00001, which is $80. Lots is 50 divided by 80, so 0.625.
The advantage is that this works for any symbol where the broker fills in tick value correctly, including crosses and gold, because the platform handles the currency conversion.
Two cautions. Tick value for crosses is calculated at current prices, so it shifts slightly through the day. And some brokers report a zero or stale tick value until the symbol has had a quote, so check it's above zero before using it.
Re: Lot size from risk percent using tick value in MQL5
Posted: Wed Oct 28, 2026 12:35 pm
by FXS HongKong Scalper
Using tick value divided by tick size is the right approach. One case to check is when SYMBOL_TRADE_TICK_VALUE changes during the day, which happens on crosses where the conversion rate moves. Reading the value at the time of sizing, not caching it from OnInit, avoids small errors. On some brokers, the tick value for profit and loss differs, available as SYMBOL_TRADE_TICK_VALUE_PROFIT and SYMBOL_TRADE_TICK_VALUE_LOSS. For a stop loss, the loss version is the correct one to use.
Re: Lot size from risk percent using tick value in MQL5
Posted: Fri Oct 30, 2026 11:01 am
by Fairman
The result needs rounding before you send it, and the direction matters. Always round down to the volume step, not to the nearest step, otherwise the risk can come out slightly above what you asked for. With a step of 0.01, 0.625 becomes 0.62. Then clamp between SYMBOL_VOLUME_MIN and SYMBOL_VOLUME_MAX. If the rounded value is below the minimum, it's safer to skip the trade than to send the minimum, since the minimum might be more risk than you wanted. The rounding step is where most sizing bugs hide. A size of zero should never reach OrderSend.
Re: Lot size from risk percent using tick value in MQL5
Posted: Fri Oct 30, 2026 12:47 pm
by Fairman
There's also SYMBOL_TRADE_TICK_VALUE_LOSS and SYMBOL_TRADE_TICK_VALUE_PROFIT in MQL5. On some brokers they differ slightly from the plain tick value because the conversion rate used for losses and profits is the bid or ask of the conversion pair. For sizing, using the loss version is the more careful choice. The difference is tiny on most pairs, but on exotic crosses it can be noticeable. In practice I compute both and use whichever is larger. On EURUSD they're nearly always identical, but on crosses like EURTRY or USDZAR they can differ enough to change the rounded size. It's a two line change and removes a rare source of overrisk.
Re: Lot size from risk percent using tick value in MQL5
Posted: Fri Oct 30, 2026 1:40 pm
by Fairman
If you want to double-check the function, OrderCalcProfit is useful. Pass it the symbol, volume, open price and the stop price, and it returns the profit or loss in account currency. Run it once with the computed lot size and compare the result to your risk money. If they don't match within a cent or two, something in your tick value or stop distance calculation is off. I use it as a sanity check inside the EA and log a warning when the gap is more than 1%. OrderCalcProfit takes the order type too, so pass the right direction.
Re: Lot size from risk percent using tick value in MQL5
Posted: Fri Oct 30, 2026 2:55 pm
by Fairman
On MT4 the equivalent is MarketInfo with MODE_TICKVALUE and MODE_TICKSIZE. The same formula works, though MT4 tick values on some brokers are less reliable for crosses, and a few report them in the wrong currency. If you run both platforms, test the function on a cross like EURGBP and on gold before trusting it live. A sizing bug is one of the few EA bugs that can quietly double your risk on every trade. Test with a stop distance in price, not pips, to rule out a units mix-up on JPY pairs.
Re: Lot size from risk percent using tick value in MQL5
Posted: Sat Oct 31, 2026 9:40 am
by Shadow Trader
Watch a thin pair for a few minutes and a pattern shows up. The bid moves up a tenth of a pip, down a tenth, up again, down again, and the ask follows. A fast tick counter goes wild, yet the real price hasn't gone anywhere.
Part of it is market makers refreshing quotes. Algorithms adjust their prices constantly in response to small changes in their own inventory or in correlated markets. Each adjustment becomes a tick, and the feed relays them all.
For indicators that count ticks, such as tick volume or tick-based bars, flickering inflates the numbers. A burst of activity may be a burst of quote revisions, not trades.
For a scalper, it also muddies the picture of what the market is doing right now. A momentum signal based on the last ten ticks can be driven entirely by flicker.
Some traders smooth the feed with a short median filter, or use time-based sampling every half second or so, which removes most of the noise. Others work from bar closes on a fast chart and ignore intra-bar movement.
The point is to know what the inputs actually measure. Tick count is not a clean proxy for anything unless the feed behind it is understood.
Does the tick feed in use seem clean, or does flicker show up on quiet pairs?