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
- Replace the literal with
_Point(one point) or a pip size derived from_Digits. - Normalise prices with
_Digitsinstead of a fixed number.
Code that fires it
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
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.
Related MQL5 errors
More rules on prices and stops
- HighStops set without the stops level checkThe EA sets a stop loss or take profit without reading the broker's minimum stop distance, which is refused with 10016 when it is too close.
- MediumChanges near the price without the freeze level checkThe EA modifies stops or deletes orders without reading the freeze level, inside which the broker refuses changes with 10029.
- MediumPrices not rounded to the symbol's digitsA price, stop loss or take profit is computed with _Point arithmetic and sent without NormalizeDouble() or rounding to the tick size.
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.