Hi all,

There were so many questions regarding using previous value and I whittled through all of them and I am not sure what I am missing I am still not able to get the formula to work.

Essentially I am trying to create Ehler's Cyclic Component formula into AFL.

which is as below

Period - calculation period;

Applied price - price used for calculations.

Cyclic Component [i] = (HP[i] + 2*HP[i-1] + 2*HP[i-2] + HP[i-3])/6,

where

HP[i] = (Price[i] - Price[i-1])*(1 + Alpha)/2 + 2*Alpha*HP[i-1],
Alpha = (1 - sin(2*Pi/Period))/cos(2*Pi/Period)

In the calculation of HP I see the previous value of HP is referenced there so I used For loop to do this but the result is not as expected. I tried various corrections to the formula and even tried using some of the formulas which were used in other threads to recreate it but I am still struggling. Much appreciate if you could take a look for me.

```
Period = 20;
pi = 3.141592653589793238;
Price = C;
Alpha = (1 - sin(2*pi/Period))/cos(2*pi/Period);
HP = 0;
for( i = 3; i < BarCount; i++ )
{
HP[i] = (Price[i] - Price[i-1])*(1 + Alpha)/2 + 2*Alpha*HP[ i - 1 ];
CyclicComponent [i] = (HP[i] + 2*HP[i-1] + 2*HP[i-2] + HP[i-3])/6;
}
Plot(CyclicComponent,"CC",colorWhite,styleLine);
```

Using filters I figured out that the issue lies in

```
2*Alpha*HP[ i - 1 ]
```

But don't know how to solved it.

Appreciate if you could help