Skip to content

EA Doctor rule · Prices and stops

Hard-coded point size or digits

The code writes 0.0001 for a pip or rounds prices to a fixed number of digits, which is wrong on JPY pairs, gold, indices and crypto.

Why it matters

0.0001 for a pip or NormalizeDouble(price, 5) ties the EA to 5-digit forex quotes. On a 3-digit JPY pair, gold, an index or a crypto symbol the same number is 100 or 1,000 times off: stops land in the wrong place or are refused (10016), and prices are rounded to the wrong digits (10015).

_Point and _Digits are the chart symbol's own values; SymbolInfoDouble(symbol, SYMBOL_POINT) and SymbolInfoInteger(symbol, SYMBOL_DIGITS) are those of any other symbol.

When the rule fires

A literal 0.0001 or 0.00001 is used in arithmetic, or NormalizeDouble() is called with a fixed 3, 4 or 5 digits on a value whose name does not say lot or volume.

When it stays quiet

Values written with _Point, _Digits, Point(), Digits() or SymbolInfo…(); default values of inputs are not flagged.

How to fix it

  1. Replace the literal with _Point (one point) or a pip size derived from _Digits.
  2. Normalise prices with _Digits instead of a fixed number.

Code that fires it

MQL5 · fires this rule
void OpenBuy()
  {
   const double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   const double sl  = NormalizeDouble(ask - 20 * 0.0001, 5);
   trade.SetExpertMagicNumber(InpMagic);
   if(!trade.Buy(InpLots, _Symbol, ask, sl, 0.0))
      Print("Buy failed: ", trade.ResultRetcodeDescription());
  }

Fixed code

MQL5 · fixed
double PipSize()
  {
   // a pip is 10 points on 3- and 5-digit quotes, 1 point otherwise
   return((_Digits == 3 || _Digits == 5) ? 10 * _Point : _Point);
  }

void OpenBuy()
  {
   const double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   const double sl  = NormalizeDouble(ask - 20 * PipSize(), _Digits);
   trade.SetExpertMagicNumber(InpMagic);
   if(!trade.Buy(InpLots, _Symbol, ask, sl, 0.0))
      Print("Buy failed: ", trade.ResultRetcodeDescription());
  }

The fixed code shows this rule’s fix and compiles in MetaEditor for MetaTrader 5 (with CTrade trade, InpLots and InpMagic declared, as in a typical EA). Other rules may still apply to it as a fragment: check your whole EA.

More rules on prices and stops

Sources

Get your EA fixed

Check a whole EA for this and 29 other mistakes with EA Doctor, free and in your browser. Or send it to us: we confirm the price in writing, then fix it.