[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AFL to count Number of Trues within a period



PureBytes Links

Trading Reference Links

hi mike,

try this , 

A=IIf(C>O,21,0);
b=MA(A,21);
Plot(b,"",4,4);



place your formula in A, you will need to use an iif function using 
the value of 21 as the true (as in the example above).
the reason is because of the 21 day MA of A, if there was only 1 day 
in the 21 days that was true then an MA of 21 days with the value of 
21 will be 1 when averaged. 

if not using iif try this ,


A=O>C;
AA=21*A;
b=MA(AA,21);
Plot(b,"",4,4); 

this will create a 21 day MA of the number of times it = 1.
for this example it counts the times the C>O. 

cheers: john.

in amibroker@xxxx, "miked33" <miked@xxxx> wrote:
> Can someone help me to write:
> 
> AFL to count the number of trues within a period. For instance a 
> variable A toggles between 1 and 0. I want to count the number of 
> times it toggles within 21 bars.
> 
> thanks