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

Notification

Icon
Error

Options
Go to last post Go to first unread
blackcat54  
#1 Posted : Thursday, April 1, 2010 3:53:05 PM(UTC)
blackcat54

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 3/23/2010(UTC)
Posts: 60

Is there a way to create a function like this?

if ("condition a" is true), then (plot "b")

b would be plotted only during the time period when "condition a" is true.

It is like a shortened version of the "if" function.

Could be called a "when function"

Thanks,

dlipter

Justin  
#2 Posted : Thursday, April 1, 2010 4:23:13 PM(UTC)
Justin

Rank: Advanced Member

Groups: Registered, Registered Users, Unverified Users
Joined: 9/13/2004(UTC)
Posts: 673
Location: Salt Lake City, UT

Amusingly there is actually already a When function although it is undocumented currently. However it doesn't work as you describe. Currently, MetaStock must always output an Else-type statement, as we must always plot something, even if it's a 0.

The When function is a shortened IF statement but does not let you specify an output...i.e.:

When(C>50)

Will output a 1 if true, a 0 if not true.
mstt  
#3 Posted : Thursday, April 1, 2010 4:45:56 PM(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 dlipter

It's not possible to turn a plot "off" while still retaining a valid plot before and after the N/A section(s). However there are ways to create that effect. The exact form such code would take would depend on what you were trying to do. Whether the switching signal was (or could be) scaled to price or some other plot would be one determining factor. Another factor would be the line style required. You can do thinbgs with dotted lines and histograms when solid or dashed lines would be quite unsuitable.

With regard to Justin's When() function, when one of two possible outputs is zero there's no need for either function. With Justin's example C>50 is all that's required. That would return a one or zero. Should the value required be other than one then using a multiplier provides a more concise expression in most cases - e.g. (C>50)*X. That expression will return zero or X.

Roy

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.