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 : Wednesday, April 14, 2010 3:09:42 PM(UTC)
blackcat54

Rank: Advanced Member

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

This code has 9 variables and one line for the plotting portion.

Is there any reason to eliminate the variables by folding them into the last line?

CenteredAvg:=Fml("+ag Avg 87");

DerivedAvg:=Fml("+ag Derived Avg 87");

Dif:=CenteredAvg-DerivedAvg;

Dif:=ExtFml("Forum20.Sum",Dif,1);

Defined:=IsDefined(CenteredAvg);

CenteredAvg:= ExtFml("Forum20.Sum",CenteredAvg,1);

RBC:=LastValue(Cum(1))-Cum(1)+1;

Adj:=ValueWhen(1,rbc=44,Dif);

Adj:=ExtFml("Forum20.Sum",Adj,1);

If(Defined,CenteredAvg,DerivedAvg+Adj)

Thank's

Dennis

wabbit  
#2 Posted : Wednesday, April 14, 2010 11:56:40 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)
If you only issue an instruction to MS without assigning it to a variable, then MS will plot the evaluated value. e.g. the codes below both produce the same result:

Code:

{example 1}
mov(c,10,s);
mov(c,20,s);


Code:

{example 2}
 x:=mov(c,10,s);


y:=mov(c,20,s);

{plot}
x;
y;



Code:

{example 3}
 x:=mov(c,10,s);



{plot}

x;

mov(c,20,s);





So when do you favour one method over another? The real difference comes when you need to call the value of the indicator using the Fml() function, or the value of the one of the variables using FmlVar() function.

In example 1, no variables are described, so you cannot use FmlVar(). Fml() will only return the value of the last item plotted i.e.the 20 period SMA.

In example 2, both MAs are assigned to variables so you can use FmlVar() to recover either value. Fml() will still only return the value of the last item plotted i.e. the value associated with variable 'y'.

In example 3, only one MA is assigned to variable so FmlVar() can be used to recover its value whilst Fml() can be used to recover the other value as it is the last item plotted.



wabbit [:D]

blackcat54  
#3 Posted : Thursday, April 15, 2010 12:08:23 AM(UTC)
blackcat54

Rank: Advanced Member

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

OK.....

I see your point Wabbit.

I was thinking from the standpoint of the effect on the processing speed of one way (with variables) vs the other (without variables). Is one way computationally more intensive, or does it use more resources to calculate or plot?

Dennis

wabbit  
#4 Posted : Thursday, April 15, 2010 12:33:42 AM(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)
I don't believe there is any significant effect on speed, although I have never absolutely tested for this; it's just an observation.


wabbit [:D]

mstt  
#5 Posted : Thursday, April 15, 2010 1:47:54 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 Dennis

There is a small cost in execution speed for every Fml() or FmlVar() you use - it's mininal but it's real. I'm probably biased but I believe that the longer a definition is the more likely it is to cause trouble. Using more than 10-12 nested If() funcions is asking for trouble and such an expression should to split into two variables if at all possible. For me long-winded definitions are clumsy, hard to read, hard to understand and even harder to troubleshoot.

For the moment I'd suggest you that you use up to the 20 variable-name limit that MetaStock allows and make each step the logical progression that it should be. Repeated expressions should be defined once and then called by name as often as needed. With time you'll develop your own style and then it won't really matter what others think.

Roy

blackcat54  
#6 Posted : Thursday, April 15, 2010 12:11:16 PM(UTC)
blackcat54

Rank: Advanced Member

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

One thing that I don't understand about the code from my original post is the need for the "Forum20.Sum" function. The period is not variable but the formula doesn't work with the "Sum" function. Also what's the difference between the Forum20 and Forum112 functions? They have the same names in the Paste Function list.

Dennis

mstt  
#7 Posted : Thursday, April 15, 2010 1:58:57 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 Dennis

In this instance the Forum DLL Sum function is being used purely to eliminate N/A results from the data array input to it. Any one of several Forum DLL functions could be used for this task. The standard IsDefined() MetaStock function is a half-baked implementation that is able to remove N/A results but converts the input data array to an almost useless TRUE or FALSE array while doing so. There are uses for the IsDefined() and IsUndefined() functions, but simply removing N/A without affecting other data in an array is not one of them. There are fully operational "IsDefined" functions (functions that remove N/A while keeping the original input intact) in a couple of MetaStock add-on DLLs, but these DLLs are not available to most MetaStock users.

Earlier versions of the "Forum" DLL had a slightly different collection of functions, and those functions were mostly named differently. For example, Mov in the current 188KB file was VarMov in earlier (and physically smaller) versions, and most other functions also had the longer function names. You can use the function button when working in the Formula window of the Indicator Builder to take a close look at the functions of any installed DLL. If both of your "Forum" DLLs are 188KB in size then they are identical copies of the same DLL regardless of the names they have. Physically smaller files will be older versions where some functions may be different (or non-existant in one version), and its functions will have different names.

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.