Better coding in metastock

oxusmorouz

Well-Known Member
#1
Most people who start off with metastock language tend to clutter their indicators and experts which make them really difficult to alter.
A good example would be a ,say, MACD crossover (I use MACD as an example here because most would be familier with it).

This is how beginners code their system: (you will know how hectic it is to understand)
Indicator:
(Mov(C,12,E)-Mov(C,26,E));
Mov(Mov(C,12,E)-Mov(C,26,E),9,E);
0

Expert:
Buy symbol:
Cross((Mov(C,12,E)-Mov(C,26,E)),Mov(Mov(C,12,E)-Mov(C,26,E),9,E));

Sell symbol:
Cross(Mov(Mov(C,12,E)-Mov(C,26,E),9,E),Mov(C,12,E)-Mov(C,26,E));

At this point, it would take a great deal of effort to:
---> Understand what was coded
---> Make others understand what was coded
---> Make changes in the MACD days
---> Add an additional condition in the formula

I'm a beginner in metastock myself but I have found some coding techniques which were of great help to me when I coded my formulas.

Indicator:
{ Time Periods }
FastPds:= Input("Fast MA",1,200,12);
SlowPds:= Input("Slow MA",1,200,26);
Signal:= Input("Signal",1,200,9);

{ Inputs }
a:= Mov(C,FastPds,E);
b:= Mov(C,SlowPds,E);
d:= a-b;

{ Condition }
d;
Mov(d,Signal,E);
0

x----------x

Expert --> Symbols

Buy:
a:= Mov(C,12,E);
b:= Mov(C,26,E);
d:= a-b
f:= Mov(d,9,E);

Cross(d,f);


Sell:
a:= Mov(C,12,E);
b:= Mov(C,26,E);
d:= a-b;
f:= Mov(d,9,E);

Cross(f,d);

x-----------x

Though the 2nd one may seem difficult to understand in the beginning, you would notice the relative ease of writing a formula once you get a hang of it. The chances of making formula errors are relatively less. Also it provides ease in changing the time periods and adding another, even, 100 conditions (if metastock permits).
Good luck.

Oxymoron.

(Special thanks to Mr.Jose Silva www.metastocktools.com from whose formulas I have learnt a lot of coding techniques)
 

Similar threads