Discussion on MQL4 documentation - page 16

 
Yurixx:

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).
Sample:
 double var1=0.123456789; Print(DoubleToStr(NormalizeDouble(var1,5),5)); // output: 0.12346

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
bool CompareDoubles(double number1,double number2)
{
   if(NormalizeDouble(number1-number2,8)==0) return(true);
   else return(false); 
}
Renat, isn't that an option?
 
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:
int start()
  {
   double haOpen, haHigh, haLow, haClose;
   if(Bars<=10) return(0);
   ExtCountedBars=IndicatorCounted();
//---- check for possible errors
   if (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:
void start()
{
  //
  //...
  //
  return;
}
 
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().
 
PSmith:
And can I write something like:
void start()
{
  //
  //...
  //
  return;
}

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.
 
Here's another question: why does the function
double iVolume( string symbol, int timeframe, int shift)
returns value of double type?
 
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...

 
Mathemat:

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 ...
 
Same month on _DJI - 42228720! Yeah...
 

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 ?

Reason: