Download MetaTrader 5

Trade Request Returns Invalid Request

To add comments, please log in or register
choongay
10
choongay 2016.05.02 12:03 

Hi, can someone correct me what is the mistake below?

I got error code 10013 which mean invalid request.

FYI, I am using MetaQuotes-Demo account.


Thank you very much.


My code

bool Trade_Buy()
 {
   ZeroMemory(my_request);
   ZeroMemory(my_result);
   ZeroMemory(my_check_result);
  
   my_request.action       = TRADE_ACTION_PENDING;         // Setting a pending order
   my_request.magic        = magic_number;                         // ORDER_MAGIC
   my_request.symbol       = _Symbol;                                 // Symbol
   my_request.volume       = 1;                                           // Volume in 0.1 lots
   my_request.price        = 0.79;                                         // Price, reaching which the order must be executed
   my_request.stoplimit    = 0.89;                                        // Pending order is not placed if reach stop limit
   my_request.sl           = 0.86;                                           // Stop Loss
   my_request.tp           = 0.9;                                            // Take Profit
   my_request.type         = ORDER_TYPE_BUY;                    // order type
   my_request.type_filling = ORDER_FILLING_FOK;
   my_request.type_time    = ORDER_TIME_DAY;

   if(OrderCheck(my_request, my_check_result) == false)
   {
      Alert("ORDER_TYPE_BUY check failed\r\n");
      return false; 
   }
  if(OrderSend(my_request, my_result) == false)
   {
      Alert("ORDER_TYPE_BUY failed\r\n");
      return false;
   } // if the order is successfully accepted by the trade server, the OrderSend() function returns true.

   return true;
}

Watch

MqlTradeRequest{  action:TRADE_ACTION_PENDING magic:55555 order:0 symbol:"NZDCAD" volume:1 price:0.79 stoplimit:0.89 sl:0.86 tp:0.9 deviation:0 type:ORDER_TYPE_BUY type_filling:ORDER_FILLING_FOK type_time:ORDER_TIME_DAY expiration:D'1970.01.01 00:00:00… }


MqlTradeResult{  retcode:10013 deal:0 order:0 volume:0 price:0 bid:0 ask:0 comment:"Invalid request" request_id:2 reserved:[128] }

Alain Verleyen
Moderator
31085
Alain Verleyen 2016.05.02 14:52  
You are using TRADE_ACTION_PENDING and ORDER_TYPE_BUY, a BUY is not a pending. Check the documentation please.
To add comments, please log in or register