Download MetaTrader 5

Strange behaviour of the NormalizeDouble() function.

To add comments, please log in or register
Are you a good trader? Become a signals provider and make even more money!
Snelle Moda
602
Snelle Moda 2015.10.16 17:49 

Hi

I use some notification alerts in my EA for displaying variables. See the picture.

To minimize the number of decimal numbers I use the NormalizeDouble() function to decrease the number of decimals to 2. 

NormalizeDouble(dPosition_Trend_RendementRatio,2)


But sometimes. This function does not work. (see the picture)

Does anybody know why? And how to solve this.


Thanks

Files:
Log.jpg 853 kb
Osama Shaban
1448
Osama Shaban 2015.10.16 20:30  

Try to look for the variable/fromula for dPosition_Trend_RendementRatio ... Do a special case if there is a zero division or so ...

In general, I mean, you have to consider every case that could happen to get the dPosition_Trend_RendementRatio value.

Also, in printing/showing dPosition_Trend_RendementRatio on chart, you have to change the value to string.

This could help.

Good luck. 

Carl Schreiber
6592
Carl Schreiber 2015.10.16 21:25  
snelle_moda:

Hi

I use some notification alerts in my EA for displaying variables. See the picture.

To minimize the number of decimal numbers I use the NormalizeDouble() function to decrease the number of decimals to 2. 

NormalizeDouble(dPosition_Trend_RendementRatio,2)


But sometimes. This function does not work. (see the picture)

Does anybody know why? And how to solve this.


Thanks

This is the nature of the doubles ( https://en.wikipedia.org/wiki/Double-precision_floating-point_format ). E.g. they never will be exactly 3! NormalizeDouble() is only the nearest value to the wanted precision!
Double-precision floating-point format - Wikipedia, the free encyclopedia
Double-precision floating-point format - Wikipedia, the free encyclopedia
  • en.wikipedia.org
Double-precision floating-point format is a computer number format which occupies 8 bytes (64 bits) in computer memory and represents a wide, dynamic range of values by using a floating point. Computers with 32-bit storage locations use two memory locations to store a 64-bit double-precision number; each storage location holds a...
Snelle Moda
602
Snelle Moda 2015.10.16 22:17  

Thanks for all the input.


It's not a zero division problem, it's already checked in the code.

Maybe I should use the DoubleToString() function because I only need to see two decimal numbers, is this correct? 

I realize that the NormalizeDouble() function does not round and "CUT" the value off as I was expecting.


Thanks for the help. 

Snelle Moda
602
Snelle Moda 2015.10.16 22:20  

Or I need to use both functions Like:

DoubleToString(NormalizeDouble(dPosition_Trend_RendementRatio,2), 2);

To add comments, please log in or register