Pending stop order, Invalid price, error 4756, retcode=10015, TRADE_RETCODE_INVALID_PRICE

 

I have a EA which will place buy stop or sell stop.

I find that there are some orders cannot be set due to error, TRADE_RETCODE_INVALID_PRICE.

Here is the log, from the same EA, one trade is success and the other is not:

GH      0       14:41:30.095    Core 1  2018.09.05 06:40:00   lastPrice: 1.964190, Point: 0.000010, Digits: 5
JG      2       14:41:30.095    Core 1  2018.09.05 06:40:00   failed buy stop 0.01 GBPNZD at 1.96439 sl: 1.95939 tp: 1.96489 [Invalid price]
PH      0       14:41:30.095    Core 1  2018.09.05 06:40:00   OrderSend error 4756
LP      0       14:41:30.095    Core 1  2018.09.05 06:40:00   retcode=10015  deal=0  order=0


HF      0       14:41:30.095    Core 1  2018.09.05 06:55:00   lastPrice: 1.963640, Point: 0.000010, Digits: 5
LH      0       14:41:30.095    Core 1  2018.09.05 06:55:08   buy stop 0.01 GBPNZD at 1.96476 sl: 1.95976 tp: 1.96526 (1.96368 / 1.96411 / 1.96368)
HF      0       14:41:30.095    Core 1  2018.09.05 06:55:08   retcode=10009  deal=0  order=89

lastPrice is come from this code:

double lastPrice = SymbolInfoDouble(Symbol(), SYMBOL_BID);

Is the current price and the stop price too closed?

 
fxea729:

Is the current price and the stop price too closed?

Probably, especially as you are getting the Bid price when BuyStop orders are at Ask

 

Thank you very much. You are right, the problem is related to ask price

PS      0       16:16:51.389    Core 1  2018.08.30 19:25:00   bitPrice: 1198.500000, askPrice: 1198.730000, Point: 0.001000, Digits: 3
RJ      0       16:16:51.389    Core 1  2018.08.30 19:25:04   sell stop 0.01 XAUUSD at 1197.840 sl: 1202.840 tp: 1197.340 (1198.500 / 1198.730 / 1198.500)
EI      0       16:16:51.389    Core 1  2018.08.30 19:25:04   retcode=10009  deal=0  order=782

HL      0       16:16:51.389    Core 1  2018.08.30 19:30:00   bitPrice: 1197.800000, askPrice: 1198.000000, Point: 0.001000, Digits: 3
CH      2       16:16:51.389    Core 1  2018.08.30 19:30:00   failed sell stop 0.01 XAUUSD at 1197.840 sl: 1202.840 tp: 1197.340 [Invalid price]
EK      0       16:16:51.389    Core 1  2018.08.30 19:30:00   OrderSend error 4756
IR      0       16:16:51.389    Core 1  2018.08.30 19:30:00   retcode=10015  deal=0  order=0
Reason: