ok some times it outputs something like 44.99999999 or 44.00000001 its like it has some small math error
------------------
this is because the floating nuber issus ,and cannot be slove within mql.
but you can fix it by Point or by LotsStep.
for Price,fix it like this:
void OnStart()
{
double x=123.1234567891;
Print("before: x=",x);
x=(int)(x/Point)*Point; //or use MathRound()
Print("after : x=",x);
}
2018.11.07 01:12:12.739 testscript EURAUD,H4: 123.12345
2018.11.07 01:12:12.739 testscript EURAUD,H4: 123.1234567891
for lots,refer to MarketInfo(xxx, MODE_LOTSTEP)
ok some times it outputs something like 44.99999999 or 44.00000001 its like it has some small math error
------------------
this is because the floating nuber issus ,and cannot be slove within mql.
but you can fix it by Point or by LotsStep.
for Price,fix it like this:
void OnStart()
{
double x=123.1234567891;
Print("before: x=",x);
x=(int)(x/Point)*Point; //or use MathRound()
Print("after : x=",x);
}
2018.11.07 01:12:12.739 testscript EURAUD,H4: 123.12345
2018.11.07 01:12:12.739 testscript EURAUD,H4: 123.1234567891
for lots,refer to MarketInfo(xxx, MODE_LOTSTEP)
ok so like this then
double m1_IRS = iRSI(NULL,1,14,PRICE_CLOSE,0); double temp1 = m1_IRS*100; m1_IRS = MathRound(temp1); m1_IRS = m1_IRS/100;
ok so like this then
you learn so fast haha
yah the only thing is it don't work though
yah the only thing is it don't work though
doesnt work well? why?
it dose the some thing even tried NormalizeDouble() it still did not work
You are not being clear of what it is you describe as is not working or what you expect to "work". Plus you must remember the "doubles" or "floats" are not exact decimal numbers. Here is a pocket link from another thread that may help you understand that you can't always get an exact number:
Forum on trading, automated trading systems and testing trading strategies
MathRound fails for one particular number
Fernando Carreiro, 2018.01.01 22:08
He means that the value "0.69" cannot be exactly represented given the way a floating point number works (based on binary and not decimal representation) - hence, why the value gets represented as "0.68999999..." (see below).
You can never really "normalize" it and it is the main reason why both @whroeder1 and myself contest the use of the NormalizeDouble() function. It should in the very least be renamed to something like "RoundDigits()" because it is more of a "rounding" function and does not "normalize" in any way or fashion.
https://www.h-schmidt.net/FloatConverter/IEEE754.html
EDIT: Please note that the above images are for examples of representation in the 4-byte "float", and not the 8-byte "double" which offers more precision but still cannot represent the value "0.69" exactly due to the "binary" nature of the format.
EDIT2: For future readers that have difficulty understanding (or accepting) this concept, of decimal values not having an exact representation with a "float" or a "double", here is an article worth reading:
Why 0.1 Does Not Exist In Floating-Point
Many new programmers become aware of binary floating-point after seeing their programs give odd results: “Why does my program print 0.10000000000000001 when I enter 0.1?”; “Why does 0.3 + 0.6 = 0.89999999999999991?”; “Why does 6 * 0.1 not equal 0.6?” Questions like these are asked every day, on online forums like stackoverflow.com.
The answer is that most decimals have infinite representations in binary. Take 0.1 for example. It’s one of the simplest decimals you can think of, and yet it looks so complicated in binary:
Decimal 0.1 In Binary ( To 1369 Places
The bits go on forever; no matter how many of those bits you store in a computer, you will never end up with the binary equivalent of decimal 0.1.
... Read the rest of the article at: http://www.exploringbinary.com/why-0-point-1-does-not-exist-in-floating-point/
void OnStart() { //Double to int back to double based on the chart symbol's digits double double_bid = Bid; Print(DoubleToString(double_bid, _Digits)); int int_bid = int(round(double_bid / _Point)); Print(int_bid); double_bid = int_bid * _Point; Print(DoubleToString(double_bid, _Digits)); }
yah that still will not work though do to bit resilion but the DoubleToString() works should have thought of that sooner my bad
if any one has a answer to my other question i tried not drawing the buffers but they still show up on the indicator
SetIndexDrawBegin(1,InpRSIPeriod); SetIndexDrawBegin(2,InpRSIPeriod);
right now i change the number of indicators to 1 so they don't show up
#property indicator_buffers 3
damn! such this problem i havd sloved ,
just by using the same code showed at the first post.
i know the issus about the float/double,why it is so difficult for you?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
ok some times it outputs something like 44.99999999 or 44.00000001 its like it has some small math error
and one other thing i added 2 more indicator buffers that show the high and the low for each candle but i want to be able to turn them off and on don't know how to do that in the code.