- Ignore the char, short, float, etc unless you are dealing with passing a structure to some API
- Why are you concerned with 4 bytes?
- A Float has ~7 digits of accuracy. so a (5 digit broker's) JPY price has 100.001 has 6 digits. Do you really want to loose precision on price?
- a float will be cast to double and passed to DoubleToStr.
Ok, then I will forget about optimizing the code. My idea was to get more familiar with the new MQL4 and therefore I wanted my old indicators to be adapted to new MQL4. My girl-friend is learning Java at the university right now and we talked about different data types and how to cast them. That was the reason why I generally thought about optimizing my code. I didn't know that Float has ~7 digits of accuracy. So you are absolutely right not to use it.
Thanks!
Ok, then I will forget about optimizing the code. My idea was to get more familiar with the new MQL4 and therefore I wanted my old indicators to be adapted to new MQL4. My girl-friend is learning Java at the university right now and we talked about different data types and how to cast them. That was the reason why I generally thought about optimizing my code. I didn't know that Float has ~7 digits of accuracy. So you are absolutely right not to use it.
Thanks!
Even the Java developers have a saying "first make it working then optimize - if you still have time left" :)
Decimals have much higher precision and are usually used within financial applications that require a high degree of accuracy. Decimals are much slower (up to 20X times in some tests) than a double/float. Decimals and Floats/Doubles cannot be compared without a cast whereas Floats and Doubles can. Decimals also allow the encoding or trailing zeros.
Float - 7 digits (32 bit)
Double-15-16 digits (64 bit)
Decimal -28-29 significant digits (128 bit)
The main difference is Floats and Doubles are binary floating point types and a Decimal will store the value as a floating decimal point type. So Decimals have much higher precision and are usually used within monetary (financial) applications that require a high degree of accuracy. But in performance wise Decimals are slower than double and float types.
- net-informations.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey guys,
I try to optimize my indicators a little bit by implementing new MQL4 code. I have some general questions about data types. When I need a high or low of a bar, I used the data type double. But now I see that float uses only 4 bytes instead of 8 bytes used by double. When it comes to prices, can I just replace double with float? And what happens when I need to convert it into a string? Can I still use DoubleToStr, even when I use float?