Meta Stock Download

Pre-Programmed Functions – Discover Nesting Functions

Learn to 'nest' functions.

How good are you when it comes to pre-programmed functions? You are now reading the continuation of our series on the basics of MetaStock Programming Language and Metastock tips. In this post we are going to go through nesting functions and alert functions that any Metastock Expert should know.

With so many functions available within MetaStock it’s important to note that functions can be ‘nested’ within a function. That is, a nested function can act as another function’s data array parameter. For example, assume you wanted to code the moving average of another moving average. This would be done as follows:

Mov( Mov( C, 5, W), 20, W)

We’ll see nesting functions applie later, so now let’s now look at one of the first major function categories, ‘Analysis Tools’. Most of the functions in this category return specific values from a data array. For example, they could return anything from the number of bars since a condition occurred, to the highest value in a data array.

ALERT

The first function we will look at is the Alert function. It’s used in conjunction with other functions to extend a signal for a specified number of periods.  In other words, it holds an expression as true for as long as we wish.

Now think about the alert function with gates and triggers in mind. Using this function we can hold a gate open for a specific period while waiting for a confirming trigger. This provides a vital ingredient to creating a fully auto- mated system. However, before we get ahead of ourselves, let’s have a closer look at the Alert function’s syntax. That is, the way in which it’s coded into MetaStock.

SYNTAX   Alert(Expression, Periods)

Expression – The technical condition that you are wishing to hold true. This is usually your gate.

Periods – The length of time that you wish to hold the expression as true.

EXAMPLE                                                                                                                                                    

Let’s see this function in action. The formula below identifies stocks that have had their volume 50% greater than the 21 period moving average of volume. This indicates that the interest within the stock has increased. More- over, by using the Alert function we have extended the period that this condition exists from one period to five. That is to say, we have told MetaStock that for all intents and purposes the increase in volume on the initial period would provide the same signal for the following five periods.

Alert(V > Mov(V,21,S)*1.5,5)

The above formula can be broken down as follows: Expression = V > mov(v,21,S)*1.5

Periods = 5

APPLICATION

We can add to this example, showing a more useful application. Mov(C,5,S)> Mov(C,22,S) AND

Alert(V > Mov(V,21,S)*1.5,5)

This formula identifies securities that are in an uptrend (denoted by the 5 period simple moving average being greater than the 22 period simple moving average). Additionally, securities must exhibit a 50% increase in their average volume at least once within the previous five periods. If we were to remove the alert function, both conditions (i.e., ‘V > Mov(V,21,S)*1.5’ and the ‘Mov(C,5,S)> Mov(C,22,S)’ would have to be true simulta- neously. This may not appear useful, however when combined with other functions (e.g. the cross function on page 41) you realise its power.

Guide

Alert Indicator

(Please note that the 5 and 22 period simple moving averages shown on the chart above is not part of this indicator. They have simply been placed on the chart to confirm the analysis shown by the indicator.)

EXERCISES

Throughout these function pages there will be plenty of exercises to practice what we’ve learnt. Although these can be easily skipped, they provide a good foundation to your understanding of MetaStock. We like to think of them as a way of gradually building up your ‘MetaSpeak’ vocabulary. Now it’s your turn to try and construct formulas for the following:

1.      Keep the expression ‘Cross(RSI(14),30)’ true for 13 periods.

2.      Specify that the volume must be greater than 50000 at any time over the previous five periods.

Do you want to learn how to use MetaStock formula like an expert and be a Metastock Professional soon? Just click here to learn more tips from the pros today.

Watch this video for a quick introduction to Metastock Basic Information.

Exit mobile version