Array of MA crossing periods

#1
Hi, I am a beginner in programming with AFL and I am blocked
with the following problem :
I would like to know the previous cycle of bars since a MA crossing.
And establish an array with all those periods in the chart.

Exemple : EMA 20 and EMA 60 crossing.

The active cycle is easy :
EMA20 == EMA(C,20);
EMA60 == EMA(C,60);
X=Barssince(EMA20>EMA60);
Y=Barssince(EMA20<EMA60);

So I know always the actual period after the last crossing.
The other one is reset to 0

But I would like to keep the value of the previous one
and to get the array of all those periods in the chart.
How can I achieve this ?

Thanks for answers
 
#2
This is the code for getting the last period, but how to get all the previous too ?

_SECTION_BEGIN("TrendBars");
E20big = False;
EMA20 = EMA(C,20);
EMA60 = EMA(C,60);
ii=Barssince(EMA20<EMA60);
jj=Barssince(EMA20>EMA60);

EMA20 == EMA(C,20);
EMA60 == EMA(C,60);
E20big == IIf(EMA20 > EMA60,True,False);

if (E20big == True)
{
ii==Barssince(EMA20<EMA60);
jj==Barssince(EMA20>EMA60);
printf(EncodeColor( colorBlack ) + "| Prev Short Trend : " + jj + "," );
printf(EncodeColor( colorBlack ) + " Long Trend : " + ii + " | " );
}
else
{
ii==Barssince(EMA20<EMA60);
jj==Barssince(EMA20>EMA60);
printf(EncodeColor( colorBlack ) + "| Short Trend : " + jj + "," );
printf(EncodeColor( colorBlack ) + " Prev Long Trend : " + ii + " | " );
}
_SECTION_END();
 

Similar threads