Nov
4

Formula 201 – #4 Using Indicators

The ability to reuse existing indicators within your formula is one of the most powerful feature of the formula language. Your formula indicators can in turn be reused by other indicators once they are installed into NeoTicker. This creates a very flexible environment for the development of complex indicators from simpler building blocks.

Your Own Customized Moving Average Indicator

Standard moving average indicator applies onto the close of the data series. What if you are interested in the average of the typical price, the one we have worked on in the first Formula 201 tutorial.

To remind you what that formula indicator MySpecialPrice looks like, here is the formula,

plot1 := (o + h + l + c) / 4

So, if we are going to apply moving average onto this indicator, there are 2 ways to proceed.

First, we can do that visually by adding the MySpecialPrice indicator first, then add a simple moving average indicator that links to our MySpecialPrice indicator instance in the chart.

Second, we can create an indicator of our own that calculate the simple moving average based on exactly what MySpecialPrice does. I am going to show you how this can be done.

My Special Average

We will create the indicator MySpecialAverage.

Here is the Indicator Specification.

formula201 part4 indicator sepc

And the formula looks like this.

formula201 part4 script editor

The function average is an indicator function.

Indicator Functions take on the following general form,

IndicatorName (BarsAgo, Link1, Link2, ..., Param1, Param2, Param3, ...)

IndicatorName is the function name of the indicator, like the one we are defining, MySpecialAverage. All indicators must have their own unique names within NeoTicker so that they can be identified easily. In this case, the IndicatorName is average which is the function name of the Simple Moving Average indicator.

BarsAgo specifies the number of bars ago to return the value from within the series. When BarsAgo equals to zero, as in this case, it can be omitted from the formula.

Link1, Link2, Link3, etc. are called the Link Specification of the indicator function. For all indicators, they must have at least one linked series. If you set the indicator to have 2 linked series, similar to the indicator Simple Spread we talked about in the previous tutorial, you will need to provide 2 linked items in the Link Specification.

In our formula, there is only one linked item, (o + h + l + c) / 4. NeoTicker understands that you want to apply the simple moving average indicator onto this expression. It can automatically take care of the calculations required by the expression and in turns, it will use the simple moving average indicator to calculate the results you want.

Param1, Param2, Param3, etc. are called the Parameter Specification of the indicator function. Similar to the Link Specification, each indicator is already predefined with a fixed number of parameters. For example, the simple moving average indicator takes only one parameter Period.

Since we are interested in creating an indicator similar to the simple moving average, we want the indicator to be able to change its period settings. So, we pass the parameter from our indicator MySpecialAverage, as the parameter specification of the simple moving average.

Once you installed the indicator, you can use it within a chart. Here is an example.

formula201 part4 chart

To use the indicator within a quote window, you can type the following formula into a quote window formula column,

MySpecialAverage (M5, 10)

It will calculate MySpecialAverage based on the 5-minute series.

Nested Indicators

I have mentioned that indicators that we have written can be reused within other indicators. In the example above, we already reused the built-in indicator Simple Moving Average.

We can actually do the same thing with the indicators we have defined with formulas.

Let’s create another indicator called MySpecialAverage2.

Here is the Indicator Specification.

formula201 part4 indicator sepc2

The main difference from the indicator we have just created is change of the function name and description.

Here is the code.

formula201 part4 script editor2

Notice (o + h + l + c) / 4 is replaced with MySpecialPrice (data1).

We have reused the indicator we have defined from the previous tutorial.

This approach of using one indicator within another is called Nested Indicators. Many programmable tools have a limit on the number of times that you can nest the indicators. NeoTicker does not impose any such restrictions. You can nest your indicators as many times as you like.

Here is a chart comparing the original MySpecialAverage indicator against MySpecialAverage2.

formula201 part4 chart2

They are exactly the same.

Utilize Indicator Wizard

An immediate question about using exsiting indicators is where to find a list of the indicators with their specifications.

The reference is right at your fingertips.

If you want to see the syntax only, you can use the Indicator Quick Reference that can be opened from the Help menu in the script editor or in the NeoTicker main program window.

If you want to use an interactive tool to contruct the exact syntax of the indicator for you, you can use the Indicator Wizard accessible from within the script editor, under the Tool menu.

Users who spent sometime reading Formula 101 have already used the Indicator Wizard for constructing quote formulas. When Indicator Wizard is launched within the script editor, it knows that it is working on indicator formula and can generate the correct syntax.

Another common question is how do I know which indicator to use?

That is a very good question. In fact, the only way to find out is to apply the indicators to the chart and study them carefully so that you have a good idea what the indicators do.

Summary

The ability to utilize existing indicators for the creation of your own is a very important step towards constructing more powerful indicators. It is important that you experiment with various combinations of the indicators to get yourself familiar with the language.

Complete Indicators

My Special Average.

My Special Average 2.

Exercise

1. Define a triple smoothing moving average.

2. Define another variation of the MySpecialAverage2 indicator, with the added ability to choose the moving average type. (Hint – look for an existing indicator that can change moving average type)

Answers For Previous Exercise

1. If we do not restrict the combined weighting, then the formula looks like this,

plot1 := (data1 * param1 + data2 * param2 + data3 * param3 + data4 * param4 + data5 * param5) /
(param1 + param2 + param3 + param4 + param5)

3. The boolean expression is pretty simple,

plot1 := time (1) < param1 and time >= param1

Discuss this article.

Leave a Comment

Blog Developed
By ContentRobot