You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
At lot of computation instead of the simple solution
I arrived at this solution which turns doubles into ints for the purpose of comparing doubles . . .
I, too, came up with a creative solution that has worked for me (so far) for comparing prices:
I upscale the price to an int that represents price as points expressed as a whole number. Thus:
can never be true.
Is CompareDoubles() from the stdlib.mq4 disqualified from this discussion? It works well for me if used for price.
A floating divide, floating addition, conversion to int, function call (copy, jump, return = 3,) * 2 all times two. (18) And that's assuming divide and convert are on par with the other operations - they are not.
vs
one subtraction, one test, 1/2 negate (on average,) and comparison. (3 1/2 if point/2 is done in init and ABS is replaced by an IF)
Don't over complicate things
if (a > b)
if (a >= b)
if (a != b)
A floating divide, floating addition, conversion to int, function call (copy, jump, return = 3,) * 2 all times two. (18) And that's assuming divide and convert are on par with the other operations - they are not.
vs
one subtraction, one test, 1/2 negate (on average,) and comparison. (3 1/2 if point/2 is done in init and ABS is replaced by an IF)
Don't over complicate things
2013.04.03 17:39:11 TestSpeed-CompareDbls USDJPY,M5: ConvertToPoints 9000000 times in 1887 ms.
2013.04.03 17:46:02 TestSpeed-CompareDbls USDJPY,M5: Flat(price) 9000000 times in 3604 ms.
"MathAbs(a-b)" method is approx 7 times faster than ConvertToPoints() method and almost 14 times faster than my "Flat()" method
2013.04.04 14:27:38 TestSpeed-CompareDbls EURUSD,H4: MathAbs(a - b) HalfAPoint 99999999 times in 3403 ms.
2013.04.04 14:27:42 TestSpeed-CompareDbls EURUSD,H4: (intRecord > intCheck) 99999999 times in 2505 ms.
But the 3-rd can't be practicably, and the 2-nd one (intRecord > intCheck) had 1 assignment more within for the intCheck before comparison.
I've tested (intRecord > price / point) and
2013.04.04 14:27:38 TestSpeed-CompareDbls EURUSD,H4: MathAbs(a - b) HalfAPoint 99999999 times in 3403 ms.
2013.04.04 14:27:42 TestSpeed-CompareDbls EURUSD,H4: (intRecord > intCheck) 99999999 times in 2505 ms.
But the 3-rd can't be practicably, and the 2-nd one (intRecord > intCheck) had 1 assignment more within for the intCheck before comparison.