return value of 'OrderModify' should be checked error

 

I am struggling with this little mq4 piece of code.

I get the following error 

return value of 'OrderModify' should be checked ea3WayHedging_1-9.mq4 399 10

      {
         OrderModify(orders[0].ticket, NormalizeDouble(Ask + TrailingDistanceOrder1*point, Digits), OrderStopLoss(), OrderTakeProfit(), OrderExpiration());
      }


I tried the following 

      {
         if ( ! OrderModify(orders[0].ticket, NormalizeDouble(Ask + TrailingDistanceOrder1*point, Digits), OrderStopLoss(), OrderTakeProfit(), OrderExpiration())) continue;
      }

then I get this error
';' - 'continue' must be used within some loop only ea3WayHedging_1-9.mq4 399 172

any idea what I am doing wrong and how to correct it would be appreciated.
Franzel

 

You're close, but you cannot use "continue" unless you are inside a loop.

What you really want to do is handle the error. At a minimum, dump the error code to the log.


if ( ! OrderModify( . . . ) )
{
        // Do something to handle the error
        Print("Error in OrderModify. Error code=",GetLastError());
}
 

Function OrderModify() returns a value depending on the outcome:

If the function succeeds, it returns true, otherwise false.


So you have to check this value to see if the call was successful or not.

The best way to illustrate what it means is like this:

bool result;

result = OrderModify(orders[0].ticket, NormalizeDouble(Ask + TrailingDistanceOrder1*point, Digits), OrderStopLoss(), OrderTakeProfit(), OrderExpiration());

if(result == 1)
 {
  Print("Ordermodify successful");
 }

if(result == 0)
 {
  Print("Ordermodify UN-successful");
 }
Trade Server Return Codes - Codes of Errors and Warnings - Standard Constants, Enumerations and Structures - MQL4 Reference
Trade Server Return Codes - Codes of Errors and Warnings - Standard Constants, Enumerations and Structures - MQL4 Reference
  • docs.mql4.com
GetLastError() - returns error codes. Error codes are defined in stderror.mqh. To print the error description you can use the ErrorDescription() function, defined in stdlib.mqh.
 
Franzel Botha:

I am struggling with this little mq4 piece of code.

I get the following error 

return value of 'OrderModify' should be checked ea3WayHedging_1-9.mq4 399 10


I tried the following 

then I get this error
';' - 'continue' must be used within some loop only ea3WayHedging_1-9.mq4 399 172

any idea what I am doing wrong and how to correct it would be appreciated.
Franzel

double TrailingDistanceOrder1=300;
   bool ticket;
   for (int i = 0; i < OrdersTotal(); i++) 
      {
      
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)        break;
     
      
     ticket= OrderModify(OrderTicket(), NormalizeDouble(Ask + TrailingDistanceOrder1*Point, Digits), OrderStopLoss(), OrderTakeProfit(), OrderExpiration());      
    

     }
 
The use of ticket would be utterly confusing.
 
if( !OrderModify(orders[0].ticket, NormalizeDouble(Ask + TrailingDistanceOrder1*point, Digits), OrderStopLoss(), OrderTakeProfit(), OrderExpiration()) )
        Print("Error in OrderModify. Error code=",GetLastError());
else
        Print("Order modified successfully.");
Reason: