![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
float askP=NormalizeDouble(Ask,Digits)/NormalizeDouble(Point,Digits);
float bidP=NormalizeDouble(Bid,Digits)/NormalizeDouble(Point,Digits);
float Averab=((askP+bidP))/2.0;
AUTOPRICE=MathFloor(Averab)*Point;
Print("FLOAT "+" askP="+askP+" bidP="+bidP+" Averab="+DoubleToString(Averab,10)+" AUTOPRICE="+DoubleToString(AUTOPRICE,10));
double AUTOPRICE2;
double askP2=NormalizeDouble(Ask,Digits)/NormalizeDouble(Point,Digits);
double bidP2=NormalizeDouble(Bid,Digits)/NormalizeDouble(Point,Digits);
double Averab2=((askP2+bidP2))/2.0;
AUTOPRICE2=MathFloor(Averab2)*Point;
Print("DOUBLE "+" askP2="+askP2+" bidP2="+bidP2+" Averab2="+DoubleToString(Averab2,10)+" AUTOPRICE="+DoubleToString(AUTOPRICE2,10));
spread:2
2017.02.26 09:56:54.475 2017.01.02 00:03:00 Exp - DOUBLE TEST MATHFLOOR EURUSD,M30: DOUBLE askP2=105143 bidP2=105141 Averab2=105142.0000000000 AUTOPRICE=1.0514200000
2017.02.26 09:56:54.475 2017.01.02 00:03:00 Exp - DOUBLE TEST MATHFLOOR EURUSD,M30: FLOAT askP=105143 bidP=105141 Averab=105142.0000000000 AUTOPRICE=1.0514199734
spread:3
2017.02.26 09:57:47.832 2017.01.02 00:03:00 Exp - DOUBLE TEST MATHFLOOR EURUSD,M30: DOUBLE askP2=105144 bidP2=105141 Averab2=105142.5000000000 AUTOPRICE=1.0514200000
2017.02.26 09:57:47.832 2017.01.02 00:03:00 Exp - DOUBLE TEST MATHFLOOR EURUSD,M30: FLOAT askP=105144 bidP=105141 Averab=105142.5000000000 AUTOPRICE=1.0514199734
spread:4
2017.02.26 09:58:05.813 2017.01.02 00:03:00 Exp - DOUBLE TEST MATHFLOOR EURUSD,M30: DOUBLE askP2=105145 bidP2=105141 Averab2=105143.000000 AUTOPRICE=1.0514200000
2017.02.26 09:58:05.813 2017.01.02 00:03:00 Exp - DOUBLE TEST MATHFLOOR EURUSD,M30: FLOAT askP=105145 bidP=105141 Averab=105143.0000000000 AUTOPRICE=1.0514299870
spread:5
2017.02.26 09:58:39.495 2017.01.02 00:03:00 Exp - DOUBLE TEST MATHFLOOR EURUSD,M30: DOUBLE askP2=105146 bidP2=105141 Averab2=105143.5000000000 AUTOPRICE=1.0514300000
2017.02.26 09:58:39.495 2017.01.02 00:03:00 Exp - DOUBLE TEST MATHFLOOR EURUSD,M30: FLOAT askP=105146 bidP=105141 Averab=105143.5000000000 AUTOPRICE=1.0514299870
2017.02.26 09:58:05.813 2017.01.02 00:03:00 Exp - DOUBLE TEST MATHFLOOR EURUSD,M30: DOUBLE askP2=105145 bidP2=105141 Averab2=105143.000000 AUTOPRICE=1.0514200000
The result is correct. Averab2 < 105143.
The result is correct. Averab2 < 105143.
why? becauseAverab2=105143.0000000000
Why?Averab2=105143.0000000000
Forum on trading, automated trading systems & strategy testing
Double vs FLOAT - unclear MathFloor error
fxsaber, 2017.02.26 08:27
The printout of the double number is about nothing. If you want to print the true value of double, you need to look at its bytes.
Why? BecauseAverab2=105143.0000000000
I see your point. Thank you, but this is as far as the unpriming is concerned.
But the real value inside the code is the same as after unpriming. I've checked it more than once,
I understand,
that double 1 = 1.0000000000000000000000000000112123515;
and so on.
:-( ok, the main thing is that the problem is solved with float
becausehttps://www.mql5.com/ru/docs/math/mathfloor
105143
after MathFloor(105143) =105142
even if 105143.000000000000000000001
but I think I know what you're talking about.
although no
why MathFloor(105143) =105142 I can't understand... (unless it's not105143 but105142.9999999999999999999999)
why then...
why then MathFloor(105143) =105142 I cannot understand... (unless it's not105143, but105142.999999999999999999999999)
void OnStart()
{
double Price1 = 105143;
double Price2 = Price1 - 1 e-11;
Print(TOSTRING(Price1) + TOSTRING(MathFloor(Price1)) +
TOSTRING(Price2) + TOSTRING(MathFloor(Price2)) +
TOSTRING(Price1 > Price2));
}
You shouldn't take double-numbers literally. Switching to float is even more of a pitfall.