Download MetaTrader 5

Need some help with this simple coding bug

To add comments, please log in or register
Muhammad Elbermawi
3285
Muhammad Elbermawi  

When I compile an EA that I try to develop I got this warning:

return value of 'OrderDelete' should be checked 

this Error message came from this function:

int DeletePendingOrders(int Magic)
{
int total  = OrdersTotal();
 
for (int cnt = total - 1; cnt >= 0; cnt--)
{
 if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
 if (OrderMagicNumber() == Magic && OrderSymbol()==Symbol() && (OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP || OrderType()==OP_BUYLIMIT|| OrderType()==OP_SELLLIMIT))
 {
 
   OrderDelete(OrderTicket());
   
 
 }
}

Could any pro here help me to get rid from this warning.

Snelle Moda
648
Snelle Moda  
bermaui314:

When I compile an EA that I try to develop I got this warning:

return value of 'OrderDelete' should be checked 

this Error message came from this function:

Could any pro here help me to get rid from this warning.

You get this warning because you need to check the return value of the function when it's executed.

https://www.mql5.com/en/docs/standardlibrary/tradeclasses/ctrade/ctradeorderdelete


In your code, you can use this as an example.


int DeletePendingOrders(int Magic)

int total  = OrdersTotal();
 
for(int cnt = total - 1; cnt >= 0; cnt--)
      {      
      if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
      if(OrderMagicNumber() == Magic && OrderSymbol()==Symbol() && (OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP || OrderType()==OP_BUYLIMIT|| OrderType()==OP_SELLLIMIT))
         {
 
         if(OrderDelete(OrderTicket()) == false)
               {              
               Alert("Your order is NOT deleted!");              
               }
         }
      }
Documentation on MQL5: Standard Library / Trade Classes / CTrade / OrderDelete
Documentation on MQL5: Standard Library / Trade Classes / CTrade / OrderDelete
  • www.mql5.com
Standard Library / Trade Classes / CTrade / OrderDelete - Reference on algorithmic/automated trading language for MetaTrader 5
InvestSoft
12030
Janusz Trojca  
bermaui314:

When I compile an EA that I try to develop I got this warning:

return value of 'OrderDelete' should be checked 

this Error message came from this function:

Could any pro here help me to get rid from this warning.

OrderDelete return true if success or false if fail so you should check what is a result of executing OrderDelete e.g.:

   if (!OrderDelete(OrderTicket())) Print("Order Delete Error "+IntegerToString(GetLastError()));
Stuart Browne
6968
Stuart Browne  

OrderDelete() returns a boolean (true/false). So the warning is telling you it should be checked to confirm if the function was successful. It won't stop your code compiling but you may experience unexpected results if you don't check the return value

eg:  

bool res = OrderDelete(OrderTicket());
if (!res)
   {
      // Your OrderDelete failed here - what are you going to do?
   }
Donald Gibson
499
Donald Gibson  
bermaui314:

When I compile an EA that I try to develop I got this warning:

return value of 'OrderDelete' should be checked 

this Error message came from this function:

Could any pro here help me to get rid from this warning.

you can also declare it as a int, which will be zero (0) if false and 1 if true.
Muhammad Elbermawi
3285
Muhammad Elbermawi  
snelle_moda:

You get this warning because you need to check the return value of the function when it's executed.

https://www.mql5.com/en/docs/standardlibrary/tradeclasses/ctrade/ctradeorderdelete


In your code, you can use this as an example.


Thanks a lot for your help
snelle_moda:

You get this warning because you need to check the return value of the function when it's executed.

https://www.mql5.com/en/docs/standardlibrary/tradeclasses/ctrade/ctradeorderdelete


In your code, you can use this as an example.


Muhammad Elbermawi
3285
Muhammad Elbermawi  

I solved the problem with your aid my friends :)

Thanks a lot for every Pro who tried to help me here

To add comments, please log in or register