Need help with OrderStopLoss and OrderTakeProfit

 
I have this piece of code:

Comment("\nOrderStopLoss: ",OrderStopLoss(), "\nSL: ", SL, "\nOrderTakeProfit: ", OrderTakeProfit(), "\nTP: ", TP);
if (OrderStopLoss() != SL || OrderTakeProfit() != TP) {
	OrderModify(OrderTicket(),0,SL,TP,0,CLR_NONE);
}



The Comment before the if statement shows that OrderStopLoss being equal to SL and OrderTakeProfit equal to TP as well. Yet, the IF statement does not agree. I looked at the Journal and see that it went to send the OrderModify command to the server:

2006.09.14 08:05:17 '1217099': modify order #11586895 buy 1.00 USDJPY at 117.4500 sl: 117.3800 tp: 117.7300 -> sl: 117.3800 tp: 117.7300


I have this subcode within a loop and the loop will keep looping while (OrderStopLoss != SL || OrderTakeProfit != TP). And since it could not perform the != operation properly, it kept looping indefinitely and keep sending an OrderModify to the server.

It does sometimes able to do the != operation properly and exits from the loop, but sometimes it does not.

Was it because all of the above values are double and MT4 engine could not properly compare "double" values properly? This has always been the problem with "non-integer" numbers with computers ever since... I'll try to "integerize" the number and see what will come out...

Any help is most welcome.

Thanks!





 
Solved.

As suspected, "double" variable is the problem.

Computers have always had hard time representing "double" (aka, fractional/real numbers) onto computers. "real" numbers are only represented as "estimates" inside a computer and therefore, what may appear to us as 1.2831 would actually be something like 1.283100031 and only rounded to appear 1.2831

So I simply "integerize" all those doubles by multiplying it with 10000. 1.2831 will now be 12831 and all ends well.
 
Reason: