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

Notification

Icon
Error

Options
Go to last post Go to first unread
Jose  
#1 Posted : Saturday, April 16, 2005 3:57:23 PM(UTC)
Jose

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/19/2005(UTC)
Posts: 1,065
Location: Koh Pha-Ngan, Earth

Was thanked: 2 time(s) in 2 post(s)
Here are some poor MetaStock coding practices worth avoiding: 1) MetaStock's PREV function slows down processing dramatically - its use should be avoided wherever possible. Placing unnecessary PREV functions in a formula generally reflects poor programming skills; 2) Rather than create a zillion formulae with different hard-coded parameters scattered inside a formula, assign these values to variables or user-inputs (in an easy-to-find code location) so that they may be easily changed as required; 3) Always use meaningful names for variables. Your code may need to be followed and understood by others, or worse still, Alzheimer's may just be around the corner; 4) Use {comments} wherever possible, for the same reasons as #3. Here is a recent example of MS code that ignores the above four points: [code:1:ee4a5480b7] ======================== 3% envelope 14 MA Expert ======================== ---8<-------------- Highlights tab: Long A:=C>1.03*Mov(C,14,S); B:=C<.97*Mov(C,14,S); D:=If(A,1,If(B,0,PREV)); D=1 Short A:=C>1.03*Mov(C,14,S); B:=C<.97*Mov(C,14,S); D:=If(A,1,If(B,0,PREV)); D=0 Symbol tab: Long A:=C>1.03*Mov(C,14,S); B:=C<.97*Mov(C,14,S); D:=If(A,1,If(B,0,PREV)); D=1 AND Ref(D,-1)=0 Short A:=C>1.03*Mov(C,14,S); B:=C<.97*Mov(C,14,S); D:=If(A,1,If(B,0,PREV)); D=0 AND Ref(D,-1)=1 ---8<-------------- [/code:1:ee4a5480b7] The code above is an example of poor coding in MetaStock, because: 1) Four (unnecessary) PREV function slows down the plotting of the Expert signals, and would dramatically slow down an exploration based on the same code; 2) There are no parameters assigned to global variables - it would take some effort to change all 16 values, and there is always the risk of introducing errors whilst doing so; 3) No meaningful names assigned to variables. Try following the code of some of the longer formulae, and the problem becomes apparent; 4) No {comments} used. The author may not need them, but others could do with some. The MS code below plots the same signals, and: 1) Avoids PREV functions; 2) Assigns values to global variables at the easy-to-get head of the formula; 3) Uses names for variables that reflect their intended use; 4) {Comments}, {Comments}, {Comments}. [code] =========================== 14 SMA / 3% envelope Expert =========================== Highlights tab: Long ---8<---------- { Variables } SMAperiods:=14; EnvPercent:=3; { Envelope signals } Env:=EnvPercent/100; upper:=C>(1+Env)*Mov(C,SMAperiods,S); lower:=C<(1-Env)*Mov(C,SMAperiods,S); { Trade binary flag } binary:=ValueWhen(1,upper-lower<>0,upper-lower); { Long trade flag } binary>0 ---8<---------- Short ---8<---------- { Variables } SMAperiods:=14; EnvPercent:=3; { Envelope signals } Env:=EnvPercent/100; upper:=C>(1+Env)*Mov(C,SMAperiods,S); lower:=C<(1-Env)*Mov(C,SMAperiods,S); { Trade binary flag } binary:=ValueWhen(1,upper-lower<>0,upper-lower); { Short trade flag } binary<0 ---8<---------- Symbols tab: Long ---8<---------- { Variables } SMAperiods:=14; EnvPercent:=3; { Envelope signals } Env:=EnvPercent/100; upper:=C>(1+Env)*Mov(C,SMAperiods,S); lower:=C<(1-Env)*Mov(C,SMAperiods,S); { Trade binary flag } binary:=ValueWhen(1,upper-lower<>0,upper-lower); { Long trade - first signal } long:=binary=1 AND Alert(bi
Patrick  
#2 Posted : Saturday, April 16, 2005 4:03:45 PM(UTC)
Patrick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/8/2004(UTC)
Posts: 2,266

Was thanked: 1 time(s) in 1 post(s)
Thank you for this great post. I will copy it to the Formulae and plug in section as well. I'm affraid it will get lost in the Formuale collection ... Patrick
skeetabomb  
#3 Posted : Thursday, April 28, 2005 5:31:17 PM(UTC)
skeetabomb

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 4/28/2005(UTC)
Posts: 41
Location: London

jose, Great post! A couple of things to add (for others reading this string!): 1. The PREV function I think only uses the LAST plot of a multiplot indicator. So when you're using it, you have to understand which PREV plot value you're after. This would be the same as when using the FML() function to look up another formula; can someone confirm this please? 2. 20 variables max per custom indicator is STILL not enough. Also, the character limit for a formula is also too small. I have had to use very short variable names (which are less 'meaningful') to fit my formula in. Yes, I know that the textbook recommendation is to split it into multiple formulae and use 'fml()', BUT this prevents me from using the 'input' function as I want to as the default value of 'input' is used when called by the fml(). Can it be unlimited? Or at least increased to, say, 128? (Yes, you read it right!) It only means more memory used on the PC. I have hit many of Metastocks limits in my formula writing and am frustrated. BUT, I have great faith in the development team! Or should I not?... Regards, skeetabomb. :?
Jose  
#4 Posted : Thursday, April 28, 2005 10:35:14 PM(UTC)
Jose

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/19/2005(UTC)
Posts: 1,065
Location: Koh Pha-Ngan, Earth

Was thanked: 2 time(s) in 2 post(s)
Skeet, the PREV & Fml() are very different functions. As for the 20-variable and 2.5Kb code space per formula, this could definitely be improved in MetaStock. In the meantime, variable names may be re-used several times within a MS formula. jose '-) http://www.metastocktools.com
skeetabomb  
#5 Posted : Friday, April 29, 2005 5:41:13 PM(UTC)
skeetabomb

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 4/28/2005(UTC)
Posts: 41
Location: London

Too true! Slight misunderstanding. What I was trying to point out was this: I am lead to believe that if I use the PREV function within a multiplot custom indicator, the value returned will be that of the last plot evaluated by Metastock at the previous bar. E.G. {name: "simple formula"} a:=5; b:=10; d:=PREV; x:=15; The value of variable 'd' above would be the value of variable 'x' at the pervious bar - which equates in this case to 'ref(x,-1)', as 'x' is the last plot to be calculated by Metastock. SIMILARLY, if I were calling my 'simple formula' function using Fml("simple formula") from within another custom formula, the value returned would also be 'yesterbars' variable 'x' result, as in the PREV example above. I hope others can comprehend this. Cheers, SteveD.
Patrick  
#6 Posted : Friday, April 29, 2005 5:44:04 PM(UTC)
Patrick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/8/2004(UTC)
Posts: 2,266

Was thanked: 1 time(s) in 1 post(s)
Steve, This is not true ... it depends on which version of Metastock You are using ... Forgot the details though ... I will have to test it again I guess. :mrgreen: Patrick
edwin4400  
#7 Posted : Sunday, June 26, 2005 5:10:23 AM(UTC)
edwin4400

Rank: Member

Groups: Registered, Registered Users
Joined: 6/22/2005(UTC)
Posts: 29
Location: Singapore

Hi, Anyone using or bought the metastock programming guide by David from this website http://www.meta-formula.com/vanced programmers. Does the guidebook also provide ideas of how to create a trading system? Thanks, Edwin
RUAGOODP  
#8 Posted : Sunday, June 26, 2005 6:19:55 AM(UTC)
RUAGOODP

Rank: Advanced Member

Groups: Registered, Registered Users, Unverified Users
Joined: 1/13/2005(UTC)
Posts: 87
Location: perth australia

I would be VERY wary of this site Edwin. Just my view. Maybe others can add input Cheers Norman
wabbit  
#9 Posted : Sunday, June 26, 2005 9:53:49 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)

Edwin....

Believe it or not - once you have paid for your copy of MS and data, there is no more to pay! Everything else you need to make MS work can be found in:

  • the Users Manual (comes with MS)
  • the Equis Formual Primer (download FREE from the Equis site, or Patrick has kindly added a link from this forum)
  • this forum, and many more like it, where you can ask questions and have people assist you (free of charge) to fix coding errors
  • your local public library, where they have books that you can borrow, learn from, takes notes and then return, free of charge!

There are some people that make their money from selling products to stock market newbies. Quite often they will also attempt to sell you a "system". I put it to you thus, if you had a system that worked, would you sell it?

There is one exception to the above: Roy Larsen produces the BEST information on exploiting MS to its fullest extent. His monthly newsletter is the only thing I subscibe to now. It is worth all of the $110 (or whatever it costs -I dont mind, it could be double and I would still get it!) I used to subscribe to all sorts of magazines, newsletters and shysters spam: its all crap! Roy's product is very good although, prbably not for the very very newbies, you have to know a little bit about MS first.

Read the users manual, work through the MS Formula Primer, go the library and ask questions in these free forums.... save your money for your first trade. When you have a win with this trade, buy yourself something nice instead of "yet-another-investment-book"

Hope this helps.

wabbit :D

viking4020  
#10 Posted : Tuesday, June 23, 2015 4:17:55 AM(UTC)
viking4020

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 10/16/2009(UTC)
Posts: 33
Location: Redcliffe, QLD Australia

Thanks: 4 times
Was thanked: 1 time(s) in 1 post(s)
David's programming guide is very good but no better than the Formula Primer which is free. I think k it is copied from the FP with enough changes to pass as their work.
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.