The post Pre-Programmed Functions – Discover Nesting Functions appeared first on Meta Stock Download.
]]>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.
The post Pre-Programmed Functions – Discover Nesting Functions appeared first on Meta Stock Download.
]]>The post Pre-Programmed Functions – Learn The Pasting Functions appeared first on Meta Stock Download.
]]>As you could imagine with over 200 pre-programmed functions it would be next to impossible to memorise every parameter and its correct syntax. As such Metastock has included a ‘Paste Functions’ dialog box. This allows you to paste the correct syntax straight into any formula you may be working on. Simply by clicking the functions button while editing any formula, you will display this dialog. (Note: your cursor must be within the ‘formula:’ dialog for the ‘Functions…’ button to become active).
Guide: Paste Functions Dialog
The ‘Paste Functions’ dialog groups all of the functions into 11 categories; these are listed on the left-hand side. On the right-hand side, the function names are listed. Also, at the bottom left of this dialog are two check boxes, ‘Paste Arguments’ and ‘Show English Names’. ‘Paste Arguments’ instructs MetaStock to include all the param- eters required for the function. ‘Show English Names’ instructs MetaStock to list the English names, rather than the function names. For ease of use, it’s best if both these boxes are checked.
Once we begin programming you will become quite familiar with this dialog box. When you require any formula’s syntax, simply scroll the ‘Paste Function’ list and the syntax of the highlighted function is displayed near the bottom of the dialog (shown under ‘Format’). Then, by clicking the ‘OK’ button (or double-clicking the function name), the selected function is pasted into the formula at the cursor location. If for some reason you do make a mistake and forget to insert the correct parameter, even though you have used the ‘Paste Functions’ dialog; don’t worry as MetaStock will display a dialog reminding you of the expected parameter.
A Metastock Professional is expected to know everything about these things. In our next post, we will be presenting information that you need to know in terms of nesting functions. Do you want to learn how to use MetaStock formula like an expert? Just click here to learn more tips from the pros.
Watch this video for a quick introduction to Quote Center for Metastock.
The post Pre-Programmed Functions – Learn The Pasting Functions appeared first on Meta Stock Download.
]]>The post Pre-Programmed Functions – Introduction For Metastock Experts appeared first on Meta Stock Download.
]]>Introduction
In addition to the mathematical operators there are over 200 pre-programmed functions to allow coding versatility. The bulk of these fall into three categories: analysis tools, indicators and candlesticks. In this chapter we’ll look at each of these categories in detail, highlighting some of the more commonly used functions. Moreover, we’ll provide specific explanations, applications, and questions about these functions.
Before we begin though, we must explain what function parameters are, and where they’re used. A function is a set of predefined mathematical operations that MetaStock follows; and a parameter provides a function with the necessary information it needs to calculate these predefined mathematical operations. Some functions need no parameters; whereas others need numerous.
Let’s look at a couple of examples; the actual parameters are in bold, to make them identifiable. (These examples are only used to highlight what parameters are and where they are used).
ATR(14)
3
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 this is further explained on the next few posts.
Mov(C,7,S)
This formula plots a 7-period simple moving average. The parameters include the data array (c), periods (7) and moving average type constant (s). Notice that when a function has multiple parameters each parameter is sepa- rated by commas. The moving average syntax is ‘Mov(Data Array, Periods, Constant)’, and this is further explained on the next few posts.
In this last example, we have introduced the idea that there are different types of parameters. Some of these may be specific to a particular function, while others are more universal. The price data array parameter, which we are already familiar with (refer to page 18, table 2.1), and the periods parameter which we just introduced in the moving average example, are the most universal parameters.
Periods refer to a single value, or a numeric constant, that determines the time period of a function. For example, a ‘periods parameter’ is the ‘7’ in the formula ‘Mov(C,7,S)’. This indicates that the moving average is a seven period average.
The other not so common parameters will be discussed as they arise in their respective functions.
A Metastock Expert is expected to know everything about these things. In our next post, we will be presenting information that you need to know in terms of pasting functions. Do you want to learn how to use MetaStock formula like an expert? Just click here to learn more tips from the pros.
Watch this video for a quick introduction to Best Trading Software.
The post Pre-Programmed Functions – Introduction For Metastock Experts appeared first on Meta Stock Download.
]]>The post MetaStock Programming Language – Exercises appeared first on Meta Stock Download.
]]>Price Array Identifier Shortcut
Open
High
Low
Close
Volume
Arithmetic Operators Shortcut
Division
Multiplication
Addition
Subtraction
Comparison Operators Shortcut
Less than
Less than or equal to
Greater than
Greater than or equal to
Equal to
Not equal to
Some of the following questions use the moving average function. If you are not familiar with this, we would suggest you to review on the previous posts to gain a basic understanding.
Complete the following formulas:
The close is greater than the open and either the volume is greater than 50000 or the turnover (closing price multiplied by the volume) is greater than 100000:
The close is within the top 20% of the period’s trading range (i.e., low to high):
The close minus 3%:
Language
A weighted moving average of the closing price which can be modified by the user (hint: you will need to use the Input function):
The closing price is greater than the 10 period simple moving average of the closing price; the volume is greater than a 10 period simple moving average of the volume; and the 10 period simple moving average of the closing price is greater than the 25 period simple moving average of the closing price. Develop this formula so that all of the ‘10’ values can be easily changed using the ‘variables’ feature:
If the closing price is greater than its 45 period exponential moving average, plot a 10, but if not, then plot a -5:
Comment out, but not remove ‘C>MOV(C,21,S)’ from the following formula:
V>Mov(V,20,S) AND C>O AND C>Mov(C,21,S) AND Ref(V,-1)<V*1.2
The 13 period simple moving average of the closing price is greater than the 21 period simple moving average of the closing price; the close is within the top 5% of the day’s trading range (i.e., low to high); and the turno- ver is greater than $200,000:
A Metastock professional is expected to know everything about these things. In our next post, we will be presenting the introduction to pre-programmed functions. Do you want to learn how to use MetaStock formula like an expert? Just click here to learn more tips from the pros.
Watch this video for a quick introduction to MetaStock Data.
The post MetaStock Programming Language – Exercises appeared first on Meta Stock Download.
]]>The post MetaStock Programming Language – Input ‘On Balance Volume Indicator’ appeared first on Meta Stock Download.
]]>This is a continuation of our series on the basics of MetaStock Programming Language and MetaStock market data. In this post we are going to talk about ‘On Balance Volume Indicator’, something that you need to know as a Metastock Expert.
Figure 2.8 –Input ‘On Balance Volume’ Indicator
When looking at the code, can you identify each separate component of the input function? i.e the prompt text, minimum value, maximum value and default value. The astute reader may have realised that inputs are most effective when used in conjunction with variables that use a single value, as shown in the above example.
Note that more than one input can be used in a formula. In fact up to 6 inputs can be used in a formula. Remember our example from the variables section?
We could rewrite this to include the input function.
x:=Input(“Enter the short-term moving average value”,2,9,5);
y:= Input(“Enter the medium-term moving average value”,10,19,10);
z:= Input(“Enter the long-term moving average value”,20,29,20); C > Mov(C, x, E) AND
Mov(C, x, E) > Mov(C, y, E) AND Mov(C, y, E) > Mov(C, z, E)
Now, each time we plot this as an indicator all of the inputs required would appear in a dialog before the indicator is plotted.
Language
If we did plot this as an indicator a ‘1’ would be displayed every time all of the conditions were true (we’ll learn more about indicators later). Thus, if the close was greater than the short moving average, the short term moving average was greater than the medium term moving average and the medium term moving average was greater than the long term moving average, then a value of ‘1’ would be plotted, otherwise the indicator would remain ‘0’.
There are a few rules to follow when using input functions. Firstly, since an input function by its nature requires an input, it can only be used in The Indicator Builder. That is to say it can’t be used in explorations, system tests and experts.
Secondly, and more importantly, in most cases you will have to assign the input() function to a variable. This is because the input() function cannot be embedded within other functions. For example, the following use of the input() function is not valid:
mov(close, input(“Enter the short-term moving average value”,1,21,7), s); This can be modified allowing for the use of the input function.
periods:= Input(“Enter the moving average value”,1,21,7); Mov(CLOSE,periods,SIMPLE)
As you can see inputs allow for great versatility within coding.
Now you know these Metastock tips and input ‘On Balance Volume Indicator’. In our next post, we will be presenting some exercises regarding Price Array Identifier and Arithmetic Operators. Do you want to learn how to use MetaStock formula like an expert? Just click here to learn more tips from the pros.
Watch this video for a quick introduction to MetaStock Basics.
The post MetaStock Programming Language – Input ‘On Balance Volume Indicator’ appeared first on Meta Stock Download.
]]>The post MetaStock Programming Language – Rules In Naming Variables appeared first on Meta Stock Download.
]]>This is a continuation of our series on the basics of MetaStock Programming Language. In this post we are going to talk about tips in naming variables as a Metastock Professional.
When naming variables, MetaStock outlines that there are a few rules to follow:
• Variable names cannot contain commas, parenthesis, spaces, underscores etc.
• Variable names cannot duplicate names already used by functions (e.g., mov, rsi, if, etc.).
• Variables cannot be assigned a name that matches the parameters reserved for use in formulas (e.g., open, high, low, close, simple etc. Moreover this includes their respective shortcuts).
• Variable names must contain at least one alpha letter (e.g., T1234 ).
• Variable names are not case sensitive (e.g., “PERIODS” is the same as “periods”).
The If() Function
The if() function employs one of the most common idioms of modern programming languages, the “if… then… else…” construct. This is a type of conditional statement that says if a predefined expression occurs, perform ‘x’, but if it does not occur, then perform ‘y’.
The correct syntax for an if() function is: If({expression},{then data},{else data})
• The “expression” is the required condition.
• The “then data” is the action or value if the expression is true.
• The “else data” is the action or value if the expression is false. Let’s look at an example called ‘positive and negative volume’:
if( C > O, +V, -V )
This formula plots “positive volume” if the selected security’s close is greater than its open. Otherwise, “negative volume” is plotted. Graphically, this is shown in Figure 2.7. The formula itself doesn’t have much practical use. However, it shows the if() function in action.
The if() function is more practically used in the “On Balance Volume” indicator (discussed in Chapter 3). The formula for this indicator is a bit advanced, however, it provides a useful example of the if() function.
(If(C > Ref(C,-1),1,-1) * VOLUME) + PREV
Later, we will learn these types of formulas and their intricacies.
Figure 2.7 – Positive & Negative Volume
Language
The Input Function
The Input function is used in conjunction with custom indicators to prompt the user for input. Most probably you’ve already encountered the input function and didn’t even notice it. I say this since a good number of MetaStock’s pre-defined indicators use the input function. For example, do you remember when applying the moving average indicator MetaStock prompts you to “enter time periods”, “method”, “price fields”, etc? These are all input functions.
When coding an input function into a custom indicator the basic syntax is:
input(“{prompt text}”,{minimum value},{maximum value},{default value});
• The prompt text is the text displayed to the user next to the input box. It’s used to describe what input is required i.e. moving average period.
• The minimum value is the smallest value that can be entered.
• The maximum value is the largest value that can be entered.
• The default value is the value that will appear initially within the input box.
When using the ‘Input’ function, we define the minimum and maximum values to be entered. If a value is set outside this range, an error message is displayed. The error message will ask that the value must be greater than or less than what was entered.
Guide
Let’s look at an example of a Metastock market data. The following custom indicator asks for the time periods that you wish to use for a moving average of the ‘On Balance Volume’ indicator, i.e. the number of smoothing periods.
SmoothingPeriods:=Input(“Enter the number of OBV smoothing periods”,1,21,7); Mov(OBV(21),SmoothingPeriods,S);
When this custom indicator is plotted, the following input dialog appears prompting you to “Enter the number of OBV smoothing periods”.
Now you know these Metastock tips on naming variables. In our next post, we will be discussing input on “On Balance Volume” indicator. Do you want to learn how to use MetaStock formula like an expert? Just click here to learn more.
Watch this video for a quick introduction to various aspects of the Metastock data platform, QuoteCenter.
The post MetaStock Programming Language – Rules In Naming Variables appeared first on Meta Stock Download.
]]>The post MetaStock Programming Language – Tips On Inserting Comments appeared first on Meta Stock Download.
]]>This is a continuation of our series on the basics of MetaStock Programming Language. In this post we are going to talk about inserting comments within a formula.
Inserting Comments
MetaStock allows you to make comments anywhere within a formula. Comments are denoted by enclosing any text in braces i.e. ‘{’ and ‘}’. These make it possible to annotate your code without wrecking the syntax. Ultimately, as a Metastock expert this makes code easier to read by yourself and others. Moreover, comments are a great tool when used in the design phase of a formula. For example, assume we wanted to test a specific section of a formula. With the use of braces we can “comment out” other specific sections of code, leaving only the code in question. Later we can simply remove the braces to restore the other code. Here are some examples:
Guide
Mov(C,5,S) > Mov(C,14,S) {AND Rsi(c,14) > 60} – this is an example of commenting out coding
Mov(C,15,S) > Mov(C,30,S) AND C>0.5 {I might have to adjust this from 50 cents to something higher if too many stocks appear in the explorer – will see what happens} – this is an example of making comments
Advanced Features
Next, we’ll look at a few of the advanced features within MetaStock guide after inserting comments within a formula. If you’re not familiar with any type of programming, most of these concepts will be new to you. To help you overcome the learning curve, there’ll be plenty of examples and questions to tackle. Additionally, in later chapters we’ll refer to all of these features and how to apply them practically.
Variables
We’ll begin with variables: a variable is a letter or a word that is assigned to an expression or single value. This letter or word can then be used instead of the original expression or single value. Basically, it enables us to select one word and use it to replace whole pieces of coding. We like to think of it as a way of writing ‘shorthand’: rather than repeating expressions over and over we can assign a variable and then reference that variable. This simplifies formulas, making them easier to read and maintain.
For MetaStock to understand our ‘shorthand’ we must first define what the variable will be replacing. The basic syntax for this is:
{variable name} := {expression or single value};
• The ‘:=’ separates the variable name from the expression.
• The semi-colon denotes the end of a variable statement.
Let’s look at a basic variable statement:
x:=10;
C > Mov(C, x, E) AND Mov(C, x, E) > Mov(C, 20, E)
Now before you are overwhelmed by this formula, remember we haven’t introduced the moving average func- tion. All you have to understand is that ‘x’ is assigned to the number ‘10’, shown by ‘x:=10;’. Therefore when- ever the letter ‘x’ is written this would be the same as writing ‘10’.
In our example, the benefit of this type of variable is that we can use it to easily change the time periods within our formula. Rather than having to edit each use of the time periods individually, we can just alter the variable. For example, if we wanted to alter the time periods in the above example, from 10 to 5, we could simply change the variable statement to ‘x:=5;’. Now whenever ‘x’ is written, the new assigned variable would be the number ‘5’. With more complex formulas the benefit of using variables cannot be overstated.
Evidently, more than one variable can be used in a formula. In fact up to 20 variables can be used in a formula, as long as they’re assigned before you use them. In the example on the next page we’ve used three separate variables. The code itself looks for securities that exhibit the following attributes: the close to be greater than the short-term moving average, the short-term moving average to be greater than the medium-term moving average, and the medium-term moving average to be greater than the long term moving average.
Language
x:=5; y:=10; z:=20;
C > Mov(C, x, E) AND
Mov(C, x, E) > Mov(C, y, E) AND Mov(C, y, E) > Mov(C, z, E)
When looking at the code, imagine that typing the variable would be the same as typing the single value the variable is assigned to. While assigning variables to a single value can make the maintenance of a complex formula easier, perhaps the 2 most effective use of variables is in assigning them to an expression. This handy tool enables complex formulas to be shortened, making them easier to read and easier to modify.
Using our previous example of multiple variables, let’s rewrite this, assigning whole expressions to variables. x:= Mov(C, 5, E);
y:= Mov(C, 10 , E); z:= Mov(C, 20, E); C > x AND
x > y AND
y > z
See how each expression is now assigned to a variable? This means that whenever the variable’s corresponding letter is typed, the expression will appear.
For example, if ‘x’ was typed, this would be the same as typing
‘Mov(C,5,E)’.
Although this next example is outside the scope of this chapter, let’s look at a complex formula and how it can be simplified by variables. We show you this formula not to impress you, but to impress upon you the usefulness of variables.
The use of variables can transform the formula “CMO Volatility”, from this: ((Stdev(CMO(C,5),5)*CMO(C,5))+( Stdev(CMO(C,8),8)*CMO(C,8))+
(Stdev(CMO(C,13),13)*CMO(C,13)))/( Stdev(CMO(C,5),5)+ Stdev(CMO(C,8),8)+
Stdev(CMO(C,13),13)) Into this:
S1:= Stdev(CMO(C,5),5); S2:= Stdev(CMO(C,8),8); S3:= Stdev(CMO(C,13),13);
((S1*CMO(C,5))+(S2*CMO(C,8))+(S3*CMO(C,13)))/(S1+S2+S3)
Guide
Not only is this code shorter, but it’s easier to read and easier to modify as a MetaStock Professional. This concludes the introduction to variables, and although they can be quite overwhelming at first, remember they simply assign a letter or a word to an expression or single value. This letter or word can then be used instead of the original expression or single value.
Now you know tips on inserting comments anywhere within a formula. In our next post, we will be discussing few rules to follow when naming variables in MetaStock Programming Language. Do you want to learn how to use MetaStock formula like the pros? Just click here to learn more.
Watch this video for a quick introduction to various aspects of the Metastock data platform, QuoteCenter.
The post MetaStock Programming Language – Tips On Inserting Comments appeared first on Meta Stock Download.
]]>The post Learning The Basics Of MetaStock Programming Language Part 3 appeared first on Meta Stock Download.
]]>This is a continuation of our series on the basics of MetaStock Programming Language. In this post we are going to talk about the order of precedence and periodicity.
Order of Precedence
The order of operator precedence specifies the standard order to be used when calculating any mathematical expression. That is to say, when using any of the mathematical operators we’ve described previously, there’s a universally agreed-upon order in which to evaluate them. You may recall learning this in basic arithmetic classes, however let’s refresh our memories.
In simple terms, the precedence of an operator specifies how “tightly” two expressions are bound together. For example, when calculating the expression 1 + 5 * 3, rather than working out the math from left to right, we obey the order of precedence. This states that the multiplication operator ranks higher than the addition operator. Therefore we first multiply five by three and then add one, this equals 16. If however we calculated the expression from left to right we would get the answer 18, which is obviously incorrect. We need to keep this in mind as Metastock expert while creating our own formulas, since whenever MetaStock calculates a piece of coding it refers to the order of operator precedence.
Table 2.5 shows the order of operator precedence, when parentheses are not used:
Mathematical Operator | Shortcut |
Negative values |
– |
Multiplication |
* |
Division |
/ |
Addition |
+ |
Subtraction |
– |
Less than |
< |
Greater than |
> |
Less than or equal to |
<= |
Greater than or equal to |
>= |
Equal to |
= |
Not equal to |
<> |
Logical “And” | and |
Logical “Or” |
or |
Table 2.5 – Operator Precedence Guide
Now that you’re getting comfortable with the operator precedence in the Metastock guide, we can introduce parentheses. By “paren- theses” we mean brackets that act as a grouping symbol i.e. ‘( )’. These are used to further control the order in which mathematical expressions are calculated. When used, all expressions within the parentheses are calculated first. If there are parentheses inside parentheses, MetaStock works from the innermost parenthesis outward. The order of operator precedence is still used, however, it’s as though the parenthesis has the highest ranking. This may appear trivial, nevertheless, it is important you understand their use and the dramatic effect they can have. Their use is best illustrated with an example. Suppose you were to encounter a ‘MetaSpeak’ expression such as:
H-(H-L)*2
MetaStock would evaluate this first by calculating the inner most parenthesis ‘(H-L)’. The multiplication would then be calculated since it has a higher precedence than subtraction ‘(H-L)*2’. Finally, the subtraction from the high would be calculated ‘H-(H-L)*2’.
Conversely, presume we asked someone who didn’t understand the use of parentheses, to code the same thing. They would write the code as ‘H-H-L*2’. Now when MetaStock calculates this, it would initially multiply the low by two ‘L*2’, since multiplication has higher precedence than subtraction. Then, the high would be sub- tracted from the high ‘H-H.’ Finally, the result of ‘L*2’ would then be taken from this.
As you can see parentheses dramatically affects the outcome.
Periodicity
Earlier in Metastock Programming Language we discussed price array identifiers saying that they reflect the open, high, low, close, volume and open interest. The astute reader may have noticed the wording of each definition made no reference to a particular period, i.e. daily, weekly or monthly. For example the definition for the open was as follows: “This is the price of the first trade for the period.” Since there was no reference to a particular period, we must identify which opening price we are referring to.
To do this as a Metastock professional, we need to pull up the periodicity tab which is located in the ‘X-Axis Properties’ dialog. Simply, select X-Axis from the ‘Format’ menu, or right-click on a chart’s X-Axis and choose ‘X-Axis Properties’ from the shortcut menu. The X-Axis Properties are shown in Figure 2.5
Figure 2.5 – X-Axis Properties
You can also change the periodicity directly by using the Periodicity button on the chart toolbar, represented by the ‘D’ in figure 2.6:
Figure 2.6 – Chart Toolbar
Within the ‘X-Axis Properties’ dialog, or using the periodicity button, we can indicate the period we wish the chart to be displayed in (ie, daily, weekly, monthly, quarterly or yearly periods). We can also select the “other” option which allows us to define the number of periods over which to compress the data, thereby selecting whatever period we like.
Now that we know where it’s located, remember to keep an eye on the periodicity, as it can greatly affect our price array identifiers. For example, assume we were using the ref(c,-1) function (we’ll discuss this function later) which returns the close from the previous period. If the periodicity was set to weekly, the previous close would be from 1 week ago. Conversely, if it was set to daily, the previous close would be from one day ago.
In Metastock Programming Language, the effects of periodicity are also seen in two other data array identifiers, the volume and open interest. MetaStock calculates volume and open interest by merely summing the values over the selected period. For example, a chart showing weekly periodicity would sum the entire week’s volume in one period.
In our next post, we will be discussing how to insert comments within a formula, as part of the advanced features of the MetaStock Programming Language. Do you want to discover how to use MetaStock formula like the pros? Just click here to learn more.
Want a quick introduction to various aspects of the Metastock data platform, QuoteCenter? Watch this video:
The post Learning The Basics Of MetaStock Programming Language Part 3 appeared first on Meta Stock Download.
]]>The post Learning The Basics Of MetaStock Programming Language Part 2 appeared first on Meta Stock Download.
]]>This is a continuation of our series on the basics of MetaStock Programming Language. In this Metastock guide post we are going to talk about the mathematical and logical operators.
Mathematical Operators
‘Mathematical Operators’ is just a fancy name for basic mathematical terms used within coding. These can be broken into three categories: arithmetic operators, comparison operators and logical operators.
Do you remember basic arithmetic from school? Table 2.2 lists the arithmetic operators and their corresponding coding shortcuts.
Arithmetic Operators | Shortcut |
Division |
/ |
Multiplication |
* |
Addition |
+ |
Subtraction |
– |
Table 2.2 – Arithmetic Operators Language
Comparison operators, as their name implies, allow you to compare two values. Table 2.3 lists the comparison operators and their corresponding coding shortcuts.
Comparison Operators | Shortcut |
L ess than |
< |
L ess than or equal to |
<= |
G reater than |
> |
G reater than or equal to |
>= |
E qual to |
= |
N ot equal to |
<> |
Table 2.3 – Comparison Operators 2
Note that within the MetaStock Programming Language only mathematical operator shortcuts can be used when referencing arithmetic and comparison operators. For example, if we wished to use multiplication we would simply type ‘*’.
Logical Operators – ‘And’ and ‘Or’
Logical Operators are a little harder to understand than the other two mathematical operators. Nevertheless, they offer increased coding flexibility. The two logical operators are ‘and’ and ‘or’. They allow a formula to involve multiple conditions.
Their use is best illustrated by way of example. Let’s assume that we wanted a security to exhibit three attributes;: the close to be equal to the high, the open to be equal to the low and the close to be greater than the open (i.e. a bullish period, as shown in Figure 2.2).
Figure 2.2 – Bullish OHLC Bar
Table 2.4 displays the required conditions and their corresponding code, written in the Metastock Professional formula language.
Condition | Code |
The close to be equal to the high | C=H |
The open to be equal to the low | O=L |
The close to be greater than the open | C>O |
Table 2.4 – Conditions Guide
Now before a bullish period can exist, we need all three statements (shown in Table 2.4) to exist. Using the ‘and’ operator we can combine these three conditions. This would effectively link the three statements, requiring that each condition exists. Written in ‘MetaSpeak’ this would look like:
C=H AND O=L AND C>O
To reinforce your understanding, look at the code, and Figure 2.1, and ask yourself ‘can I visually identify what the code is saying?’ If you can not, break down the coding into its separate components and visualise each component separately.
Let’s look at another example. Assume that we wanted a security to exhibit three different attributes: the close to be equal to the high, the open to be greater than the low and the close to be greater than the open (shown in Figure 2.3).
Figure 2.3 – Bullish Hammer OHLC Bar
In the space below, write the formula for the above conditions:
Again, visually identify how the coding reflects the price bar (shown in Figure 2.3). See how the ‘and’ operator links each component?
Now presume that we wanted to identify one of these price bar patterns or the other. This is shown in Figure 2.4
Figure 2.4 – Bullish Hammer and Bullish OHLC Bar
Notice that we want one ‘or’ the other. This is where we would use the ‘or’ operator to link the coding together. In this way we would isolate securities displaying either the first set of conditions or the second set.
The code would simply look like this: (C=H AND O=L AND C>O)
OR
(C=H AND LO)
Can you now see the difference between the two logical operators? The ‘and’ operator requires that all the linked conditions be correct whereas, the ‘or’ operator only requires one or the other of the linked statements to be correct.
In our next post, we will be discussing the advanced features of the MetaStock Programming Language. Do you want to discover how to use MetaStock formula like the pros? Just click here to learn more.
Want a quick introduction to various aspects of the Metastock trading software? Watch this video:
The post Learning The Basics Of MetaStock Programming Language Part 2 appeared first on Meta Stock Download.
]]>The post Learning The Basics Of MetaStock Programming Language Part 1 appeared first on Meta Stock Download.
]]>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:
The post Learning The Basics Of MetaStock Programming Language Part 1 appeared first on Meta Stock Download.
]]>