Hi,
I wrote a simple script that is supposed to calculate a distance (in pips) between moving average and current price.
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.0006
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?
I wrote a simple script that is supposed to calculate a distance (in pips) between moving average and current price.
Inserted Code
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.0006
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?