Although both MA lines are equal Orders where made

 
 

Try replacing

if ( line1 == line2 ) return ( 0 );

[/PHP]with

[PHP]if ( MathAbs( line1 - line2 ) < Point ) return ( 0 );

 
 

It has to do with "precision".

The double number representation is 64 bits, which makes it very high precision (though not mathematically exact).

Lines on the screen are limited by the screen resolution, which is of the order of 10 bits.

Obviously when plotting two double numbers onto the screen, you might need to put them on the same pixels even if the numbers are different.

As a rule of thumb, double numbers that are computed by different calculations very rarely end up equal, even when you think they should; very, very small differences (down to 20:th decimal or so), but enough for "==" to say false.

By your test, the lines were required to be equal to the highest precision offered by the representation, while by my suggestion, they are only required to be equal to a Point precision.

Perhaps you would really want "Point*Period/6" or something since the idea of MA lines "being equal" might also depend on the chart time frame; on an hourly time frame, perhaps being within 10 pips of each other is equal enough to be considered equal?