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
WHRoeder: this code good (especially check "added" and "default")? It may also serve as an easy final-reference for those who visit this thread and just go the last page (as I did)
That code is not accurate.
How can if( !MathAbs( a - b ) > Point/2) be used to compare for equality? That would tell you 1.4999 == 1.5000
if( ! (MathAbs(1.4999 - 1.5000 > 0.00005 )
if( ! (0.0001 > 0.00005 )
if( ! (true )
if( false ) 1.4999 is NOT equal to 1.5000
I use
or for doubles that arn't actual prices, a higher precision
Raptors post about this code
So if you use,
I have tested that method in a variety of ways I have not found a scenario where it would not return the expected or desired result.Final code... Thanks WHRoeder
And, maybe a secondary function for comparing all other doubles that are not prices...
See also 'MQL4 Reference > Language Basics > Data Types > Real Types (double, float)' in regards using small number for comparision.
Maybe someone knows how to write 0.00...1 better in expon
So there is something else interesting I found, potentially in connection with "// 0 compare doesn't need this function".
Maybe a bug only in the latest versions, not sure. Comparing with 0 no longer functions correctly. I had to resort to something unfriendly like;
outcome=(int(outcome*100)/100.0); // Resolution 2 digits
Just to ensure that 0 values actually ended up as 0 values.
WHRoeder, thanks. More study needed :)
I think this topic is dealt with too much unnecessary complexity.
Try to make your programmer's life always as easy as possible. Write defines (or go ahead with methods if you really must) in those classes where you need your double comparisons:
When you need to compare two doubles then use it in a condition like this:
If you want to see if a double is zero (or very, very close to zero) use a condition like this:
On a side note, since I see many posts talking about divisions:
With encapsulation we tend to forget about the costs of code that is "outsourced" to some utility methods. Remind yourself that divisions are computationally very expensive! Especially, once wrapped in nice utility methods somewhere in utility classes, we start to use them everywhere in indicators or EAs and have long forgotten what computational steps they perform. When using the strategy tester we pay a lot of unnecessary time for our sloppiness.
Rule of thumb: Additions and subtractions are much much faster than multiplications and divisions. The division operation takes the highest computation time. Optimize divisions - wherever possible! If the denominator is fix like in this loop...
then replace the denominator x with its inverted value 1/x:
Also, if the result of a division is always the same, then do the computation once and save the result in a variable so you can use it everywhere in your code (e.g. in loops):
Cheers,
A.T.