MetaStock Reference Function

Provided By www.meta-formula.com

The Reference function is one of the most commonly used functions, as it allows us to refer to the value of any expression, or the selected `data array', any number of periods back or subsequent periods into the future. It's important to note that if you are using the reference function to refer to a period into the future it is obviously dynamic, meaning that it can change. Therefore be careful when using it within system tests, since it can create deceptively good results.

SYNTAX Ref(Data Array, Periods)

Data Array _ The value of the data array that will be returned from `x' number of periods ago.

Periods _ This dictates how many periods forward or back to reference the value of the data array from. A negative number will refer to a value in the past, whereas a positive number will refer to a value in the future.

EXAMPLE

The following formula refers to the closing price yesterday:

Ref(C,-1)

In the formula above:

Data Array = C

Periods = -1

APPLICATION

A more useful application of this example could be:

C>Ref(C,-1) AND Ref(C,-1)> Ref(C,-2)

This formula specifies that the closing price from the current period must be above the closing price from the previous period; and the closing price from the previous period must be greater than the closing price from the period before that. In this example, we have used the closing price as the data array, however you can use almost any function or indicator.

Another common application of the reference function is to accurately describe peaks and troughs, without using the peak and trough functions within MetaStock. A simple definition of a peak is a bar that has had 2 previous periods with lower highs and 2 subsequent periods with lower highs. Using the reference function, we can accurately code this as follows:

H>Ref(H,-1) AND Ref(H,-1)>Ref(H,-2) AND H>Ref(H,1) AND Ref(H,1)>Ref(H,2) 

Note that since we are using a positive application of the Reference function (denoted by `H>REF(H,1)'), a signal will only appear after the event has passed. In other words, you only know a peak has occurred after it has happened.

Looking at Figure 3.19, we can see this example applied to the chart

 
 

Figure 3.19 _ Reference

EXERCISES

Construct formulas for the following:

1. Obtain the volume from 3 periods ago:

__________________________________________________

2. A conditional statement that states that the 30 period simple moving average of the closing price is greater than what it was 5 periods ago:

__________________________________________________

This article is a snippet from the
MetaStock Programming Study Guide...

"Discover The Simple Secret to Make Metastock Easy & Identify Profitable Trades"

Click Here To Find For More About
The MetaStock Programming Study Guide

copyright 2007 www.meta-formula.com