Loading…

Price Normalization To Tick Size

NormalizeDouble(price, Digits) is the normalisation most EAs use, and it is not enough. Digits tells you how many decimal places the quote prints with, not the smallest increment the server will actually accept. A handful of index and metal instruments have a tick size that is not a clean power of ten, and some FX feeds quote fractional pips with a tick size larger than one point. A price rounded only by digit count can still land between two valid ticks and come back rejected or requoted. The arithmetic has the same trap as lot rounding: price divided by tick size does not land on a clean integer in binary floating point, so a floor or ceil applied without an epsilon can snap to the wrong tick. Every division in this header is nudged the same way LotNormalize handles volume divisions. Direction matters as much as the grid does. FloorPrice never rounds up - use it for a buy-side entry or a sell-side stop loss, where the SL sits below the market and rounding it toward price would tighten the stop beyond what was asked for. CeilPrice never rounds down - use it for a sell-side entry or a buy-side stop loss, the mirror case. RoundPrice takes the nearest tick and is right when the price has no directional bias, such as a level read off a chart for display. Also included: TickSizeOf and PriceDigitsOf read the server's real tick size and digit count with a point-size fallback for symbols the terminal has not fully synchronised; IsValidTickPrice for asserts and pre-trade checks; and TickConstraintsToString, a one-line summary for the journal at startup. The header is self-contained. No dependencies, no DLLs, no classes - plain functions callable from a script, an indicator or an EA. Notes and limitations - Broker symbol properties come from the server. On a symbol the terminal has never synchronised they can be zero; the point-size fallback keeps the code running but is still a guess. Call TickConstraintsToString at startup and read it. - The grid this header snaps to is anchored at zero (an integer count of ticks from zero), which is how brokers validate submitted prices. It is not anchored to the current Bid/Ask. - This header only makes a price valid on the tick grid. It does not check the broker's stop-level or freeze-level distance - that is a separate concern with a separate library. - No thread or state concerns: every function is pure and reads only broker properties.

Script · MT4 · v1.0 · Free

About Price Normalization To Tick Size

Price Normalization To Tick Size is a script for MetaTrader 4. It has 1 setting, such as Offset points. MQL source code included.

Files in the download: PriceNormalize.mqh, PriceNormalize.txt, PriceNormalizeDemo.mq4.

Settings

SettingDefaultWhat it does
Offset points7.0Points to offset from Bid for the worked example

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Grid · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria