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

Re: Function Wish List



PureBytes Links

Trading Reference Links

Frank - 

I've wanted to do the same thing - count occurances of something. 
There is a solution too.

Here's what I do to accomplish counting:

AVG = MA (Close, 21); /* a moving average for example */
Per = 185;	

/* Get closes that are over and under AVG */
CloseOver = IIF ( Close > AVG, Close, 0);
CloseUnder = IIF ( Close < AVG, Close, 0);

/* Count closes over and under */
CountUp = SUM ( IIF ( Close > AVG, 1, 0), PER);
CountLo = SUM ( IIF ( Close < AVG, 1, 0), PER);

Pretty clever if I do say so for a non programmer type.

Brett


--- In amibroker@xxxx, fesnay@xxxx wrote:
> Tj,
> In a ranking system that I am building, I have a need to count the 
> number of times something happens within the past "X" number of 
> days. For example, suppose I want to count the number of times in 
> the most recent 50 days that the close was higher than the previous 
> days'. The only way I can accomplish this in the current AFL is 
via 
> multiple iif() statements, one for each day. Not difficult if only 
a 
> couple of days of testing is needed, but cumbersome for a year of 
> data!
> Any suggestions? Possible example:
> A count function, ie, count(condition, # of days back from end of 
> data)
> or count(condition, starting # back, ending # back) with ending # 
> back defaulting to end of current data unless specified elsewise.
> 
> Thanks, 
> Frank