Strange MT4 output - mql bug ?

 
Hi,
I wrote a simple script that is supposed to calculate a distance (in pips) between moving average and current price.
int start()
{
Alert("++++++++++++++++++");
Alert("Digits: ", Digits);
Alert("Bid: "+(Bid));
Alert("MA: ",+(iMA(NULL, 0, 3, 1, MODE_LWMA, PRICE_CLOSE, 0)));
if (Bid > iMA(NULL, 0, 3, 1, MODE_LWMA, PRICE_CLOSE, 0))
{
x = Bid - iMA(NULL, 0, 3, 1, MODE_LWMA, PRICE_CLOSE, 0);
Alert("Bid - MA = ", x);
}
if (Bid < iMA(NULL, 0, 3, 1, MODE_LWMA, PRICE_CLOSE, 0))
{
x = iMA(NULL, 0, 3, 1, MODE_LWMA, PRICE_CLOSE, 0) - Bid;
Alert("MA - Bid = ", x);
}
y = MathPow(10, Digits);
Alert("10 to power of ", Digits, " = ", y);
z = x * y;
Alert(x, " * ", y, " = ", z);
return(0);
}

Example outputs:

Digits: 4
Bid: 1.08420000
MA: 1.0749
MA - Bid = 0.0093
10 to power of 4 = 10000

0.0093 * 10000 = 92.8333


Digits: 5
Bid: 1.53059000
MA: 1.53
Bid - MA = 0.000 6
10 to power of 5 = 100000

0.0006 * 100000 = 59


How comes 0.0093 * 10000 equals 92.8333 ? Should be 93.
How comes 0.0006 * 100000 equals 59 ??
This is not a single case, almost always calculation is wrong...

Can someone explain what does it happen ? Is it a mql4 error or am I missing something?

 
okt:
[...] This is not a single case, almost always calculation is wrong...

Can someone explain what does it happen ? Is it a mql4 error or am I missing something?

This sounds like an issue to do with arithmetic involving double values - for one of the many previous discussions of this issue, see https://www.mql5.com/en/forum/117138. In essence, MT4 is using more digits of precision than you're seeing in your alerts.

 
Reason: