Simple coding question - page 2

 
Or you can use a slightly higher/lower value for your check ... e.g. compare it with 3.5 pips as in (ma1-ma2)<0.00035 in order to catch cases where a difference of 0.0004 is represented as 0.00039999999 (which appears lower than 0.0004).

If I understand you correctly, I assume you want it to be true for less or equal 3 pips, so a check for lower than 3.5 pips will yield the right result with some leeway for misrepresentation of the figures.


Markus
 
Last comment: If you're running on JPY pairs, a pip will be 0.01. To take this into account the check could be coded as

if (.... && (ma1-ma2)< 3.5*Point) {

}



Markus
 
Or you can use a slightly higher/lower value for your check ... e.g. compare it with 3.5 pips as in (ma1-ma2)<0.00035 in order to catch cases where a difference of 0.0004 is represented as 0.00039999999 (which appears lower than 0.0004).

If I understand you correctly, I assume you want it to be true for less or equal 3 pips, so a check for lower than 3.5 pips will yield the right result with some leeway for misrepresentation of the figures.


Markus

You can use the following:
StrToDouble(DoubleToStr(ma1-ma2, 4))<0.0003
where (ma1-ma2) result will be rounded to 4 dec. points.
i.e. 0.00035 will be 0.0004
and 0.00034 will be 0.0003
 
@Sub.

The problem could be that if the string is converted back to double for comparism it may still have no precise representation in the double format and the problem may start all over.


Markus
 
ok, changing the value from 0.0004 to 0.00034 seems to solve the problem

gonna check other situations to see if it really works
 
well, on a quick eye inspection it really removed all the bad signals

strange thing it also removed one good signal where ma20 was 3 pips away from ma34

I adjusted the value so that that signal wouldn't be removed and I ended up with 0.00037 pips...
 
ok, using 0.00037 makes some of the bad signals return

final solution (I think!) is the code Shimodax provided and that returns only the correct signals:

int maval= 0,
ma20inpips= MathRound(ma20/Point),
ma100inpips= MathRound(ma100/Point),


if (ma20>=ma34 && (ma20inpips-ma100inpips<4))
maval= 1;
else
if (ma20<=ma34 && (ma100inpips-ma20inpips<4))
maval=-1;
else
maval= 0;

Thanks a lot everyone!!!! :-)
Reason: