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?
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.
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.