Do not assume - you must test.
Which is faster - Floating-Point or Integer arithmetic? - Expert Advisors and Automated Trading - MQL5 programming forum - Page 11
hey again guys. can we store our price information in float type instead of double?
we need maximum 5 decimal for price. and its faster in huge calculations.
is there any problems with using that for EAs with lots of variables?
For example if multiply two 5-digits prices, the result needs at least 10 digits of precision. (1.12345 * 1.12345 = 1.2621399025).
void OnStart() { double d = 1.12345 * 1.12345; float f = 1.12345 * 1.12345; Print("d = ", d); Print("f = ", f); } //--- output // d = 1.2621399025 // f = 1.26214
In some cases for heavy calculation, better to convert to int. So, normalize to int. Do the calculation, de-normalize to double.
Keeping it aligned to SYMBOL_MODE_TICK_SIZE will ensure your prices are always right.
In some cases for heavy calculation, better to convert to int. So, normalize to int. Do the calculation, de-normalize to double.
Keeping it aligned to SYMBOL_MODE_TICK_SIZE will ensure your prices are always right.
There are two concerns against that approach:
1. The large overhead in conversion between integer and double types will cancel the possible benefits.
2. Calculations involving integer division are normally truncated, and that will lead to loss of precision.
(for example, to calculate the simple moving average we divide the sum of prices by the ma_period).
FYI, floating-point calculations are done by the math co-processor (FPU). Their speeds have enormously improved over the last few years. Now, FP calculations are assumed to be as fast as (or even faster than) integer calculations.
- 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 again guys. can we store our price information in float type instead of double?
we need maximum 5 decimal for price. and its faster in huge calculations.
is there any problems with using that for EAs with lots of variables?