MetaStock – The Expert Advisor

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 ‘ 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
<Name> (<symbol>)
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)
Volume: writeval(V,10.0)

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.