Learning The Basics Of MetaStock Programming Language Part 1

Posted in Blog

Introduction To The MetaStock Programming Language

You don't have to be a geek to use MetaStock.

MetaStock uses a patented programming language that, to the untrained eye, seems more like a foreign language. Some users have even affectionately named it ‘MetaSpeak’. At first glance it may look intimidating, but MetaStock is quite logical in its processes. Consequently, anyone with a bit of persistence can learn to program custom indicators, explorations, system tests and experts. In fact, you don’t have to be a MetaStock expert just to get started.

MetaStock’s programming language breaks down into three simple components: parameters (e.g. open, high, low, close, etc.), mathematical operators (e.g. +, -, /, *) and functions (e.g. a moving average, the Stochastic Oscillator or the Relative Strength Index). When combined, they form the foundation of MetaStock’s program- ming language. Essentially this is what drives MetaStock’s four major tools: The Indicator Builder, The Explorer, The Expert Advisor and The System Tester.

The MetaStock programming language itself is actually patterned after popular spreadsheet languages. So for those of you 2 who can already create a reasonable spreadsheet you’re half way there to understanding ‘MetaSpeak’. If you can’t, don’t worry, we will begin with the basics first.

Parameters – Price Array Identifiers

Let’s begin by looking at some parameters called price array identifiers, or price plot data. They form the basis of all technical analysis: the open, high, low, close, volume and open interest (shown graphically in Figure 2.1). When used they identify specific price fields that the formula should operate on. Here are some simple defini- tions:

Open – This is the price of the first trade for the period (e.g., the first trade of the day). When analyzing daily data, the Open is especially important as it is the consensus price after everybody has had a chance to “sleep on it.”

High – This is the highest price that the security traded during the period. It is the point at which supply overcame demand. There are always sellers willing to sell at higher prices, but the High represents the highest price buyers were willing to pay.

Low – This is the lowest price that the security traded during the period. It is the point at which demand overcame supply. There are always buyers willing to buy at lower prices, but the Low represents the lowest price sellers were willing to accept.

Close – This is the last price that the security traded during the period. Due to its availability, the Close is the most often used price for analysis. The relationship between the Open (the first price), and the Close (the last price), are considered to be significant by most technical analysts. This relationship is emphasized in candlestick charts.

Volume – This is the number of shares (or contracts) that were traded during the period. The relationship between prices and volume (e.g., increasing prices accompanied by increasing volume) are considered impor- tant.

Open Interest – This is the total number of outstanding contracts (i.e., those that have not been exercised, closed, or expired) in relation to futures or options. Open interest is often used as an indicator.

OHLC Bar

Table 2.1 lists the Price Array Identifiers and their corresponding coding shortcuts.

The Price Array Identifiers Shortcut
Open

O

High

H

Low

L

Close

C

Volume

V

Open Interest         OI

Table 2.1 – Price Array Identifiers

Either the full price array identifiers or their shortcuts can be used when coding. For example, ‘close’ or ‘c’ would return the last price that the security traded during the period.

Note that with regard to upper and lower-case characters, MetaStock isn’t case sensitive. Meaning, when entering formulas it doesn’t matter whether ‘c’ or ‘C’ is typed. When checking for syntax errors MetaStock automatically adjusts the case, making them all uniform anyway.

On our next blog post we will be discussing the mathematical and logical operators frequently used in the MetaStock Programming Language. In the meantime, if you want to watch videos on how to use MetaStock, click here to visit our YouTube channel.

Want to jump ahead and learn some tips on MetaStock formula writing? Watch the video below:

Leave a Reply

Your email address will not be published. Required fields are marked *

Get Your Metastock 30 Day Free Trial