Yeah man.... Converting to Int works wonders. I had this code thing which seemed stupid but after awhile I'm realizing how nice it is.
if(StringFind(Symbol(),"JPY")>-1){int _2Real=100;}else{_2Real=10000;}
Changes any Price on any Digit broker to Integer_Pips. And then get used to working in Integer Pips.
converting them to int is not very accurate because the doubles are rounded up or down in the first decimal place.
converting them to int is not very accurate because the doubles are rounded up or down in the first decimal place.
converting them to int is not very accurate because the doubles are rounded up or down in the first decimal place.
converting them to int is not very accurate because the doubles are rounded up or down in the first decimal place.
There is need for conversion to ints for arrays indexes and exact comparison in many(more) cases, exact double search is paradox on more decimals (endless), ie. exact return can't be done with doubles (+- is not nN dna).
Hm,
in order to be fast and slim I made this:
#define _EQ 0 // equal #define _NE 1 // not equal #define _GE 2 // greater or equal #define _GT 3 // greater than #define _LE 4 // less or equal #define _LS 5 // lesss than #define _ZERO 0.0000001 // usage: if ( dC( a, _EQ, b ) ) { ... bool dC(double d1, int comp, double d2){ switch (comp){ case _EQ: retrun( MathAbs(a-b) < _ZERO ); case _NE: return( MathAbs(a-b) > _ZERO ); case _GE: return( (a-b) > -_ZERO ); case _GT: return( (a-b) > _ZERO ); case _LE: return( (b-a) > -_ZERO ); case _LS: return( (b-a) > _ZERO ); default: return(false); } }
I guess / hope it'l do it and its faster than the others. Am I right?
Thanks, Gooly
case _EQ: if ( MathAbs(d1-d2) < _ZERO ) return(true); else return(false);
return(true) else return(false) is unnecessarycase _EQ: return( MathAbs(d1-d2) < _ZERO );
- Your zero may generally work for prices (but not for indicator values.) The double value from the broker could be anywhere from
1.234575000000000000 through 1.23458499999999999 and still be considered
the same 1.23458 price. This is why I used Point/2 for prices. For a 0-100 indicator I'd define epsilon as 1/100 * 10%
- Why use the overhead of a function call instead of a plain readable IF.
- Also remember, these cases are only necessary when the equal/not-equal case is important in the presence of roundoff. Your original question was if(aDouble < 0) Do you really care if the calculation was essentially zero but rounded down to negative? Do you really want the IF to function randomly near zero? Shouldn't the code be if(aDouble < -0.0001) .. else if (aDouble > 0.0001) .. such as when the aDouble is a slope (e.i. pips/bar.)
I changed my code acc. to 1.) - you were right!
2.hmm. If you calc (smallets pip-size I know) 0.00001*0.00001 you get 0.0000000001. It may be use full to reduce _ZERO
3. This I don't understand, what do you mean? IF will not be a function or just
bool IF(double a, int c, double b) { ... }
Then you will have
if( IF(x,_EQ, y)){ .. }
4. You are right, my guess was that there is a signature bit to be check, but an calculation result of - 0.0000000000001 would be negative and not 0.0, if that is important!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have read avout the problems of CompareDoubles.
But would it be safe (and faster) NOT to use the coorect way: if( NoramlizeDouble(doubleValue,8)<0.0) ... if I only check the sign:
Thanks in advance,
Carl