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

Notification

Icon
Error

Options
Go to last post Go to first unread
TimX  
#1 Posted : Tuesday, March 19, 2013 8:20:00 PM(UTC)
TimX

Rank: Member

Groups: Registered, Registered Users
Joined: 10/26/2012(UTC)
Posts: 19


Hi, how can I get the first non-zero value of a an indicator?

I have a signal that is usually 0 but spikes occasionally when conditions are met.

I want to compare later values with the first value, but in general I don't know when that first value was.

There must be some neat trick to do this in the MS language, right?

Thanks all, Tim
mstt  
#2 Posted : Wednesday, March 20, 2013 2:28:33 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)
Hi Tim

ValueWhen(1, Cum(Signal<>0)=1, Signal);

or if you want to prevent the leading N/A result that this expression will generate then try

ValueWhen(1, Cum(IsDefined(Signal))=1 OR Cum(Signal<>0)=1, Signal);

where "Signal" is the variable or indicator that you want to monitor. I think my syntax is correct but I haven't run the code in MetaStock to pick up any typo's.

Roy


TimX  
#3 Posted : Wednesday, March 20, 2013 3:27:30 AM(UTC)
TimX

Rank: Member

Groups: Registered, Registered Users
Joined: 10/26/2012(UTC)
Posts: 19


Exactly what I needed (I used the second version to avoid any N/A issues).

Thanks for your quick and expert help, cheers, Tim
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.