Trade server return code
10015 TRADE_ RETCODE_ INVALID_ PRICE
Invalid price: the order price is not valid for the symbol
What it means
The price in the request is not one the server accepts for this order. A price has to be a multiple of the symbol's tick size (SYMBOL_TRADE_TICK_SIZE, "Minimal price change"), have the symbol's number of digits, and fit the order type.
Common causes
- A pending order price computed with arithmetic (an ATR multiple, a midpoint) and not rounded to the tick size.
- Index and metal CFDs whose tick size is larger than one point, for example 0.25 or 0.5 while the price shows two digits.
- A pending order on the wrong side of the market: a buy limit above the Ask or a buy stop below it.
- A market order on Instant execution sent with the wrong side of the quote (the Bid for a buy).
A real scenario
An EA places breakout buy stops on an index CFD a fixed fraction of the daily range above the high. The computed price, for example 18234.37, has two decimals like the quote, but the symbol only trades in steps of 0.25, so every order is refused with 10015. Rounding to the tick size gave 18234.25 and the orders were accepted.
How to fix it
- Round every computed price to the tick size, then normalise it to
SYMBOL_DIGITS. - Check the side of a pending order against the current Bid and Ask before sending it.
- Use the Ask for buys and the Bid for sells, read just before the request.
Fixed MQL5 code
#include <Trade/Trade.mqh>
CTrade trade;
double RoundToTick(const string symbol, const double price)
{
double tick = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE);
int digits = (int)SymbolInfoInteger(symbol, SYMBOL_DIGITS);
if(tick <= 0.0)
return NormalizeDouble(price, digits);
return NormalizeDouble(MathRound(price / tick) * tick, digits);
}
bool PlaceBuyLimit(const double lots, double price)
{
MqlTick t;
if(!SymbolInfoTick(_Symbol, t))
return false;
price = RoundToTick(_Symbol, price);
if(price >= t.ask)
{
Print("A buy limit must be below the Ask: use a buy stop for a price above it");
return false;
}
return trade.BuyLimit(lots, price, _Symbol);
}
A focused example for MetaTrader 5: adapt names, magic number and limits to your EA, and test it on a demo account first.
Related codes
- 10016Invalid StopsTRADE_RETCODE_INVALID_STOPSInvalid stops: SL or TP too close to the price or on the wrong side
- 10004RequoteTRADE_RETCODE_REQUOTERequote: the price moved before the order was filled
EA Doctor rules that catch it
- 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.
- MediumHard-coded point size or digitsThe 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.
Sources
Get your EA fixed
Still failing with 10015? Send us the EA and the journal lines: we find the cause in the code and fix it. Or check it yourself first with the EA Doctor.