Advanced topic: if you had the choice, what data type would you choose to work with currency rates ?
Based on my experience, especially in the old days, high-quality applications used Binary Coded Decimal (BCD) for financial and accounting data. The main advantage was that the number always had a true decimal representation and the number of digits could be set to a fixed number of digits. There are however other modern options besides BCD, that still maintain this kind of functionality, which is especially needed for financial data.
In the case of MetaTrader and it's Quote data, I would have designed it, using "ticks" (quote, not count) saved as Integer format, given that the "tick size" is already part of the symbol's contract specifications. This would allow all the raw quote data to be handled without any need for conversion, and could easily converted to floating point when equations such as moving averages need to be applied.
I would have also designed MQL trade functions to ALL work with "ticks" (in Integer format) and not in quote prices as "doubles".
EDIT: As for the volume (lots), I would have also designed it based on "lot step" and save as Integer and not "double".
EDIT2: One more advantage of using "ticks" and "lot step" would be the prevention of the annoying runtime errors that "newbie" codes get, when price and volume are not properly aligned.- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
In MQL double data type is used to represent currency rates, as well as for all data needing some decimals.
It has some advantages :
And drawbacks :
If you had to design it, would you still use double or an alternative ? And why ?
Personally I would keep double internally, but I would hide it, as an implementation detail, behind a "rate" type (or whatever the name). And I would provide a clean and simple interface, easily understandable and usable, even by amateur coders. So I would keep the advantages and "hide" the drawbacks.