MQL4 broker constraints

MQL4 price normalization beyond NormalizeDouble

Normalize a price to the target symbol digits, but also validate its tick size, stop level, freeze level, lot step, and current Bid or Ask. NormalizeDouble controls decimal digits; it does not make an order price valid for a broker.

Open the Coding Agent, then choose MQL4 from the language menu.

NormalizePriceExample.mq4.mq4
#property strict
#property script_show_inputs

input int DistancePoints = 100;

void OnStart()
  {
   string symbol = Symbol();
   int digits = (int)MarketInfo(symbol, MODE_DIGITS);
   double point = MarketInfo(symbol, MODE_POINT);
   int stop_level = (int)MarketInfo(symbol, MODE_STOPLEVEL);

   RefreshRates();
   double raw_price = Ask + DistancePoints * point;
   double normalized_price = NormalizeDouble(raw_price, digits);

   PrintFormat("raw=%s normalized=%s point=%s stopLevel=%d",
               DoubleToString(raw_price, digits + 2),
               DoubleToString(normalized_price, digits),
               DoubleToString(point, digits),
               stop_level);
  }
  • Digits controls display precision
  • Point is the minimum quoted unit
  • Broker distance rules still apply
  • Volume has a separate lot step

Digits, point, tick size, and pip are not interchangeable

Digits is the number of decimals in a quote. Point is the point size reported for the symbol. A pip is a market convention rather than a universal MQL4 unit, and many five-digit forex quotes contain ten points per conventional pip.

Order slippage and MODE_STOPLEVEL values are expressed in points in the classic trade API. Convert user-facing pip settings explicitly instead of assuming one point equals one pip on every symbol.

PropertyMeaningUse
MODE_DIGITSQuote decimal countPrice formatting and normalization
MODE_POINTPoint sizeDistance conversion
MODE_STOPLEVELMinimum stop distance in pointsPreflight validation
MODE_LOTSTEPVolume incrementLot normalization

NormalizeDouble is not a broker validator

NormalizeDouble rounds a floating-point value to a requested number of digits. The resulting binary double can still print with representation artifacts, and the requested order can still violate stop, freeze, tick, or volume constraints.

Use symbol-specific properties for the symbol being traded. Global Bid, Ask, Digits, and Point refer to the current chart symbol, which is unsafe when an EA trades another symbol.

  • Read properties for the actual order symbol
  • Convert all user distances into points explicitly
  • Normalize volume by MODE_LOTSTEP, not price digits
  • Handle error 130 even when MODE_STOPLEVEL reports zero

Price validity is time-sensitive

A normalized price can become stale between calculation and OrderSend or OrderClose. Refresh the relevant quote and apply a bounded policy for requotes and invalid-price responses.

Compile success proves only that function calls and types are accepted. Demo testing on each target symbol is required to expose broker-specific contract settings.

Review the complete example

The script reads digits and point size from the chart symbol, expresses distance in points, and normalizes the result for display. It does not send an order or claim that the result satisfies every broker rule.

The example does not trade. Contract specifications can differ by broker and symbol, so validate prices and volumes again at the operation boundary.

NormalizePriceExample.mq4.mq4
#property strict
#property script_show_inputs

input int DistancePoints = 100;

void OnStart()
  {
   string symbol = Symbol();
   int digits = (int)MarketInfo(symbol, MODE_DIGITS);
   double point = MarketInfo(symbol, MODE_POINT);
   int stop_level = (int)MarketInfo(symbol, MODE_STOPLEVEL);

   RefreshRates();
   double raw_price = Ask + DistancePoints * point;
   double normalized_price = NormalizeDouble(raw_price, digits);

   PrintFormat("raw=%s normalized=%s point=%s stopLevel=%d",
               DoubleToString(raw_price, digits + 2),
               DoubleToString(normalized_price, digits),
               DoubleToString(point, digits),
               stop_level);
  }
Where Pineify fits

Move from the rule to editable MQL4 source

Pineify can generate or revise one self-contained .mq4 file with MQL4-specific reference context. Its independent static checker returns MetaEditor diagnostics so you can repair source issues before testing in your own MT4 environment.

Open MQL4 Coding Agent

Static diagnostics do not prove runtime behavior, backtest results, broker compatibility, or live-trading safety.

Pineify MQL4 Coding Agent with MQL4 selected and an editable MetaTrader 4 code artifact

A practical workflow

  1. 1

    Read symbol properties

    Get digits, point, stop level, freeze level, and lot step for the traded symbol.

  2. 2

    Convert units

    Translate user distances into points and volume into lot-step increments.

  3. 3

    Normalize the value

    Round prices to symbol precision and volumes to supported steps.

  4. 4

    Validate at send time

    Refresh quotes, check broker distances, and handle the returned trade error.

Frequently asked questions

What does NormalizeDouble do in MQL4?

It rounds a double to the requested number of decimal digits. It does not validate a price against broker rules.

What is Point in MQL4?

Point is the point size of the current symbol, or of a named symbol when read through MarketInfo.

Are pips and points the same?

Not always. On many five-digit forex symbols, one conventional pip is ten points.

Why do I still get invalid stops after normalization?

The distance may violate MODE_STOPLEVEL or a dynamic server rule, or use the wrong side of the quote. Normalized decimals alone do not guarantee valid stops.

Should lot size use NormalizeDouble with Digits?

No. Volume should follow minimum, maximum, and MODE_LOTSTEP constraints, which are separate from price digits.

Last verified against the linked official references on . Compile and test the final source in the MetaTrader 4 build, broker, symbol, and account environment you plan to use.

Continue with one reviewable MQL4 file

Define the requirement, inspect the generated source, repair diagnostics, and test the behavior in your own MT4 environment.

Open Coding Agent