"Not" question

 

Hi!

I want to use GetLastError() on my closing functions and my question is this:

If I specify it like that

if(!OrderClose(OrderTicket(),LotSize,Bid,Slippage,Yellow))
Print("Your order was not closed because...");

Do I need to specify it cleanly before the if statement like so,>>  OrderClose(OrderTicket(),LotSize,Bid,Slippage,Yellow);
or it will try to run it anyway and only in the case it cannot it will print..?

 
t0mbfunk:

Hi!

I want to use GetLastError() on my closing functions and my question is this:

If I specify it like that

If you do this . . .

if(!OrderClose(OrderTicket(),LotSize,Bid,Slippage,Yellow))
   Print("Your order was not closed because...");

OrderClose returns a bool so it is the same as doing this . . .

if(!bool)
   Print("Your order was not closed because...");

so it is the correct way to do it . . .


If you do this . . .

OrderClose(OrderTicket(),LotSize,Bid,Slippage,Yellow);

if(!OrderClose(OrderTicket(),LotSize,Bid,Slippage,Yellow))
   Print("Your order was not closed because...");

. . . you have tried to close the same order twice and you will get errors.

You would do this instead . . .

bool OrderClosed;

OrderClosed = OrderClose(OrderTicket(),LotSize,Bid,Slippage,Yellow);

if(!OrderClosed)
   Print("Your order was not closed because...");


I use the first version.

 
Thank you
 
All equivalent:
.
bool OrderClosed;
OrderClosed = OrderClose(OrderTicket(),LotSize,Bid,Slippage,Yellow);
if(!OrderClosed) Print(...
I prefer this over the first, when you need the status in two different places, or when the meaning of the bool is different than the call, e..g. bool isOpenTime = nonTimeFcn().
bool OrderClosed = OrderClose(OrderTicket(),LotSize,Bid,Slippage,Yellow);
if(!OrderClosed) Print(...
For short function calls I prefer this over the second. When a if(function call) must be split over two lines because of its length, then I prefer the second version.
if( !OrderClose(OrderTicket(),LotSize,Bid,Slippage,Yellow) ) Print(...
Reason: