Rounding a price to the tick size (not NormalizeDouble)
On gold, indices or futures, the quote step (SYMBOL_TRADE_TICK_SIZE) can be 0.25 or 0.05: NormalizeDouble isn't enough, you have to quantize the price to a multiple of the tick.
Prerequisites
MetaTrader 5, MQL5
MQL5
double RoundToTick(string symbol, double price)
{
double tickSize = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE);
int digits = (int)SymbolInfoInteger(symbol, SYMBOL_DIGITS);
if(tickSize <= 0.0)
return NormalizeDouble(price, digits); // repli
// Quantifier au multiple de tick le plus proche, PUIS normaliser
double rounded = MathRound(price / tickSize) * tickSize;
return NormalizeDouble(rounded, digits);
}
// Exemple : sur un future coté au quart de point
// RoundToTick(sym, 15123.37) -> 15123.25 (et non 15123.37)
double entry = RoundToTick(_Symbol, levelFromIndicator);Result
2026.06.10 10:15:00.310 TickRound (US500,M5) tick_size=0.25 : niveau indicateur 5123.37 -> 5123.25 2026.06.10 10:15:00.345 TickRound (US500,M5) BuyLimit 5123.25 accepté (retcode 10009) 2026.06.10 10:15:00.412 TickRound (XAUUSD,M5) tick_size=0.05 : 2380.43 -> 2380.45 2026.06.10 10:15:00.413 TickRound (XAUUSD,M5) NormalizeDouble seul aurait laissé 2380.43 -> « invalid price »
Tick SizeNormalizeDoubleInvalid PricePiège