Mql5 Tester OrderSend error 4756 BUT there is no SL and TP

 

Hi. I use this void to open my trades and i get error 4756  which from what i understand is invalid stop.BUT i do not set either sl or tp.

  ///////////////////////////////////////////////////////////////////
void SendOrder(string thissymbol, double found, ENUM_TIMEFRAMES TF2 , double buys, double sells, double stop1, double limit1,double closed, int count  , string dir)
{


     double Lots=(Firstdeposit+closed)/dieresi;

            if (found>count)Lots=Lots*(found+1);
            if (count>found)Lots=Lots*(count+1);

MqlDateTime mdt;
TimeCurrent(mdt);
 if (  dir=="buy" && isNewBar(thissymbol,TF2)
 ){ 
 
//--- declare and initialize the trade request and result of trade request
MqlTradeRequest request;
ZeroMemory(request);
MqlTradeResult result;
ZeroMemory(result);


      request.action = TRADE_ACTION_DEAL;
      request.symbol = thissymbol;
      request.volume = NormalizeDouble(Lots,2);
      request.type = ORDER_TYPE_BUY;
  if (IsFillingTypeAllowed(thissymbol,ORDER_FILLING_FOK))    request.type_filling = ORDER_FILLING_FOK;///
  if (IsFillingTypeAllowed(thissymbol,ORDER_FILLING_IOC))    request.type_filling = ORDER_FILLING_IOC;///
  if (IsFillingTypeAllowed(thissymbol,ORDER_FILLING_RETURN))    request.type_filling = ORDER_FILLING_RETURN;///
      request.price    =NormalizeDouble(SymbolInfoDouble(thissymbol,SYMBOL_ASK),ENUM_SYMBOL_INFO_INTEGER(SYMBOL_DIGITS));// price for opening
      request.deviation = 1000;
      request.magic    =12345;  
      request.comment = EnumToString(TF2);  
       if (CheckVolumeValue(NormalizeDouble(Lots,2),thissymbol)) 
          {
    if(!OrderSend(request,result))
            PrintFormat("OrderSend error %d",GetLastError());
          } 
 }
 

 if (  dir=="sell" && isNewBar(thissymbol,TF2)
 ){
//--- declare and initialize the trade request and result of trade request
   MqlTradeRequest request;
   ZeroMemory(request);
   MqlTradeResult  result;
   ZeroMemory(result);

      request.action = TRADE_ACTION_DEAL;
      request.symbol = thissymbol;
      request.volume = NormalizeDouble(Lots,2);
      request.type = ORDER_TYPE_SELL;
  if (IsFillingTypeAllowed(thissymbol,ORDER_FILLING_FOK))    request.type_filling = ORDER_FILLING_FOK;///
  if (IsFillingTypeAllowed(thissymbol,ORDER_FILLING_IOC))    request.type_filling = ORDER_FILLING_IOC;///
  if (IsFillingTypeAllowed(thissymbol,ORDER_FILLING_RETURN))    request.type_filling = ORDER_FILLING_RETURN;///
      request.price    =NormalizeDouble(SymbolInfoDouble(thissymbol,SYMBOL_BID),ENUM_SYMBOL_INFO_INTEGER(SYMBOL_DIGITS));// price for opening
      request.deviation = 1000;
      request.magic    =12345;  
      request.comment =EnumToString(TF2);    
   if (CheckVolumeValue(NormalizeDouble(Lots,2),thissymbol)) 
   {
    if(!OrderSend(request,result))
            PrintFormat("OrderSend error %d",GetLastError());
   }
   


 }
 

}
//+------------------------------------------------------------------+
//| Checks if the specified filling mode is allowed                  |
//+------------------------------------------------------------------+
bool IsFillingTypeAllowed(string thissymbol,int fill_type)
  {
//--- Obtain the value of the property that describes allowed filling modes
   int filling=(int)SymbolInfoInteger(thissymbol,SYMBOL_FILLING_MODE);
//--- Return true, if mode fill_type is allowed
   return((filling & fill_type)==fill_type);
  }
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   bool isNewBar(string thissymbol, ENUM_TIMEFRAMES TF2)
  {
//--- memorize the time of opening of the last bar in the static variable
   static datetime last_time=0;
//--- current time
   datetime lastbar_time=SeriesInfoInteger(thissymbol,TF2,SERIES_LASTBAR_DATE);

//--- if it is the first call of the function
   if(last_time==0)
     {
      //--- set the time and exit
      last_time=lastbar_time;
      return(false);
     }

//--- if the time differs
   if(last_time!=lastbar_time)
     {
      //--- memorize the time and return true
      last_time=lastbar_time;
      return(true);
     }
//--- if we passed to this line, then the bar is not new; return false
   return(false);
  }
   
   
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

As you can see in the image some trades are succesfull and some are not.

I use MT5 from metaquotes where i have opened a demo account and trying to test my strategy.

Can you spot what i am doing wrong?


I Tried.

1 to check filling mode first.

2 to normalize price ask/bid.

3 to remove request.sl and request.tp



 
Your topic has been moved to the section: Expert Advisors and Automated Trading — In the future, please consider which section is most appropriate for your query.
 

The error only means this ...

ERR_TRADE_SEND_FAILED

4756

Trade request sending failed

Verify the trade result code as well for the real reason. Also analyse the log output.

As an extra guidance follow the practices described in the following article as well ...

Articles

The checks a trading robot must pass before publication in the Market

MetaQuotes, 2016.08.01 09:30

Before any product is published in the Market, it must undergo compulsory preliminary checks in order to ensure a uniform quality standard. This article considers the most frequent errors made by developers in their technical indicators and trading robots. An also shows how to self-test a product before sending it to the Market.