OrderModify

 

Hello,

I wrote this:


TicketModify = OrderModify(OrderTicket(),OpenPrice,StopLoss,0,0,Blue); // Order modify


// Returns result and error messages
void PrintMessageOrderModify (bool ticket) {
int check;
check=GetLastError();
if(ticket) Print("An order has been successfully placed with ticket # ",ticket,"."); // request is completed or order is placed
if(ticket<0)
switch(check) {
case 2: Print("TradeLog: Trade request failed. Error: ",check, ". Description: ERR_COMMON_ERROR"); break; //

case 3: Print("TradeLog: Trade request failed. Error: ",check, ". Description: ERR_INVALID_TRADE_PARAMETERS"); break; //

case 130: Print("TradeLog: Trade request failed. Error: ",check, ". Description: ERR_INVALID_STOPS"); break; //

etc...

}

}

When I use OrderModify() to move the stop loss, and then PrintMessageOrderModify is called to display whether it worked or not, I'm always getting that OrderModify has been successful, that is, "An order has been successfully placed with ticket # 0", even though in cases that the stop loss could't trail (didn't move) because there were no pips enough to allow it (distance was too tight, price didn't move enough), so I should be getting 'INVALID STOPS'.

So the problem may be with the condition I'm putting for the conditionals if(). From Documentation I know that OrderModify yields TRUE or FALSE, and I'm using if(ticket) and if(ticket<0). I tried if(ticket==TRUE) and if (ticket==FALSE), but in this case no message was displayed, not even "An order has been successfully placed with ticket # 0".

Any ideas?

Thanks

 

Try this . .

if(!ticket) 
switch(check) { 

is the same as . . .

if(ticket == false) 
switch(check) { 

From here: https://docs.mql4.com/basis/types/bool "Boolean constants may have the value of true or false, numeric representation of them is 1 or 0, respectively. True or TRUE, False or FALSE can be used, as well."

If that doesn't help . . . make sure TicketModify is declared as type bool . . .

 

OrderSend returns an int (the ticket number or -1 on error)

OrderModify returns a bool (true or false) Not a ticket number

RTFM