Another option.

If you toss a coin enough times you will end up with 50/50 heads 
tails.

The chance of tossing the second head is still 0.5.... this assumes 
independency.

You can use serial dependency formulas to calculate depenendency:

refer to google, RalphVince or Howard Bandy (I seem to recall that 
Howard gives some AFL code in his book Quantatative Trading Systems).

I use this quick and dirty method:

logic == of there is dependency the ratio of ups that follow the 
firstup will be > 0.5 probability


Filter = 1;

Up = Cum(Ref(ROC(C,1),-1) > 0);
SUp = Cum(Ref(ROC(C,1),-1) > 0 AND ROC(C,1) > 0);

AddColumn(Up,"Up",1,1);
AddColumn(SUp,"SecondUp",1,1);
//AddColumn(BarCount,"Count",1,1);
AddSummaryRows(1,1);

Plot(Up,"Up",1,1);

Plot(SUp,"SecondUp",1,1);


Also, since every streak (run) starts with a trend reversal you can 
count bars in trend by:

find the pivot that starts the trend
count barsince(pivot)

pivot = Ref(ROC(C,1),-1) < 0 and ROC(C,1) > 0;

Note: there are other definitions of a pivot but that is my preferred
      you can use Param functions to change the field.


--- In [email protected], "Soham" <soham...@...> wrote:
>
> Hi guys,
> 
> Although I am familiar with AFL but strangely finding myself not 
able
> to get my work done.
> 
> I am having a requirement to:
> 
> 1. Count the number of days,Close is above [or below] the bollinger 
band
> 2. And count the number of days for which it has trended in the same
> direction.
> 
> I would additionally love to see, a standard histogram of trending 
days.
> 
> Can you help me out?
> 
> 
> Soham
>


Reply via email to