I stumbled upon an issue during the development of an Expert Advisor and I was wondering if anyone had any idea that might help.
I get an “Invalid Price” error in backtest when the Expert Advisor tries to close a position on XAUUSD on a specific broker.
The error messages my Expert Advisor prints:
2018.05.16 18:05:40 failed market buy 0.15 XAUUSD, close #2 sell 0.15 XAUUSD 1321.220 [Invalid price] 2018.05.16 18:05:40 CTrade::OrderSend: market buy 0.15 XAUUSD [invalid price] 2018.05.16 18:05:40 *** FAILED Closing Position. Return code=10015. Code description: invalid price__ Invalid price
When I run the backtest with “Open prices only” the Expert Advisor opens a position at the beginning and never closes it until the end, while at the same time printing a lot of these error messages.
When I run the backtest with “OHLC Minute” or “Tick based on every tick” I still get a lot of these error messages but now the EA does manage to open and close several positions during the backtest period.
I use the
bool CTrade::PositionClose(const ulong ticket,const ulong deviation)
method to close the position. I have tried both with unspecified deviation parameter and a specified deviation of big value and the result is exactly the same.
I also tested it on MT5 Version:5.00 build 1861 and on MT5 Version:5.00 build 1755 , again with the same results.
I have also read everything on the forum about this error and checked that the execution mode for this symbol is “Market”, both in the Symbol Description and from inside the Expert Advisor(SYMBOL_ORDER_MARKET).
This only happens for this specific broker on XAUUSD and on backtest(I have not checked on live trading). All other brokers and symbols I have checked(of various execution modes) do not show the same problem.
Do you have any idea about what could be causing it?