return value of OrderSend should be checked

 

Hi all,

I couldnt find any solution that worked on the following problem:

I added a new "Order function" to my EA, but everytime I get the warning "return value of OrderSend should be checked". The EA doesnt open any trades anymore.

void BuyOrder()
{
    
    //--- prepare a request
    MqlTradeRequest request;
    ZeroMemory(request);
    request.action = TRADE_ACTION_DEAL;          // setting a deal order
    request.magic = 1;                   // ORDER_MAGIC
    request.symbol = Symbol();                   // symbol
    request.volume= Lots;                      // volume in lots
    request.price = Ask();
    request.sl = Low(current+1);                     // Stop Loss specified
    request.tp = 250;                   // Take Profit specified
    request.deviation= Deviation;             // deviation in 5 points
    request.type = ORDER_TYPE_BUY;
    request.comment = "Order";
    
    MqlTradeResult result;
    ZeroMemory(result);
    OrderSend(request,result);
    // check the result
    if (!IsError(result, __FUNCTION__))
    {
        
    }
}

Any ideas where the mistake could be?


Thansk in advance!

 
Nils1990:

Hi all,

I couldnt find any solution that worked on the following problem:

I added a new "Order function" to my EA, but everytime I get the warning "return value of OrderSend should be checked". The EA doesnt open any trades anymore.

Any ideas where the mistake could be?


Thansk in advance!

Try by changing this line of code:


bool success = OrderSend(request,result);


Whether you use the boolean " success" or not is not so important, the compiler wants to see that you define and assign it. 

 
WindmillMQL:

Try by changing this line of code:



Whether you use the boolean " success" or not is not so important, the compiler wants to see that you define and assign it. 

thanks for your quick reply. I really appreciate it!!!

I still get the same Warning and still no trades.... Do u have maybe another idea?
 

You have to analyze the result to see if the action was successful or not.

//+------------------------------------------------------------------+
//| Opening Buy position                                             |
//+------------------------------------------------------------------+
void Buy(int magicnumber,string symbol,double lots,double tp,double sl)
{
//--- 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    = lots;                                  // volume
   request.type      = ORDER_TYPE_BUY;                        // order type
   request.price     = SymbolInfoDouble(symbol,SYMBOL_ASK);   // price for opening
   request.deviation = 3;                                     // allowed deviation from the price
   request.sl        = sl;                                    // Stop Loss of the position
   request.tp        = tp;                                    // Take Profit of the position
   request.magic     = magicnumber;                           // 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);
}
//+------------------------------------------------------------------+
//| Opening Sell position                                            |
//+------------------------------------------------------------------+
void Sell(int magicnumber,string symbol,double lots,double tp,double sl)
{
//--- 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    = lots;                                  // volume
   request.type      = ORDER_TYPE_SELL;                       // order type
   request.price     = SymbolInfoDouble(symbol,SYMBOL_BID);   // price for opening
   request.deviation = 3;                                     // allowed deviation from the price
   request.sl        = sl;                                    // Stop Loss of the position
   request.tp        = tp;                                    // Take Profit of the position
   request.magic     = magicnumber;                           // 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);
}
//+------------------------------------------------------------------+
 
Marco vd Heijden :

You have to analyze the result to see if the action was successful or not.

Its working now !!

thank you very much and enjoy your day :)

 
Nils1990:
thanks for your quick reply. I really appreciate it!!!

I still get the same Warning and still no trades.... Do u have maybe another idea?
I was wrong. As Marco indicated you actually have to analyse the result.
 

please how can I loop over my positions and select a position to further work it?

The code below works for MQL4 but I need MQL5 code that will do exactly the same thing.

Please I need help on this.

int openOrders = PositionsTotal();

for(int i = 0; i < openOrders; i++)                                            

      {                                                                                                                       
                                                             
         if(OrderSelect(i,SELECT_BY_POS) == true)               
         {                                                        
            if(OrderMagicNumber() == magicNB)                       
            {       
               return true;                                            
            }                                                        
         }      

      }                       

Thanks.

 
mike5n:


Please edit your post and use the code button (Alt+S) when pasting code.

EDIT your original post, please do not just post the code properly in a new post.

 

I have deleted a post as code was not posted properly.

There is no excuse for the person as it was directly after my last post.

Reason: