How do I create a loop/function/anything that'll check the amount of bars that have happened since a certain period?

 

It's for an Ea.

For example I want the EA to count the amount of bars(starting from 0) that appeared since an MA crossover.

I just don't understand the logic that will 'BarsSinceMACrossover++' every new bar. - Regards

 
Balloooon:

It's for an Ea.

For example I want the EA to count the amount of bars(starting from 0) that appeared since an MA crossover.

I just don't understand the logic that will 'BarsSinceMACrossover++' every new bar. - Regards

Pseudo code:

while MA crossover not found yet

did MA crossover happen on this bar shift ? if yes exit while loop

increment the shift count


MA crossover happened at shift bar number.
 

while MA crossover not found yet

did MA crossover happen on this bar shift ? if yes exit while loop

increment the shift count

MA crossover happened at shift bar number.
for(int BarsSinceMACrossover = 0; BarsSinceMACrossover < Bars; BarsSinceMACrossover++){
   double maFastCur = iMA(NULL,0, Fast, ... BarsSinceMACrossover),
          maFastPre = iMA(NULL,0, Fast, ... BarsSinceMACrossover + 1),
          maSlowCur = iMA(NULL,0, Slow, ... BarsSinceMACrossover),
          maSlowPre = iMA(NULL,0, Slow, ... BarsSinceMACrossover + 1);
    bool  wasAbove = maFastPre > maSlowPre,
           isAbove = maFastCur > maSlowCur;
    if(isAbove != wasAbove) break; // Crossed at BarsSinceMACrossover
}
if(BarsSinceMACrossover == Bars) ... // None (tester?)