Ma comparisons

 

Good day everyone


Has anyone else noticed that MT4 code doesn't
always compare equivalent bars?

In the attached image showing 2 moving averages
crossing over (taken during the second half-hour
when the right hand bar was filling), the ma values
the code's comparing are picked out with arrows
and horizontal lines of the same colour as them.

The aqua curve is a 5 ma named 'faster' in the
code and on screen, the red curve is a 9 ma
named 'chanmed'.

Judging by the on-screen display of the variables'
values, if the rightmost, current, bar is bar 0,
and the two to its left are bars -1 & -2, then code
which defines 'now' as bar(i) and 'prev' as bar(i+1):

fasterMAnow = iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_MEDIAN, i);
fasterMAprev = iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_MEDIAN, i+1);

ChanMedMAnow = iMA(NULL, 0, ChanMedMA, 1, ChanMedMode, PRICE_MEDIAN, i);
ChanMedMAprev = iMA(NULL, 0, ChanMedMA, 1, ChanMedMode, PRICE_MEDIAN, i+1);

then does the comparison:
if ( (fasterMAnow > ChanMedMAnow) && (fasterMAprev < ChanMedMAprev) )
is actually doing:
if ( (fasterma@bar-1 > slowerma@bar-2 ) && (fasterma@bar-2 < slowerma@bar-3 ) )

I'm not sure of the implications of this - except
that it probably helps sift out crossovers in
cases where the ma's remain very close to each
other during a period. But it also allows a
period of play in which the two ma's can cross
over during the comparison period then cross back
again before the end of it.

Junja

Reason: