What is the problem of this code? - page 2

 

I tested the last code on real account and got the same errors:


There is a problem here
There is a problem hereee
The Buy order request could not be completed -error:4756

I also checked the journal tab and found the log:


2019.01.13 12:07:23.775 Trades  '323232': failed exchange buy 1.0K وبملت at 2623 sl: 2373 tp: 2873 [Unsupported filling mode]
 
mrequest.type_filling = ORDER_FILLING_IOC; //ORDER_FILLING_FOK;                             // Order execution type

Why is it like that ?

#define EXPERT_MAGIC 123456   // MagicNumber of the expert
//+------------------------------------------------------------------+
//| Opening Buy position                                             |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- declare and initialize the trade request and result of trade request
   MqlTradeRequest request={0};
   MqlTradeResult  result={0};
//--- parameters of request
   request.action   =TRADE_ACTION_DEAL;                     // type of trade operation
   request.symbol   =Symbol();                              // symbol
   request.volume   =0.1;                                   // volume of 0.1 lot
   request.type     =ORDER_TYPE_BUY;                        // order type
   request.price    =SymbolInfoDouble(Symbol(),SYMBOL_ASK); // price for opening
   request.deviation=5;                                     // allowed deviation from the price
   request.magic    =EXPERT_MAGIC;                          // MagicNumber of the order
//--- send the request
   if(!OrderSend(request,result))
      PrintFormat("OrderSend error %d",GetLastError());     // if unable to send the request, output the error code
//--- information about the operation
   PrintFormat("retcode=%u  deal=%I64u  order=%I64u",result.retcode,result.deal,result.order);
  }
//+------------------------------------------------------------------+

 
Example of the TRADE_ACTION_DEAL trade operation for opening a Sell position:

#define EXPERT_MAGIC 123456   // MagicNumber of the expert
//+------------------------------------------------------------------+
//| Opening Sell position                                            |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- declare and initialize the trade request and result of trade request
   MqlTradeRequest request={0};
   MqlTradeResult  result={0};
//--- parameters of request
   request.action   =TRADE_ACTION_DEAL;                     // type of trade operation
   request.symbol   =Symbol();                              // symbol
   request.volume   =0.2;                                   // volume of 0.2 lot
   request.type     =ORDER_TYPE_SELL;                       // order type
   request.price    =SymbolInfoDouble(Symbol(),SYMBOL_BID); // price for opening
   request.deviation=5;                                     // allowed deviation from the price
   request.magic    =EXPERT_MAGIC;                          // MagicNumber of the order
//--- send the request
   if(!OrderSend(request,result))
      PrintFormat("OrderSend error %d",GetLastError());     // if unable to send the request, output the error code
//--- information about the operation
   PrintFormat("retcode=%u  deal=%I64u  order=%I64u",result.retcode,result.deal,result.order);
  }
//+------------------------------------------------------------------+

Try like these.

 
Marco vd Heijden:

Why is it like that ?

Try like these.

What is the difference between OnTick() and OnStart() ?

 
Marco vd Heijden:

Why is it like that ?

Try like these.

I tried your code but I get "4753" error!


I also tried to comment the filling_type code or test all the filling types methods. The only change happened when I used this code:

 mrequest.type_filling =  ORDER_FILLING_RETURN; //ORDER_FILLING_FOK; // ORDER_FILLING_IOC;  

And got these new errors in journal tab:

2019.01.14 12:22:26.819 Trades '89412': accepted exchange buy 1.0K خساپا at market sl: 1297 tp: 1433

2019.01.14 12:22:26.828 Trades '89412': rejected exchange buy 1.0K خساپا at market sl: 1297 tp: 1433


 
Please study the order filling types so you know which one you want to use.
 
check the return code of MqlTradeResult
 
caren1985:
check the return code of MqlTradeResult

I checked for retcode:


2019.01.14 12:22:26.828 RealExpert (خساپا,D1)   retcode=10006  deal=0  order=9577666
 
I read this topic https://www.mql5.com/en/forum/60690, and maybe I must add a comment to my order request too. But I don't know where can I find the keyword that I must to use?
Order gets rejected when used in real trade
Order gets rejected when used in real trade
  • 2015.06.26
  • www.mql5.com
The code works in strategy tester, but when using in real trade, I get Error 4756 (Trade request sending failed) and retcode 10006 (Request rejecte...
 
rezaeee :

I checked for retcode:


The broker does not support expert
Reason: