Position not opened despite trade.ResultRetcodeDescription() returncode = 10008

 

Hi,

I'm currently testing an EA on multiple currencies. For the most part, it works ok, but has big troubles with requotes. I've intentionally set deviation to 10000 points just to see if this will help, which isn't the case unfortunately. 

Here's the code I'm using (PositionerTrade = 1) is preventing multiple position openings. 

   if(Signal == "1.0")
     {
      if(!trade.Buy(PositionSize, _Symbol, 0.0, Ask-ATR_coeff*myATRValue, Ask + ATR_coeff*myATRValue, NULL))
        {
         //--- failure message
         Print("Buy() method failed. Return code=",trade.ResultRetcode(),
               ". Code description: ",trade.ResultRetcodeDescription());
        }
      else
        {
         Print("Buy() method executed successfully. Return code=",trade.ResultRetcode(),
               " (",trade.ResultRetcodeDescription(),")");
         PositionerTrade = 1;
         break;
        }
     }
   if(Signal == "-1.0")
     {
      if(!trade.Sell(PositionSize, _Symbol, 0.0, Bid+ATR_coeff*myATRValue, Bid - ATR_coeff*myATRValue, NULL))
        {
         //--- failure message
         Print("Buy() method failed. Return code=",trade.ResultRetcode(),
               ". Code description: ",trade.ResultRetcodeDescription());
        }
      else
        {
         Print("Buy() method executed successfully. Return code=",trade.ResultRetcode(),
               " (",trade.ResultRetcodeDescription(),")");
         PositionerTrade = 1;
         break;
        }
     }

For example, the last 3 orders are below. The first 2 were executed succefully, while the 3rd one wasn't.

EA prints (result of trade.ResultRetcode() and trade.ResultRetcodeDescription()) 

KL 0 10:59:00.185 PythonTraderNZDCHF4H (NZDCHF,H4)         Buy() method executed successfully. Return code=10008 (placed)

RJ 0 10:59:00.221 PythonTraderAUDNZD4H (AUDNZD,H4) Buy() method executed successfully. Return code=10008 (placed)

PROBLEM - order not executed:

JH 0 14:59:00.391 PythonTraderNZDCHF4H (NZDCHF,H4)         Buy() method executed successfully. Return code=10008 (placed)


MT5 Journaly prints

KK 0 10:59:00.185 Trades '35925': instant sell 0.22 NZDCHF at 0.66375 sl: 0.67142 tp: 0.65608 (deviation: 10000)

HG 0 10:59:00.221 Trades '35925': instant buy 0.42 AUDNZD at 1.07541 sl: 1.06937 tp: 1.08145 (deviation: 10000)

QM 0 10:59:00.401 Trades '35925': accepted instant sell 0.22 NZDCHF at 0.66375 sl: 0.67142 tp: 0.65608 (deviation: 10000)

KN 0 10:59:00.401 Trades '35925': deal #3180674 sell 0.22 NZDCHF at 0.66376 done (based on order #4456322)

DQ 0 10:59:00.421 Trades '35925': order #4456322 sell 0.22 / 0.22 NZDCHF at 0.66376 done in 237.031 ms

GM 0 10:59:00.436 Trades '35925': accepted instant buy 0.42 AUDNZD at 1.07541 sl: 1.06937 tp: 1.08145 (deviation: 10000)

JO 0 10:59:00.436 Trades '35925': deal #3180675 buy 0.42 AUDNZD at 1.07541 done (based on order #4456323)

FE 0 10:59:00.438 Trades '35925': order #4456323 buy 0.42 / 0.42 AUDNZD at 1.07541 done in 216.436 ms

PROBLEM - order not executed:

MJ 0 14:59:00.391 Trades '35925': instant sell 0.21 NZDCHF at 0.66655 sl: 0.67441 tp: 0.65869 (deviation: 10000)

ME 0 14:59:00.610 Trades '35925': requote 0.66659 / 0.66678 (instant sell 0.21 NZDCHF at 0.66655 sl: 0.67441 tp: 0.65869 (deviation: 10000))


I'd like to have a loop created that keeps opening orders until 1 is succesfull. However I'm unable to do this with the return code 10008 as it's obviously coming back for successfull and unsuccessfull orders. I understand there's also a 10009 code, but that doesn't seem to be coming back as feedback when checking. Would really appreciate any suggestions.


Thanks,


emperor14

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Deal Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Deal Properties
  • www.mql5.com
Deal Properties - Trade Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Please insert the code correctly - using the button Code
 

Apologies, I'm new to forum posting, thanks for the heads up on code formatting. I've edited my question now as suggested.

Best,

emperor14

 

Hi,

can anyone help with this?

Regards,

emperor14

 

CTrade::Buy

Note

Successful completion of the Buy(...) method does not always mean successful execution of the trade operation. It is necessary to check the result of trade request (trade server return code) using ResultRetcode() and value returned by ResultDeal().

Documentation on MQL5: Standard Library / Trade Classes / CTrade / Buy
Documentation on MQL5: Standard Library / Trade Classes / CTrade / Buy
  • www.mql5.com
Buy(double,const string,double,double,double,const string) - CTrade - Trade Classes - Standard Library - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Thanks so much for your reply Vladimir, however this unfortunately doesn't help this issue. I am already checking both the ResultRetcode() and ResultDeal(), and they both return 10008 and 0 for ResultDeal() in case when the trade is sucesfully opened, and in case when not. So this one's not helping to differentiate. Any other ideas?

Best,


emperor14