Decimal precision problem

My broker uses 5 decimal digits for EUR/USD, but the High and Close function in MQL4 will round it to nearest 4 digits. How can I preserve the 5 digits for High, Low, Open and Close functions? thanks

Check your code - particularly your use of DoubleToStr() and NormalizeDouble. They should use Digits for the precision field, not hard coded values like 4 or some local variable.

I see, that fixed the problem. But now I have to do this:


DoubleToStr(Open[1],Digits)

everytime I want to get the value of open, high, close and low, and those functions are scattered all over the place. Is there anyway to somehow set the decimal precision in the init function or someway to make the 5 decimal digit setting as global setting? thanks

You only have to use DoubleToStr in Print() or other display statements. Of course if you made a mistake in the past, you have more work to do now. Digits is the global setting for precision, don’t need to use something else.

how about in comparisons? will this line of code work (comparison is done with 5 decimal precision)?


if(DoubleToStr(Open[1],Digits)>DoubleToStr(Open[2],Digits))

thanks

You need to think about what you are doing. You are doing a string comparison of 2 floating point numbers. Does that make sense?

so, how do I compare two 5-decimal digit floating-point numbers? there are also part in my code that needs this. I need this because switching to broker that uses 5 decimal digits. oh wait, do I do this:


if(NormalizeDouble(Open[1],Digits)>NormalizeDouble(Open[2],Digits))

for comparison? thanks

Edit : Above syntax didn’t work. It still operates using 4 decimal digits

This thread is becoming a tutorial on programming and I’m not going to allow that, so this is my last post.

Floating point numbers should be compared as floating point numbers, not strings.

if(Open[1]>Open[2])