Metastock's programming language breaks down into three simple components:-
- Parameters
- Mathematical operators, and
- Functions
When they are combined together they are the foundation of the metastock programing language that, can take you forward in your technical trading future. This knowledge and programming are the key to the four major tools of metastock being:-
- Indicator Builder
- Explorer
- Expert Advisor
- System Tester
The formula system used by metastock is the same language used with Microsoft Excel so if you have experience building spreadsheets with formulas you are well on your way to unlocking the power of metastock, but if you don't have experience with Excel you should not worry as this and the lessons to come will teach you how to unlock the power of technical trading with Metastock.
Parameters - Price Array Identifiers
This is the basics, this is how you unlock the raw data collected with your metastock data downloader, simple all the information within any spreadsheet.
CODE - Identifier - Description
O - Open - This is the price of the first trade of that trading period
H - High - This is the highest price trade of that trading period
L - Low - This is the lowest price of that trading period
C - Close - This is the last price of that trading period
V - Volume - This is the number of shares trading during that period
Mathematical Operators
The mathematical operators are the basic mathematic functions of programming and can be separated into three (3) categories:-
- Arithmetic operation
- Comparison operation
- Logical operation
Arithmetic operation
CODE - Operator - Description
/ - Division - Dividing x by y
* - Multiplication - In school we all used the X symbol
+ - Addition - Adding two (2) numbers together
- - Subtraction - Taking one (1) number from another
Comparison operation
CODE - Operator - Description
< - Less Than - X is less than Y (X<Y)
<= - Less Than or Equal to - X is less than or equal to Y (X<=Y)
> - Greater Than - X is greater than Y (X>Y)
<= - Greater Than or Equal to - X is grater than or equal to Y (X>=Y)
= - Equal - Same value
<> - Not Equal - Any values that are not the same
Logical operation
CODE - Operator
C=H - close to be equal to high
O=L - open to be equal to low
C>O - close to be greater than open
AND - Logical code for and
OR - Logical code for or, does not need to be all.
Implement Simple Components
When trying to read or write the code you want you need to stop and talk it out loud, you need to be able to visualise each component separately.
For example - How to work it through
I want to identify when the close is equal to the high for the period, and when the close is greater than the open. - Step 1 write it all out
I want to identify when the close is equal to the high for the period, and when the close is greater than the open. - Step 2 identify elements
C=H and C>O - Step 3 simplify and replace works with code.
EXERCISE 1.1
Write the code for the following conditions:-
Open to be greater than the low, and the close to be greater than the open.
Order of Mathematic Function
Now that you are starting to get comfortable with the coding I expect that you start building longer and more complicated codes, when you do this you will need to create an order for the software to interpret and understand what you are looking for.
Now within the software there is an order for the way mathematical functions are done, personally I recommend a high use of parentheses, these things ( ).
Part A1 - Part A2 - Part B1 - Part B2
C=H and O<C or C=H and O=L
Without using the parentheses makes metastock show us if Part A1, Part B2 are true, and either Part A2 or Part B1.
Part A1 - Part A2 - Part B1 - Part B2
(C=H and O<C) or (C=H and O=L)
Using the parentheses makes metastock show us if Part A or Part B if true.
Remember metastock works from the innermost parenthesis out.
EXERCISE 1.2
Write the code for the following conditions:-
Open to be greater than the low and the close to be greater than the open, OR, Open to be greater than Low and High to be greater than Open.
EXERCISE 1.3
Write the code for the following conditions:-
High to be 10% more than the Open and High to be 15% more than the Low
- Parameters
- Mathematical operators, and
- Functions
When they are combined together they are the foundation of the metastock programing language that, can take you forward in your technical trading future. This knowledge and programming are the key to the four major tools of metastock being:-
- Indicator Builder
- Explorer
- Expert Advisor
- System Tester
The formula system used by metastock is the same language used with Microsoft Excel so if you have experience building spreadsheets with formulas you are well on your way to unlocking the power of metastock, but if you don't have experience with Excel you should not worry as this and the lessons to come will teach you how to unlock the power of technical trading with Metastock.
Parameters - Price Array Identifiers
This is the basics, this is how you unlock the raw data collected with your metastock data downloader, simple all the information within any spreadsheet.
CODE - Identifier - Description
O - Open - This is the price of the first trade of that trading period
H - High - This is the highest price trade of that trading period
L - Low - This is the lowest price of that trading period
C - Close - This is the last price of that trading period
V - Volume - This is the number of shares trading during that period
Mathematical Operators
The mathematical operators are the basic mathematic functions of programming and can be separated into three (3) categories:-
- Arithmetic operation
- Comparison operation
- Logical operation
Arithmetic operation
CODE - Operator - Description
/ - Division - Dividing x by y
* - Multiplication - In school we all used the X symbol
+ - Addition - Adding two (2) numbers together
- - Subtraction - Taking one (1) number from another
Comparison operation
CODE - Operator - Description
< - Less Than - X is less than Y (X<Y)
<= - Less Than or Equal to - X is less than or equal to Y (X<=Y)
> - Greater Than - X is greater than Y (X>Y)
<= - Greater Than or Equal to - X is grater than or equal to Y (X>=Y)
= - Equal - Same value
<> - Not Equal - Any values that are not the same
Logical operation
CODE - Operator
C=H - close to be equal to high
O=L - open to be equal to low
C>O - close to be greater than open
AND - Logical code for and
OR - Logical code for or, does not need to be all.
Implement Simple Components
When trying to read or write the code you want you need to stop and talk it out loud, you need to be able to visualise each component separately.
For example - How to work it through
I want to identify when the close is equal to the high for the period, and when the close is greater than the open. - Step 1 write it all out
I want to identify when the close is equal to the high for the period, and when the close is greater than the open. - Step 2 identify elements
C=H and C>O - Step 3 simplify and replace works with code.
EXERCISE 1.1
Write the code for the following conditions:-
Open to be greater than the low, and the close to be greater than the open.
Order of Mathematic Function
Now that you are starting to get comfortable with the coding I expect that you start building longer and more complicated codes, when you do this you will need to create an order for the software to interpret and understand what you are looking for.
Now within the software there is an order for the way mathematical functions are done, personally I recommend a high use of parentheses, these things ( ).
Part A1 - Part A2 - Part B1 - Part B2
C=H and O<C or C=H and O=L
Without using the parentheses makes metastock show us if Part A1, Part B2 are true, and either Part A2 or Part B1.
Part A1 - Part A2 - Part B1 - Part B2
(C=H and O<C) or (C=H and O=L)
Using the parentheses makes metastock show us if Part A or Part B if true.
Remember metastock works from the innermost parenthesis out.
EXERCISE 1.2
Write the code for the following conditions:-
Open to be greater than the low and the close to be greater than the open, OR, Open to be greater than Low and High to be greater than Open.
EXERCISE 1.3
Write the code for the following conditions:-
High to be 10% more than the Open and High to be 15% more than the Low