Download MetaTrader 5

Error 4756 (ERR_TRADE_SEND_FAILED) using "Instant Execution" requests

To add comments, please log in or register
Deposit to your account using bank cards via Gate2Shop
Micha_dan
13
Micha_dan 2015.05.03 14:54 

I'm trying to buy and sell at market value with the "Instant Execution" method (see here https://www.mql5.com/en/docs/constants/structures/mqltraderequest).

I have filled the required properties of the request, but OrderCheck returns error code 4756, from the docs: 

ERR_TRADE_SEND_FAILED

4756

Trade request sending failed

 

I googled the error but couldn't find anything. I am using a demo acount and the strategy tester so there is no broker involved.

 

Note 1: The first buy and the first sell work. 

Note 2: If I remove the OrderCheck() calls, I all buy orders work successfully but sells still fail, it' doesn't make any sense.

Below the code : 


void OnTimer()

{

MqlTick curTick;

if(!SymbolInfoTick(Symbol(), curTick)) return;

if(...){ //true when I need to buy, false when I need to sell

Request request;

         request.action = TRADE_ACTION_DEAL;

         request.symbol = Symbol();

         request.volume = 1;

         request.price = curTick.ask;

         request.sl = 0;

         request.tp = 0;

         request.deviation = 0;

         request.type = ORDER_TYPE_BUY;

         request.type_filling = ORDER_FILLING_FOK;

 

   MqlTradeCheckResult checkResult;

         bool success = OrderCheck(request, checkResult);

         if(!success) Print("OrderCheck failed error: ", GetLastError());


         MqlTradeResult tradeResult;

         bool successTrade = OrderSend(request, tradeResult);

         if(!successTrade) Print("OrderSend (buy) failed error: ", GetLastError());


}else{

MqlTradeRequest request;

         request.action = TRADE_ACTION_DEAL;

         request.symbol = Symbol();

         request.volume = 1;

         request.price = curTick.bid;

         request.sl = 0;

         request.tp = 0;

         request.deviation = 0;

         request.type = ORDER_TYPE_SELL;

         request.type_filling = ORDER_FILLING_FOK;

 MqlTradeCheckResult checkResult;

         bool success = OrderCheck(request, checkResult);

         if(!success)Print("OrderCheck failed error: ", GetLastError());


         MqlTradeResult tradeResult;

         bool successTrade = OrderSend(request, tradeResult);

         if(!successTrade)Print("OrderSend (sell) failed error: ", GetLastError()); 

}

 

I am properly checking that trading is allowed :

 

int OnInit()

  {

      Print("SYMBOL_TRADE_EXEMODE= ", SymbolInfoInteger(Symbol(), SYMBOL_TRADE_EXEMODE));

      Check_SYMBOL_ORDER_MODE(Symbol());

      

   if(!TerminalInfoInteger(TERMINAL_TRADE_ALLOWED)) 

      Alert("Automated trading is not allowed in the terminal settings!");

   

   if(!MQLInfoInteger(MQL_TRADE_ALLOWED))

      Alert("Automated trading is forbidden in the program settings for ",__FILE__);

         

   if(!AccountInfoInteger(ACCOUNT_TRADE_EXPERT))

      Alert("Automated trading is forbidden for the account ",AccountInfoInteger(ACCOUNT_LOGIN)," at the trade server side");     

   

   if(!AccountInfoInteger(ACCOUNT_TRADE_ALLOWED))

      Comment("Trading is forbidden for the account ",AccountInfoInteger(ACCOUNT_LOGIN),

            ".\n Perhaps an investor password has been used to connect to the trading account.",

            "\n Check the terminal journal for the following entry:",

            "\n\'",AccountInfoInteger(ACCOUNT_LOGIN),"\': trading has been disabled - investor mode.");

                  

   EventSetTimer(10);//10sec

   return(INIT_SUCCEEDED);

  }

 

Micha_dan
13
Micha_dan 2015.05.06 22:00  
Everything works fine now without changing anything, I guess the demo servers had some issues.
yhjcjmn1234
7
yhjcjmn1234 2017.03.19 03:22  

request.type_filling = ORDER_FILLING_FOK

have a try ,change the ORDER_FILLING_FOK.because the symbol it's own ORDER_FILLING mode.

i'm not sure it's changeable.

i'm get a prolem when a use the CTrade  PositionOpen.some symbol can but some not with no error.now ,it's ok after the FILLING Mode changed.

To add comments, please log in or register