Introduction to The Expert Advisor
The Expert Advisor is one of the more powerful tools within MetaStock. That said, itâ€™s probably the least used. We suspect this is due to its complexity, and to the fact that many people donâ€™t appreciate its usefulness. Its power lies in the fact that it can automatically carry out a wide range of analysis on a selected security. This analysis is then displayed on the chart itself through the five components of The Expert Advisor. These five components are described below:
- Trends: Trends are defined technical conditions that are then displayed as a ribbon on the bottom of the security. Ultimately, they provide a convenient way to view bullish, bearish, and neutral zones of a security.
- Commentary: The Commentary is perhaps the most powerful of the five components. It allows us to write text and then control how the text is displayed based on logical conditions. This information is then presented in a separate window. When we examine this further, its usefulness will become apparent.
- Highlights: Highlights change the colour of the price bars depending on defined technical conditions.
- Symbols: Symbols are placed either above or below the price plot depending on defined technical conditions. These are similar to Highlights, with the only difference being the way in which the conditions are displayed, i.e. symbols are used instead of changing the colouring of bars.
- Alerts: Alerts place small pop-up boxes over the securityâ€™s chart alerting us when certain defined technical conditions are met. These are similar to Highlights and Symbols in that they alert you to the existence of certain technical conditions.
These five simple yet effective components make up The Expert Advisor and greatly assist in analysis of charts. Â Their effectiveness is based on the fact that human beings are sensory creatures. That is to say, we love to â€˜seeâ€™ things in order to achieve greater understanding. Generally we are not satisfied with just reading something to understand it; rather we prefer seeing it with our own eyes. Herein lies the power of The Expert Advisor. By using these five components, we are able to change the colour of price bars, place Symbols on the chart, lay coloured ribbons to depict the trend, and have this accompanied by limitless amounts of technical analysis commentary.
Before we begin, open a chart so once we have created a new expert advisor we can apply it. To access The Expert Advisor, click The Expert Advisor Icon on the Standard Toolbar or select it from the Tools drop down menu. This opens the â€˜Expert Advisorâ€™ dialog shown below:
From within this dialog expert advisors can be created, edited, copied, deleted, and printed. The options available in this dialog are as follows:
- Close: Closes the Expert Advisor dialog.
- New: Displays the â€˜Expert Advisor Editorâ€™ dialog, allowing you to name and create a new expert advisor.
- Edit: Displays the â€˜Expert Advisor Editorâ€™ dialog of the selected expert advisor, allowing you to change the name or the formula of The Expert Advisor.
- Copy: Copies the selected â€˜Expert Advisorâ€™, allowing you to rename it and change the original expert advisor.
- Delete: Deletes the selected expert advisor.
- Print: This will print the details of the selected expert advisor or all expert advisors to include all the names or the names and formulas for them.
- Organizer: Displays the â€˜Formula Organizer Wizardâ€™ and enable you to import or export formulas from any of the four main formula using tools within MetaStock.
- Help: Displays the built in Help Feature.
Creating a New Expert Advisor
Letâ€™s create an expert advisor, describing the steps and menus along the way. Click â€˜Newâ€™, and the â€˜Expert Editorâ€™ dialog opens, shown below:
Notice the six tabs across the top of the window. The first one is labelled â€˜Nameâ€™ and the remaining five are the five central components to The Expert Advisor. Letâ€™s start with the â€˜Nameâ€™ page; here we are presented with the two separate text boxes allowing us to insert information. The top one is the â€˜Nameâ€™ box and obviously this is where we â€˜Nameâ€™ our expert advisor.
We are going to call this expert the â€˜MetaStockAustralia.com Expertâ€™. Â Below this is the notes section; remember, any information entered into this text box does not affect the operation of The Expert Advisor.
Weâ€™ll now move through each one of the five components beginning with the Trends tab, shown below:
You will notice that there are two distinct areas within the Trends tab, namely bullish and bearish. Entering any technical condition here will result in the placement of a coloured ribbon on the chart. For now, we are going to place a coloured ribbon at the base of the chart, identifying when the selected security is trading above or below a 50 period simple moving average. Â To achieve this, we simply type the following condition into the â€˜Bullishâ€™ text box:
The effect is such that, every time the closing price is greater than a 50 period simple moving average, a bullish ribbon is placed along the chart. We can further control the details of the ribbon by clicking on the â€˜Ribbonâ€™ button. The expert ribbon dialog is shown below:
From within this dialog, we can change the colour of the bullish, bearish and neutral ribbon. Furthermore, we can label this ribbon with either text or Symbols. Within this dialog there is one more option to note, the â€˜display vertical linesâ€™ option. This allows you to place vertical lines on the chart at the points where the trend ribbon changes status, e.g. from bullish to bearish.
Back to our expert advisor. Â Click â€˜OKâ€™ and now we will define the technical condition for a bearish ribbon. In most cases, this will be the opposite of the bullish condition and in our example weâ€™ll use the following:
Within the Trends tab, we can also place a symbol in The Expert Corner. This area is located at the bottom right hand corner of the chart. Basically, this enables us to quickly identify which conditions exist at present, i.e. bullish, bearish, or neutral. To activate these Symbols, click the â€˜Cornerâ€™ button and tick the check box â€˜Display Symbol In Expert Cornerâ€™. Â Additionally, within this dialog, you can change the Symbols and select their colours. Â In our example weâ€™ll leave these set to default.
The first part of creating our expert advisor is now complete; letâ€™s apply this to the chart to see its effect. Close the â€˜Expert Editorâ€™ dialog, and our new Expert Advisor will be highlighted. Click â€˜Attachâ€™, and then â€˜Close
The result is a ribbon that looks similar to the one shown on the chart below:
(Please note that the 50 period simple moving average shown on the chart above is not part of The Expert Advisor. This has simply been placed on the chart to confirm the analysis shown by the trend ribbon.)
The Commentary is the most complex component of The Expert Advisor. Within this component we can use MetaStockâ€™s powerful formula language to its full potential. In essence the Commentary is just a text report of analysis conducted on the chart. To begin, re-open our newly created Expert Advisor. To edit any Expert Advisor you can click on The Expert Advisor icon in the standard toolbar; select it via the Tools menu; or right mouse click on the chartâ€™s background and select â€˜Expert Propertiesâ€™ under Expert Advisor. This last option will only allow you to edit the Expert Advisor currently attached to the chart you are viewing.
Once The Expert Advisor editor is open, click on the â€˜Commentaryâ€™ tab, shown below:
Before we begin explaining the finer details within the Commentary, it is important that we introduce you to the five â€˜constantsâ€™ that are available within the Commentary. These simply return â€˜constantâ€™ security specific values and are as follows:
- <Name> Displays the name of the security that The Expert Advisor is analysing.
- <Symbol> Displays the code for the security (i.e. ASX code).
- <Periodicity> Displays the periodicity of the chart that The Expert Advisor is analysing, eg. daily, weekly, monthly etc. Note that if you append â€˜:Sâ€™, making the syntax <periodicity:s>, then the words day, week, month etc. will be used instead. Your choice will depend on the context in which it is being used.
- <Date> Displays the date that The Expert Advisor is analysing. Similarly to the periodicity, there are two options for displaying the date. Appending â€˜:Lâ€™ to the syntax, making it <Date:L>, will display the date in long format, e.g. â€˜Friday, April 1, 2016â€™. The short format, which is shown by not including the â€˜:Lâ€™, is displayed as â€˜1/04/2016â€™.
- <Expert> Displays the name of the expert being used.
Those constants allow us to refer to information within the Commentary. For example, by using the date constant, we can refer to the present date without having to edit The Expert Advisor daily, i.e. maintaining the correct date. In this way the Commentary remains dynamic. Back to our Expert Advisor, weâ€™ll start our Commentary with a heading. Furthermore, weâ€™ll create a heading using all of the constants. Simply type the following into the Commentary text box:
This is an analysis of
using the <expert>.
You are presently analysing <date:l> and you are looking at a <periodicity> chart.
Once entered we can click the â€˜Previewâ€™ button and this will show us what our Commentary looks like applied to the present chart. Â The above Commentary should look similar to this:
There are two other important functions which are unique and central to The Expert Advisor Commentary. They are the â€˜writeifâ€™ and â€˜writevalâ€™ functions, and both are described below:
Writeif(Expression, â€œtrue textâ€, â€œfalse textâ€)
The â€˜writeifâ€™ function allows us to display one of two different text options, depending on whether an expression is true or not. That is, if the expression is true, the first text string is displayed, however if the expression is false, the second text string is displayed. The astute reader may notice that this is simply a variation on the â€˜ifâ€™ function.
In our example, we will use this function to display the word â€˜aboveâ€™, or the word â€˜belowâ€™, depending on whether or not the closing price is greater than the 30 period simple moving average. Within the Commentary text box type the following:
<symbol> is presently trading writeif(C> Mov(C,30,s),â€aboveâ€,â€belowâ€) a 30 <periodicity:s> simple moving average, and has been for the last writeif(C>Mov(C,30,s), â€œwriteval((BarsSince(Cross(C,Mov(C,30,s)))),3.0)â€, â€œwriteval((BarsSince(Cross(Mov(C,30,s),C))),3.0)â€) <periodicity:s>s.
In this example, by using the â€˜writeifâ€™ function, we have stipulated that after the word â€˜tradingâ€™ either the wordÂ â€˜aboveâ€™ or â€˜belowâ€™ (but not both), will be typed. The word that is to be used is dependant on whether or not theÂ expression is true. The writeif function is broken down as follows:
Expression = C>Mov(C,30,S)
Text True = â€œaboveâ€
Text False = â€œbelowâ€
Writeval(data array) OR Writeval(data array,format)
The other unique function is the â€˜writevalâ€™ function. This allows you to display the numeric value of any selected data array. Furthermore we can select the format for this value. For example, â€˜Writeval(H)â€™ will return the high value for the present period. By using this syntax, the value will be displayed with four decimal places (by default). If we wish to control the number of decimal places this can be done as follows:
In the formula above:
X = The maximum number of characters to be used for the number.
Y = The number of decimal places to be used.
Using this information, we can now place the open, high, low, close and volume data into our Commentary.
Type the following into the Commentary text box:
Open: $writeval(O,6.3) High: $writeval(H,6.3)
Low: $writeval(L,6.3) Close: $writeval(C,6.3)
Notice for all these prices, we have limited them to 3 decimal places. The only exception was the volume where we have specified a whole number by using the syntax â€˜writeval(V,10.0)â€™.
With the use of both the writeif and writeval functions, our Commentary preview screen should look something like this:
Above the Commentary text box, there is a group of formatting tools. At first glance you may be familiar with these since theyâ€™re very similar to those used in Microsoft Word. These formatting tools are shown below:
Basically, these buttons allow us to modify the appearance of the text in our Commentary. We can alter everything from the fonts used to their colours. Using the formatting tools allows our Commentary to come alive and will add value to our analysis. For example, in Commentary we could have the words â€˜aboveâ€™, â€˜higher thanâ€™, and â€˜increasedâ€™ all in bold green text while their opposites could all be in bold red. These simple changes will add a new effectiveness to any Commentary.
With the most complex component out of the way letâ€™s look at Highlights. As a reminder, Highlights change the colour of price bars when certain technical conditions are met. If we click on the Highlights tab from within the Expert Editor, you will see a window resembling the one below:
Notice that there are several buttons on the right hand side of the window, of which only one is available, â€˜Newâ€™. By clicking â€˜Newâ€™ button we will open the â€˜Expert Highlight Editorâ€™. From here we can name the Highlight, and define the condition that the Highlight is looking for. For our expert advisor letâ€™s insert a Highlight called â€˜Low Turnoverâ€™, with the formula as follows:
This formula identifies when a securityâ€™s turnover is less than $200,000. Since we consider this condition as negative, letâ€™s change the colour of the Highlight to red.
As a result, your â€˜Expert Highlight Editorâ€™ should look like this:
We can also add another Highlight. Perhaps one based on a 30 period simple moving average. Our goal is to have the Highlight change the colour of the price bars should the closing price cross above the moving average. Â Since we see this condition as positive, letâ€™s select its colour as green. This is coded as follows:
Click â€˜OKâ€™, and now within the expert editor there should be two separate Highlight entries, these are shown below:
Theoretically, you can place an infinite number of Highlights within the same expert. You can then rank these in the order of importance. To do this simply use the up and down arrows to rank the Highlight as you wish. The reason we must rank our Highlights is because two Highlights cannot be applied to the same chart at once. If two conditions occur for the same period, the Highlight that ranks higher will take precedence and be applied.
There is one more important point to note; there is a check box to the left of the Highlight name which allows us to literally turn on or off individual Highlights. This avoids the need to delete them. We can simply activate, or deactivate, them as we wish.
Symbols are placed either above or below the price plot when certain technical conditions are met. These Symbols can also be labelled to assist in their identification. If you click on the Symbols tab within the Expert Editor, the window below appears:
You will notice that the Symbols tab is similar to the Highlights section, in fact, itâ€™s almost identical. Click â€˜Newâ€™ to open the â€˜Expert Symbol Editorâ€™. For our example, we are going to insert a Symbol called â€˜Main Triggerâ€™, with a formula as follows:
C>Ref(HHV(H,60),-1) AND C>Mov(C,50,S)
Within the â€˜Expert Symbol Editorâ€™ dialog, there is also a â€˜Graphicâ€™ tab. Within this tab, we can select the Symbol that will be used when the technical condition is met. Moreover, we can also decide on its size, colour and any label that appears. In the case of our expert advisor, we have selected a medium size, buy arrow and have labelled it with â€˜Buyâ€™. The label and symbol shall be positioned below the price plot.
The â€˜Expert Symbol Editorâ€™ should now resemble below:
Similar to the Highlights, we can place an infinite number of Symbols; however, remember that if two conditions occur at the same time the Symbol that ranks higher will take precedence and be applied to the chart.
We have now completed four of the five comonents within our expert advisor; letâ€™s apply this to a chart to review our progress. Close the â€˜Expert Symbol Editorâ€™ and the â€˜Expert Editorâ€™ dialog, and then attach our new expert advisor to the chart. Notice on the chart below that there is now a trend ribbon, some Highlights and some Symbols labelled â€˜Buyâ€™.
Alerts activate a small pop-up box over the chart alerting us to the fact that a certain technical condition has occurred in the present period, (i.e., in the last price bar). By clicking on the Alerts tab from within the â€˜Expert Editorâ€™ the follow dialog appears:
Notice that the Alerts section is identical to the Highlights and Symbols section. Click â€˜Newâ€™ and the â€˜Expert Alert Editorâ€™ will open. In our example, we are going to insert an Alert called â€˜Low Liquidityâ€™, and the formula is as follows:
Within the â€˜Expert Alert Editorâ€™ dialog, there is also an â€˜Alertâ€™ tab next to the â€˜Nameâ€™ tab. With this tab we can specify what action to take, should the condition be met. We can choose from three options: enter text, select a video or select an audio file. In our example, we are going to place a text Alert, thus write into the message box, â€œThis stock is illiquid and should be avoidedâ€. Once this information is entered, click â€˜OKâ€™ and we return to the main â€˜Expert Editorâ€™ dialog.
In our example weâ€™ll add two more Alerts which will be activated should the security achieve a 20 period high, or 20 period low. The formula used is as follows:
The Alert text used would be, â€œThis security has achieved a new 20 period highâ€. The formula used to achieve the 20 period low is:
The Alert text used would be, â€œThis security has achieved a new 20 period lowâ€. Please note that these are two separate Alerts, and once entered, the â€˜Expert Editorâ€™ dialog should look like this:
Similarly to the Highlights and Symbols sections we can create an infinite number of Alerts; however unlike the other components, if two Alerts are triggered for the same period then the Alert that ranks first will be shown first. That said, as soon as you close this Alert, the next applicable Alert will be shown.
When an Alert is triggered, a small pop-up box appears over the chart, shown below:
Working with Expert Advisors
When first creating an expert advisor it can be quite time consuming; however, once set up, we can quickly and easily apply it to any chart we wish. This is done by simply opening a chart, opening the â€˜Expert Advisorâ€™ dialog, selecting the expert that you wish, clicking â€˜Attachâ€™ and then closing The â€˜Expert Advisorâ€™ dialog. By following these simple steps The Expert Advisor becomes active and any Trend Ribbon, Highlights, Symbols and/or Alerts are displayed. Just remember though, you can only attach one expert to a chart at any one time. That said, if you wish to deactivate an expert, simply open The Expert Advisor dialog again and click â€˜Detach.â€™
With so many options and possibilities to choose from, the Expert Advisor can be quite complex, however itâ€™s well worth learning about. This is one of the little used gems within Metastock. So, load up The Expert Advisor, fiddle around and learn from the experience.