And I'd appreciate a clear statement when double normalize is needed.
Exactly, there is an obvious misunderstanding here. The help for this function gives an example where this function is completely useless:
double NormalizeDouble(
double value, int digits)
Rounds the floating point value to the given precision. Returns normalized value of the double type. The calculated StopLoss and TakeProfit values, as well as open price of pending orders must be normalized with a precision the value of which is stored in the pre-defined variable of Digits.
Parameters:
value
-
Floating point value.
digits
-
Precision format, number of digits after decimal point (0-8).
This double conversion was very confusing to me the first time I saw it. In fact, when outputting it into the Expert Advisor's log, the
Print( DoubleToStr( var1, 5 );
Perhaps the example with some trade function would be much more informative, i.e. it is there where normalization is really needed. The example with CompareDoubles() function from stdlib.mq4 would be very informative too (this is the place where beginners step on it almost invariably):
// Функция корректного сравнения двух переменных типа double из библиотеки stdlib.mq4
boolCompareDoubles(doublenumber1,doublenumber2){if(NormalizeDouble(number1-number2,8)==0)return(true);
elsereturn(false);
}
Now that we're talking about it, I'd like to ask a question that I've been struggling with for a while now. Here's a sample code:
intstart(){doublehaOpen, haHigh, haLow, haClose;
if(Bars<=10)return(0);
ExtCountedBars=IndicatorCounted();
//---- check for possible errorsif(ExtCountedBars<0)return(-1);
What is the fundamental difference between the first return(0) and the second return(-1)? How does it affect the execution of an indicator (or Expert Advisor)? What happens when a negative value is returned? And can I write something like:
There is no difference in principle, because the return value is not analysed by the terminal (at the moment). In fact, this is a recording style which helps the programmer himself to understand that in this case there is a non-standard termination (value minus 1) of start().
That's how I've been writing lately, for example. :) Moreover, I don't even use final return at all. It seems that somewhere in documentation it was even said that in functions like void final return is not necessary.
Originally it was not double, but at some point it suddenly turned out that int type is not always suitable for storing volumes (for example, take a monthly timeframe for a highly volatile instrument). In this case it is easy to get an overflow error.
From documentation (Data types): Integer constants can assume values from -2147483648 to 2147483647. July 2002, EURUSD: maximum number of ticks per month in history, 670000. It would take 3000 months, i.e. 250 years, to get an overflow even with this maximum tick volume. On the other hand, the volumes may grow further, so the figure is not so unattainable theoretically...
From documentation (Data types): Integer constants can assume values from -2147483648 to 2147483647. July 2002, EURUSD: maximum number of ticks per month in history, 670000. It would take 3000 months, i.e. 250 years, to get an overflow even with this maximum tick volume. On the other hand, the volumes may grow further, so the figure is not so unattainable theoretically...
I asked that question myself and got exactly that answer. Even though it's hard to believe. But if you put quotes from the stock market into MT4 ...
Rosh, if I understand your silence correctly, there is no clear statement for which cases and for which expressions/variables normalisation is needed. If this is the case, maybe a simpler question can be answered: is normalisation of calculated values of the form
int StLs=25; double prc = Ask + StLs*Point;
Or should I find this out on my own, in an experiment ?
And I'd appreciate a clear statement when double normalize is needed.
The calculated StopLoss and TakeProfit values, as well as open price of pending orders must be normalized with a precision the value of which is stored in the pre-defined variable of Digits.
This double conversion was very confusing to me the first time I saw it. In fact, when outputting it into the Expert Advisor's log, the
Perhaps the example with some trade function would be much more informative, i.e. it is there where normalization is really needed. The example with CompareDoubles() function from stdlib.mq4 would be very informative too (this is the place where beginners step on it almost invariably):
Renat, isn't that an option?
What is the fundamental difference between the first return(0) and the second return(-1)?
How does it affect the execution of an indicator (or Expert Advisor)?
What happens when a negative value is returned?
And can I write something like:
And can I write something like:
From documentation (Data types): Integer constants can assume values from -2147483648 to 2147483647. July 2002, EURUSD: maximum number of ticks per month in history, 670000. It would take 3000 months, i.e. 250 years, to get an overflow even with this maximum tick volume. On the other hand, the volumes may grow further, so the figure is not so unattainable theoretically...
From documentation (Data types): Integer constants can assume values from -2147483648 to 2147483647. July 2002, EURUSD: maximum number of ticks per month in history, 670000. It would take 3000 months, i.e. 250 years, to get an overflow even with this maximum tick volume. On the other hand, the volumes may grow further, so the figure is not so unattainable theoretically...
I asked that question myself and got exactly that answer. Even though it's hard to believe. But if you put quotes from the stock market into MT4 ...
Rosh, if I understand your silence correctly, there is no clear statement for which cases and for which expressions/variables normalisation is needed. If this is the case, maybe a simpler question can be answered: is normalisation of calculated values of the form
int StLs=25;
double prc = Ask + StLs*Point;
Or should I find this out on my own, in an experiment ?