Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 7/25/2005(UTC) Posts: 1,042
Was thanked: 57 time(s) in 54 post(s)
|
Wm
Here's a counter that may or may not be able to be adapted to your particular use. It may be that you are actually looking for a loop function. That's something else which requires a little improvisation. The second formula is a PREV version of Ehlers DC Filter, and the third formula is a non-PREV "simulated loop" version of Ehlers DCF. This might give you some more ideas on how to attack your problem.
{Signal Counter}
{© 2003-2006 Roy Larsen}
{www.metastocktips.co.nz}
D:=Input("Count: 0=Leading Edge, 1=Bars",0,1,1);
B:=Mov(C,10,S)>Mov(C,50,S); {sample reset signal}
A:=B=0 AND C>Ref(HHV(C,10),-1); {sample count signal}
I:=Cum(A+B>-1)=1; {signals valid}
X:=Cum(A); {bar count}
A:=If(D,A,A*Alert(A=0,2));
{count leading edges or bars?}
F:=BarsSince(I+A)<BarsSince(I+B); {window}
X-ValueWhen(1,I OR F=0,X);
{Ehlers DC Filter}
ti:=Input("periods",2,27,27);
pr:=MP();
coef:=Sum(Power(Ref(LastValue(pr+PREV-PREV)-pr,-1),2),ti);
x:=Sum(coef*pr,ti)/If(Sum(coef,ti)=0,1,Sum(coef,ti));
x;
{Ehlers DC Filter (Non-PREV}
n:=Input("Periods",2,27,27);
pr:=MP();
coef:=Ref(Pwr(pr-Ref(pr,-1),2)+
(n>2)*Pwr(pr-Ref(pr,-2),2)+
(n>3)*Pwr(pr-Ref(pr,-3),2)+
(n>4)*Pwr(pr-Ref(pr,-4),2)+
(n>5)*Pwr(pr-Ref(pr,-5),2)+
(n>6)*Pwr(pr-Ref(pr,-6),2)+
(n>7)*Pwr(pr-Ref(pr,-7),2)+
(n>8)*Pwr(pr-Ref(pr,-8),2)+
(n>9)*Pwr(pr-Ref(pr,-9),2)+
(n>10)*Pwr(pr-Ref(pr,-10),2)+
(n>11)*Pwr(pr-Ref(pr,-11),2)+
(n>12)*Pwr(pr-Ref(pr,-12),2)+
(n>13)*Pwr(pr-Ref(pr,-13),2)+
(n>14)*Pwr(pr-Ref(pr,-14),2)+
(n>15)*Pwr(pr-Ref(pr,-15),2)+
(n>16)*Pwr(pr-Ref(pr,-16),2)+
(n>17)*Pwr(pr-Ref(pr,-17),2)+
(n>18)*Pwr(pr-Ref(pr,-18),2)+
(n>19)*Pwr(pr-Ref(pr,-19),2)+
(n>20)*Pwr(pr-Ref(pr,-20),2)+
(n>21)*Pwr(pr-Ref(pr,-21),2)+
(n>22)*Pwr(pr-Ref(pr,-22),2)+
(n>23)*Pwr(pr-Ref(pr,-23),2)+
(n>24)*Pwr(pr-Ref(pr,-24),2)+
(n>25)*Pwr(pr-Ref(pr,-25),2)+
(n>26)*Pwr(pr-Ref(pr,-26),2),-1);
x:=Sum(coef*pr,n)/If(Sum(coef,n)=0,1,Sum(coef,n));
x;
Roy
MetaStock Tips & Tools
|