Use of "!"

 

Would someone please tell me the significance of the "!" in front of OrderClose and what it does.

if (!OrderClose(MyOrderTicket, LotsNumber, Ask, 3, CLR_NONE))

I am attempting to code a simple EA and this is the first time I have come across the "!" being used like this.

Regards,

KeithN

 

! simply means logical NOT, so as OrderClose() returns a boolean value, !OrderClose() inverts the return value from the function.

 
flimbo wrote >>

! simply means logical NOT, so as OrderClose() returns a boolean value, !OrderClose() inverts the return value from the function.

Thanks flimbo.

But the Order would be closed, wouldn't it?

KeithN

 
KeithN:

Thanks flimbo.

But the Order would be closed, wouldn't it?

KeithN

It is attempting to close the order, if it returns true, then you know it was successfully closed. If it failed to close it, then it returns false and you can handle that situation. In other words:

if (!OrderClose(MyOrderTicket, LotsNumber, Ask, 3, CLR_NONE))

{

//oh no, my order DID NOT close, do something !

}


Or the oppositve approach,

if (OrderClose(MyOrderTicket, LotsNumber, Ask, 3, CLR_NONE))

{

//Yes, my order closed, I'm in my happy place now

}




Reason: