logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
WmWaster  
#1 Posted : Tuesday, May 16, 2006 4:57:21 PM(UTC)
WmWaster

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 3/20/2006(UTC)
Posts: 53

How to create a counter? Hi. I would like to create a counter. For a specific period (eg 30days), it tries to compare each day with its previous one. For example, first it tries to compare today's close with yesterday one. If it's clearly lower than the yesterday one, it minuses 1 to the indicator. Then it moves to yesterday. It tries to compare yesterday's with day before yesterday's. If it's clearly lower than the yesterday one, it minuses another 1 to the indicator (so the value of the indicator becomes -2 now). The process keeps going until it reaches the specific period. How to do? Thanks for your help. :)
wabbit  
#2 Posted : Tuesday, May 16, 2006 11:10:57 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
Have a look in the MS Users Manual for the Sum() and Cum() functions. Sum() adds values over a specified number of bars, say 30; Cum() adds values over the entire valid range. If you have any trouble implementing these in your solution, please post your best effort at the code and we will correct it for you. wabbit :D
mstt  
#3 Posted : Wednesday, May 17, 2006 2:09:40 AM(UTC)
mstt

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
Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.