Rounding prices to tick size before an order goes out
Posted: Wed Oct 21, 2026 1:20 pm
Rounding prices to tick size before an order goes out
Invalid price errors on order sends often come down to one thing. The price the EA calculated has more decimal places than the symbol allows, or it isn't a multiple of the symbol's tick size.
On most FX pairs the tick size equals the point, so rounding to the number of digits is enough. On some symbols, especially indices, metals and a few CFDs, the tick size is larger than the point. A symbol might show two decimals but only allow prices in steps of 0.25 or 0.5. Rounding to two decimals isn't enough there.
The safe approach is to read the tick size from the symbol properties at runtime and round every price to a multiple of it before sending. In MQL5 that's SYMBOL_TRADE_TICK_SIZE. Divide the price by the tick size, round to the nearest whole number, multiply back. Then normalise to the symbol's digits to clean up floating point leftovers.
Do this for entry prices on pending orders, stop losses and take profits. Market orders usually take the current price, but the stop and target attached to them still need rounding.
It's a small function, but it removes a whole class of rejected orders, and it means the same EA can run on a symbol with an unusual tick size without changes.
It's the kind of thing that only shows up when you move an EA to a new symbol, which is exactly when you're least likely to be watching closely. Running the EA on a demo of any new symbol for a day and checking the journal for rejections is a cheap way to catch it before it matters.
A quick way to see which symbols on your account need this is to print the tick size and point for every symbol in the Market Watch once, and look for any where the two differ.
Invalid price errors on order sends often come down to one thing. The price the EA calculated has more decimal places than the symbol allows, or it isn't a multiple of the symbol's tick size.
On most FX pairs the tick size equals the point, so rounding to the number of digits is enough. On some symbols, especially indices, metals and a few CFDs, the tick size is larger than the point. A symbol might show two decimals but only allow prices in steps of 0.25 or 0.5. Rounding to two decimals isn't enough there.
The safe approach is to read the tick size from the symbol properties at runtime and round every price to a multiple of it before sending. In MQL5 that's SYMBOL_TRADE_TICK_SIZE. Divide the price by the tick size, round to the nearest whole number, multiply back. Then normalise to the symbol's digits to clean up floating point leftovers.
Do this for entry prices on pending orders, stop losses and take profits. Market orders usually take the current price, but the stop and target attached to them still need rounding.
It's a small function, but it removes a whole class of rejected orders, and it means the same EA can run on a symbol with an unusual tick size without changes.
It's the kind of thing that only shows up when you move an EA to a new symbol, which is exactly when you're least likely to be watching closely. Running the EA on a demo of any new symbol for a day and checking the journal for rejections is a cheap way to catch it before it matters.
A quick way to see which symbols on your account need this is to print the tick size and point for every symbol in the Market Watch once, and look for any where the two differ.