Formula Language Course · Lesson 4 of 9
Beyond the mathematical operators sit more than 200 pre-programmed functions. Learn what they are, what feeds them, and how to read their syntax at a glance.
In addition to the mathematical operators, MetaStock ships with over 200 pre-programmed functions to give your coding versatility. The bulk of these fall into three categories: analysis tools, indicators and candlesticks. Over the coming lessons we will look at the more commonly used functions, with explanations and applications for each.
Before we begin, we must explain what function parameters are and where they are used. A function is a set of predefined mathematical operations that MetaStock follows; a parameter provides a function with the information it needs to calculate those operations. Some functions need no parameters; others need several.
Let's look at a couple of examples.
ATR(14)
This formula calculates a 14-period Average True Range. The only parameter required
is the number of periods, 14. The ATR syntax is
ATR(Periods), and we put it to work in the
Average True Range tutorial.
Mov(C,7,S)
This formula plots a 7-period simple moving average. The parameters are the data
array (C), the periods (7) and the moving
average type constant (S). Notice that when a function has
multiple parameters, each parameter is separated by commas. The moving average
syntax is Mov(Data Array, Periods, Constant), and it appears
again and again through the rest of the course.
That last example introduces the idea that there are different types of parameters. Some are specific to a particular function; others are near universal. The two most universal are the price data array, which you already know from Lesson 1, and the periods parameter.
Periods refers to a single value, a numeric constant, that determines the time
period of a function. The periods parameter is the 7 in
Mov(C,7,S): it makes the moving average a seven-period average.
The less common parameters will be explained as they arise in their respective
functions.
With 200-plus functions available, the real power comes from combining them. In Lesson 5 we learn to nest one function inside another, and meet the Alert function.
Everything in these lessons works in the free 30-day MetaStock trial: full software, live data, your own watchlist.
Start Your Free 30-Day Trial →30-DAY TRIAL · FULL VERSION · CANCEL ANYTIME · AFFILIATE LINK, SAME PRICE FOR YOU
The Formula Language Course: Course home · 1. First formulas · 2. Operators · 3. Precedence & periodicity · 4. Built-in functions · 5. Nesting · 6. Variables · 7. Comments · 8. Pasting functions · 9. Exercises