invalid request - 10013

 

Hello to everyone!

Can anybody make it clear for me, why this amazingly sophisticated code does not work?

So, the deal is I am dropping that Script onto my Graph, and as a result I get a Messege:

Invalid request - 10013. To tell the truth this messege is not able to clarify anything for me.

If you, my dear friends, can open my eyes and may make this code work, please help me, I will really appreciate that.

 
//+------------------------------------------------------------------+
//|                                                          Nik.mq5 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

int STP = 40;
int TKP = STP*6;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
      if( PositionSelect( Symbol() ) == true ){
      Print( "You've got some position" );
      return;
    }
    Print( "You don't have positions" );
    MqlTradeRequest mrequest;
    MqlTradeResult  mresult;  
    MqlTick latest_price;
    MqlTradeCheckResult cres;
    
    
    if(!SymbolInfoTick(_Symbol,latest_price)){
      Alert("Ошибка получения последних котировок - ошибка:",GetLastError(),"!!");
      return;
    }
    mrequest.action = TRADE_ACTION_DEAL;                                 // немедленное исполнение
    mrequest.price  = NormalizeDouble( latest_price.bid, _Digits);          // последняя цена ask
    mrequest.sl     = NormalizeDouble( latest_price.ask - STP * _Point, _Digits); // Stop Loss
    mrequest.tp     = NormalizeDouble( latest_price.ask + TKP * _Point, _Digits); // Take Profit
    mrequest.symbol = _Symbol;                                         // символ
    mrequest.volume = 0.1;                                            // количество лотов для торговли
//  mrequest.magic  = 12345;                                        // Magic Number
    mrequest.type   = ORDER_TYPE_BUY;                                     // ордер на покупку
    mrequest.type_filling = ORDER_FILLING_IOC;                          // тип исполнения ордера - все или ничего
    mrequest.deviation=30;              
    if( OrderCheck( mrequest, cres ) ){
      Print( "Check is successful" );
      int res = OrderSend( mrequest, mresult);
    }
    else{
      Print( "Check is down - ", cres.retcode );    
      Print( "price - ", mrequest.price );    
      Print( "StopLoss - ", mrequest.sl);    
      Print( "TakeProfit - ", mrequest.tp );    
    }
    Print(__FUNCTION__,": ",mresult.comment," код ответа ",mresult.retcode); 

  }
//+------------------------------------------------------------------+

 


 

Change this line :

   MqlTradeRequest mrequest={0};
 
Alain Verleyen:

Change this line :

Thanks a lot. Checking is completed successfully. You are a magician)))
 
Thanks Alain, solved my problem too. 
 

Hello,

Here is my code:

//+------------------------------------------------------------------+
//|                                                           C1.mq5 |
//|                                  Copyright 2021, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
MqlTradeRequest Action={0};
MqlTradeResult result={0};

Action.action=TRADE_ACTION_DEAL;
Action.type=ORDER_TYPE_BUY;
Action.symbol=_Symbol;
Action.volume=.01;
Action.type_filling=ORDER_FILLING_IOC;//ORDER_FILLING_FOK;

   if(OrderSend(Action,result))
   {
      Print("OKK");
   }
   else
   {
      Print("Not OKK");
      Print(result.retcode);
      Print(result.comment);
   }

   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+


The above solution shows me this error : "cannot convert 0 to enum 'ENUM_TRADE_REQUEST_ACTIONS'    C1.mq5    15    25" for 

MqlTradeRequest Action={0}

Before that I got (removing ={0}) retcore=10013 error. what is my mistake?

 
MqlTradeRequest Action={};
 
Hello to everyone!

Can anybody make it clear for me, why this  code does not work?

So, the deal is I am dropping that Script onto my Graph, and as a result I get a Messege:

Invalid request - 10013. To tell the truth this messege is not able to clarify anything for me.

If you, my dear friends, can open my eyes and may make this code work, please help me, I will really appreciate that.
//+------------------------------------------------------------------+
//|                                                        trade.mq5 |
//|                                  Copyright 2021, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
 long ask_p=0;
 long ask_v = 0;
 long bid_v = 0;
 
 long ask_price=0;
 long ask_volume = 0;
 long bid_volume = 0;
  MqlTradeRequest request{};
   MqlTradeResult result{};

 
int OnInit()
  {
//---
MqlBookInfo BookInfo[];
MarketBookAdd(_Symbol);
MarketBookGet(_Symbol,BookInfo);

for(int j=0;j<1;j++)
{
for(int i=0;i<ArraySize(BookInfo)-1;i++)
  {
   if(BookInfo[i].type != BookInfo[i+1].type)
     {
      ask_p= BookInfo[i].price;
      ask_v = BookInfo[i].volume;
      bid_v = BookInfo[i+1].volume;
     
  }
  }
  }
      if(ask_volume<((ask_v)/14))
{
  
 printf("ok") ;
   request.action = TRADE_ACTION_PENDING;
   request.type = ORDER_TYPE_BUY;
   request.symbol = _Symbol;
   request.volume = 500;
   request.type_filling = ORDER_FILLING_RETURN;
   request.price = ask_price;
   request.tp = 1.042*(request.price);
   
   }
   OrderSend(request,result);
   
   if(result.retcode == 10008 || result.retcode == 10009)
   {
      Print("Trade placed");
   }
   else
   {
   printf("naok") ;
      Print("Trade not placed. Error code ",result.retcode);
   }
   
   Print("Return Code:",result.retcode,", Volume: ",result.volume,
         ", Price: ",result.price,", Bid: ",result.bid,", Ask: ",result.ask);
   

   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {
//---
   
  }

void OnTick()
  {
  MqlBookInfo BookInfo[];
MarketBookAdd(_Symbol);
MarketBookGet(_Symbol,BookInfo);
  for(int z=0;z<ArraySize(BookInfo)-1;z++)
  {
   if(BookInfo[z].type != BookInfo[z+1].type)
     {
      ask_price= BookInfo[z].price;
      ask_volume = BookInfo[z].volume;
      bid_volume = BookInfo[z+1].volume;
      
     }
     }
 
  
     }
//---

 


  
//+------------------------------------------------------------------+

 
Your TP is not set to normalized price.

Are you sure you want to open 500 lot? Is that intentional?

I would suggest initializing the structs empty.

  MqlTradeRequest request = {};
Reason: