Error or NO Error

 

I have my reporting logs and I sometimes see something like

Sell  ticket = 2303414370 request.price = 1.07751 request.volume = 0.16 type = 1 iRes = 1 price = 1.07747 volume = 0.16 is TRUE MyComment = EURUSD_40117263422_S My_error: 4756 Trade request sending failed

The command 'Sell' appears to have worked and created a ticket number (as per other parameters) but I get the Error Message - 4756

I check the conditions

if ( MQLInfoInteger(MQL_TRADE_ALLOWED) != 1 )

Then used the command and check the result iRes

iRes = OrderSend (request,result);

Doesn't seem to create a problem but would like to understand why this happens and maybe change some detail if required

Any help very much appreciated

Documentation on MQL5: Python Integration / order_calc_margin
Documentation on MQL5: Python Integration / order_calc_margin
  • www.mql5.com
order_calc_margin - Python Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

it would be hard to debug it with the code that you provide.

Since sell position worked, try to check again between code for buy and sell.

 
Luandre Ezra #:

it would be hard to debug it with the code that you provide.

Since sell position worked, try to check again between code for buy and sell.

Here is my code for PLACING a Trade.  Report_StringError writes message to file and error message if error generated


bool Place_A_Trade(double TradingLots,double myprice,string OrderType)
{  ulong uTicket = 0;                        //>>>>>>>>>>>>>>>>>>>>>>>>>>>>//A buy is opened at ask and closed at bid.     //A sell is opened at bid and closed at ask.
   
   MqlTradeRequest      request;
   MqlTradeResult       result;
   MqlTradeCheckResult  Checkresult;
   ZeroMemory(request);
   ZeroMemory(result);
   ZeroMemory(Checkresult);
   double   REQvolume      = TradingLots;
   double   REQprice       = myprice;
   double   REQ_TP         = 0;
   Report_StringError("Both","888012 PAT"+strBorS+"TradingLots = "+DoubleToString(TradingLots,2)+" myprice = "+DoubleToString(myprice,_Digits)+" OrderType = "+OrderType+" MyComment = "+MyComment); 
//...............................Determine REQtype...................................................................................
   if ( OrderType == "Buy_Now"  ) request.type    = ORDER_TYPE_BUY;
   if ( OrderType == "Buy_Lim"  ) request.type    = ORDER_TYPE_BUY_LIMIT;
   if ( OrderType == "BuyStop"  ) request.type    = ORDER_TYPE_BUY_STOP;
   
   if ( OrderType == "Sell_Now" ) request.type    = ORDER_TYPE_SELL; 
   if ( OrderType == "Sell_Lim" ) request.type    = ORDER_TYPE_SELL_LIMIT;
   if ( OrderType == "SellStop" ) request.type    = ORDER_TYPE_SELL_STOP;
   
//...............................Determine REQaction...................................................................................
   if (  OrderType == "Buy_Now" || OrderType == "Sell_Now"                                                      ) request.action      = TRADE_ACTION_DEAL;
   if (  OrderType == "Buy_Lim" || OrderType == "BuyStop" || OrderType == "Sell_Lim" || OrderType == "SellStop" ) request.action      = TRADE_ACTION_PENDING;
//...............................Determine REQtypefilling................................................................................
   if ( (OrderType == "Buy_Now" || OrderType == "Sell_Now") && StringFind(RTF,"FOK",0) > 0                     ) request.type_filling = ORDER_FILLING_FOK;
   if ( (OrderType == "Buy_Now" || OrderType == "Sell_Now") && StringFind(RTF,"IOC",0) > 0                     ) request.type_filling = ORDER_FILLING_IOC;
   if (  OrderType == "Buy_Lim" || OrderType == "BuyStop" || OrderType == "Sell_Lim" || OrderType == "SellStop" ) request.type_filling = ORDER_FILLING_RETURN;
   if (  OrderType == "Buy_Lim" || OrderType == "BuyStop" || OrderType == "Sell_Lim" || OrderType == "SellStop" ) request.type_filling = ORDER_FILLING_RETURN;
   request.symbol       = MySymbol;
   request.volume       = REQvolume;
   request.price        = REQprice;
   request.tp           = 0;                 // REQ_TP;  
   
   request.sl           = 0;
   if (FIBO_Flag[Index] == "UP" || FIBO_Flag[Index] == "DN" ) request.sl = My_StopLoss;
   request.deviation    = 50;                
   request.magic        = MagicNumber;
   request.comment      = MyComment;
   //if ( OrderCheck(request,Checkresult) == true  ) 
   
   //int iTA = MQLInfoInteger(MQL5_TRADE_ALLOWED);
   int  iTA = MQLInfoInteger(MQL_TRADE_ALLOWED);
   string str_iTA = "FALSE";
   if ( MQLInfoInteger(MQL_TRADE_ALLOWED) == true) str_iTA = "TRUE";
   Report_StringError("Both","888013 PAT"+strBorS+"request.type = "+EnumToString(request.type)+"("+IntegerToString(request.type)+") request.action = "+EnumToString(request.action)+"("
      +IntegerToString(request.action)+") request.type_filling = "+EnumToString(request.type_filling)+"("+IntegerToString(request.type_filling)+"), iTA = "+IntegerToString(iTA)+" request.comment = "+request.comment);
   if ( MQLInfoInteger(MQL_TRADE_ALLOWED) != 1 )
   {  Report_StringError("Both","888015 PAT"+strBorS+"MQLInfoInteger(MQL_TRADE_ALLOWED) = "+IntegerToString(iTA)+" str_iTA = "+str_iTA+" ~ RETURN");
      return(false);
   }
   int iCount = 0;
   do
   {  iRes = OrderSend (request,result);
      iCount++;
      if ( OrderCheck(request,Checkresult) == false ) Report_StringError("Error"," 888020 PAT iCount = "+IntegerToString(iCount)+" OrderCheck Fails ~ Checkresult.retcode = "+IntegerToString(Checkresult.retcode));
      Sleep(50);
      if (iCount > 50 ) return(false);        
   }
   while (iRes == false);
   string str_res       = "Not Available";
   if ( iRes == true)   str_res = "TRUE";
   if ( iRes == false)  str_res = "FALSE";
   ulong    deal        = result.deal;
   double   volume      = result.volume;
   double   price       = result.price;
   ulong    myMagic     = request.magic; 
   ulong    ticket      = result.order;
   Ticket               = result.order;
   //ulong    myTP        = result.
   
   //string   strComment  = result.comment;

   Report_StringError("Both","888030 PAT"+strBorS+"ticket = "+IntegerToString(ticket)+" request.price = "+DoubleToString(request.price,_Digits)+" request.volume = "+DoubleToString(request.volume,2)+
         " type = "+IntegerToString(request.type)+" iRes = "+IntegerToString(iRes)+" price = "+DoubleToString(price,_Digits)+" volume = "+DoubleToString(volume,2)+" is "+str_res+
         " MyComment = "+MyComment);
   return(iRes);
}
//==============================Place_A_Trade END=====================================+

example of Report_StringError above produces the following in my log

GBPUSD 888030 PAT Buy   ticket = 66897307 request.price = 1.26080 request.volume = 0.02 type = 0 iRes = 1 price = 1.26080 volume = 0.02 is TRUE MyComment = GBPUSD_80317499414_B

Probably used this routine 1,000's of times

 
Peter Williams #:
GBPUSD 888030 PAT Buy   ticket = 66897307 request.price = 1.26080 request.volume = 0.02 type = 0 iRes = 1 price = 1.26080 volume = 0.02 is TRUE MyComment = GBPUSD_80317499414_B

If your EA print this part it means that it pass without any error. Does the error really for that ticket?

 
Try to check freeze level, many EA failed a validation because of sl and tp distance lower than freeze level.