NormalizeDouble() not working

To add comments, please log in or register
kumaillakhani
165
kumaillakhani  
StopLossBuy    = NormalizeDouble(Low[2] - 0.0003, Digits()); 	//1.1304799999999999
StopLossBuy    = NormalizeDouble(Low[2] - 0.0003, 5); 		//1.1304799999999999

I have tried both code from both code after decimal value appearing 16 digits. Where I have made mistake?

Petr Nosek
1532
Petr Nosek  
kumaillakhani:

I have tried both code from both code after decimal value appearing 16 digits. Where I have made mistake?

This is not your fault, it's a feature of double type. NormalizeDouble() provides rounding (BTW in a slightly non standard way) to required number of decimal places. But double is still double.
It could be dangerous to normalize prices (stop loss and take profit are also prices) by NormalizeDouble() because not always a tick size is equal to points.
Alain Verleyen
36617
Alain Verleyen  
Petr Nosek:
This is not your fault, it's a feature of double type. NormalizeDouble() provides rounding (BTW in a slightly non standard way) to required number of decimal places. But double is still double.
It could be dangerous to normalize prices (stop loss and take profit are also prices) by NormalizeDouble() because not always a tick size is equal to points.
Could you please provide a reference to the rounding standard(s) ? Thanks.
Carl Schreiber
Moderator
7282
Carl Schreiber  
May be you should read this here: http://articles.mql4.com/866
Working with Doubles in MQL4
Working with Doubles in MQL4
  • www.mql5.com
The MQL programming opens new opportunities for the automated trading, many people all over the world already have appreciated it. When we are writing an Expert Advisor for trading, we must be sure that it will work correctly. Many newbies often have some questions when the results of some mathematical calculations differ from those expected...
Petr Nosek
1532
Petr Nosek  
Alain Verleyen:
Could you please provide a reference to the rounding standard(s) ? Thanks.

https://physics.nist.gov/cuu/pdf/sp811.pdf

appendix B.7 on page 43

Alain Verleyen
36617
Alain Verleyen  
Petr Nosek:

https://physics.nist.gov/cuu/pdf/sp811.pdf

appendix B.7 on page 43

Thanks Petr.

However what I wanted to point is there is no reason to think Metaquotes is following any standard if not documented, certainly not a US standard.

Petr Nosek
1532
Petr Nosek  
Alain Verleyen:

Thanks Petr.

However what I wanted to point is there is no reason to think Metaquotes is following any standard if not documented, certainly not a US standard.

You're right that Metaquotes doesn't have to follow any standard (SI is not an US standard, but an international standard).
Alain Verleyen
36617
Alain Verleyen  
Petr Nosek:
You're right that Metaquotes doesn't have to follow any standard (SI is not an US standard, but an international standard).

NIST is US, it's what I meant.

US like to think they are the "international standard". But it's not the place to discuss about that.

To add comments, please log in or register