the prevtime variable must be staitc
example:
to find the bar position of the latest C cross up the ma
int barsSince() {
int bars=Bars;
static datetime prevtime=0;
if( prevtime == Time[0]) return(0);
prevtime = Time[0];
for (i=0,i<bars,i++) {
ci=Close[i];
c1i=Close[1+i];
mai=iMA(....,i);
ma1i=iMA(....,1+i);
bool cXmaUp=ci>mai && c1i<ma1i;
if (cXmaUp) {
int barPos=i;
break;
}
}
if (barPos<bars) return(barPos);
else return(-1);
}
to call this function you will get the latest bar position of c cross up ma.
suffic369
www.wsforex.com