PureBytes Links
Trading Reference Links
|
wwflhp
> Can anyone tell me how I can generate a custom indicator using the
> indicator builder that is =0 before a specified date and =1 after that
> date, and compute the number of bars since that date? I presume that
> I have to use the LastValue and the ValueWhen functions, but I can't
> figure out how to do it.
> Also, how do I control what gets plotted and what doesn't?
> Also, when are semicolons required, and what do they do?
> Thanks, wwflhp
Let's start with the simplest question first. A semicolon terminates the definition of a variable.
It's good practice (IMHO) to terminate result plots, unnamed variables, and indicators with a
semicolon too. This is not mandatory, but it makes life much simpler when copying an pasting to
create new formulas, particularly when copying from text files outside of MetaStock. The use of
optional semicolons at the end of formulas saves many hassles for the poor sucker trying to copy
your work.
Variables do not need to be placed on separate lines, and neither do they need an intervening space
character. The semicolon is all that's needed to indicate the end of a variable.
At last count there were seventeen or more ways to plot a zero before a given date and a one after
it. Most of them are simpler than the indicator formula I'm about to give you, and once you've been
through the Formula Language section of the manual a couple of times you'll suddenly find functions
that look useful. Check them out. The "Date Filter" is very useful, and to get it to hold a one
after the start date just make sure the defaults for the end date are set to some date in the
future.
{Date Filter}
{2003 Roy Larsen, rlarsen@xxxxxxxxxxxxxx}
Sd:=Input("Start day" ,1,31,1);
Sm:=Input("Start month",1,12,1);
Sy:=Input("Start year" ,1980,2010,2004);
Ed:=Input("End day" ,1,31,31);
Em:=Input("End month" ,1,12,12);
Ey:=Input("End year" ,1980,2010,2004);
Start:=(DayOfMonth()>=Sd AND Month()=Sm AND
Year()=Sy) OR Year()>Sy OR (Year()=Sy AND
Month()>Sm);
End:=(DayOfMonth()<=Ed AND Month()=Em AND
Year()=Ey) OR Year()<Ey OR (Year()=Ey AND
Month()<Em);
Filter:=Start AND (End OR (Start AND Alert(Start=0,2)));
Filter;
As I said, there are many easier ways to do it, but all of them are less versatile.
Forget LastValue(). It has many uses, but I don't think this whole situation is one of them.
BarsSince(FmlVar("Date Filter")=0); should tell you how many bars since it went true. I'm not going
to count but I suggest you do. There's a real possibility that my suggestion will be off by one in
the count. There are other ways to count bars or events, and I'll cover one of them in the next
newsletter. You can adjust my suggested formula by one by changing it to..
BarsSince(Ref(FmlVar("Date Filter"),-1)=0); As always in MetaStock there are several ways to
achieve the desired objective. They do exist, even if you can't figure them out.
The ValueWhen() function is particularly good for two things. One is for creating a long N/A
(invalid) plot when you DON'T want it. The other is for creating a long invalid plot when you DO
want it. (I'm jesting, it has many other uses too) It will not plot a result until the "trigger"
expression first comes true. Therefore, to inhibit a plot, any plot, all you need to do is feed it
to a ValueWhen() function and make sure your trigger expression stays false (zero) until the plot is
needed - ValueWhen(1, "trigger", "controlled plot" ). Simple really. Use Fml("Date Filter") (or
Fml("Date Filter")=TRUE if you prefer) as your trigger.
I hope this helps some.
Roy Larsen
www.metastocktips.co.nz
Free formulas and MS links
------------------------ Yahoo! Groups Sponsor --------------------~-->
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/BefplB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/equismetastock/
<*> To unsubscribe from this group, send an email to:
equismetastock-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|