Download MetaTrader 5

Need some help with this simple coding bug

To add comments, please log in or register
Publish programs in Code Base. Improve your rating!
Muhammad Elbermawi
3068
Muhammad Elbermawi 2015.02.12 09:47 

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
602
Snelle Moda 2015.02.12 10:39  
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
8576
Janusz Trojca 2015.02.12 10:40  
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
5812
Stuart Browne 2015.02.12 10:42  

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
498
Donald Gibson 2015.02.12 10:49  
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
3068
Muhammad Elbermawi 2015.02.12 19:29  
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
3068
Muhammad Elbermawi 2015.02.13 06:21  

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