Digits problem for prices

 

Hello,

I actually encounter a problem with the iHigh and iLow functions. I would like to get the higher and lower prices of a predefined period.

Here you can see the code I made :


The problem is that returned prices have sometimes too much digits (underlined in red on the picture below), but I don't understand why and how to solve this problem.


I already tried NormalizeDouble function / to multiply by "10^(Digits)", round the value and divided by "10^(Digits)" / to change the variable type...

But any of these solutions is working (whereas when I multiply by 10^(Digits), the integer value is okay).


Please someone can help me !

And sorry for english faults, I'm french trying to do his best ^^


Florian

 
When printing doubles use DoubleToString()
 
I would use NormalizeDouble and as a rounder number use logarithm of digits on chart
 
Keith Watford:
When printing doubles use DoubleToString()

Your solution returns good results, but I can't make operations anymore due to the string type... And when I try StrToDouble() function, the problem appears again...

 
Florian Bernard Joseph Grossat:

Your solution returns good results, but I can't make operations anymore due to the string type... And when I try StrToDouble() function, the problem appears again...

You only use DoubleToString() when printing the value, not for any calculations.

Read the documentation for double including.

Real Types (double, float)

It should be remembered that real numbers are stored in memory with some limited accuracy in the binary system, while generally the decimal notation is used. That's why many numbers that are precisely represented in the decimal system can be written only as an infinite fraction in the binary system.

For example, numbers 0.3 and 0.7 are represented in the computer as infinite fractions, while the number of 0.25 is stored exactly, because it represents the power of two.

In this regard, it is strongly recommended not to compare two real numbers for equality, because such a comparison is not correct.



Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.
 
Keith Watford:

You only use DoubleToString() when printing the value, not for any calculations.

Read the documentation for double including.

Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.

Thanks for all, I just understood where the problem was coming !

Just have to move a little the price (1 or -1 pip) ^^

 
Florian Bernard Joseph Grossat:

Thanks for all, I just understood where the problem was coming !

Just have to move a little the price (1 or -1 pip) ^^

You obviously don't understand the problem (actually there is no problem)

https://www.mql5.com/en/forum/136997

Can price != price ?
Can price != price ?
  • 2011.12.08
  • www.mql5.com
I'm trying to understand something strange that I am seeing so I can better code round it in the future...