Oct
23

Formula 201 – #3 A Simple Spread Indicator Using 2 Linked Series

Indicators can be linked to multiple series and perform computation across all these series, no matter the linked item is a data series or indicator series. One of the most common usage for linking with multiple series is spread analysis. I am going to show you a basic formula indicator that calculate the spread between two data series with user customizable weightings.

Defining Our Indicator

I am creating an indicator called Simple Spread.

Here is the Indicator Specification.

formula201 part3 indicator spec

The main difference between this indicator and the ones from previous tutorials is that the Links property is set to 2, while all the previous indicators have Links set to 1.

For the parameters, we need 2 of them so that we can customize the weighting for each of the linked series.

Writing the Code

The formula of this indicator looks like this.

formula201 part3 script

The data series functions data1 and data2 are refering to the first linked series (the primary series) and the second linked series respectively.

In general, we access the linked series through data series functions in the following forms,

dataN (BarsAgo)
dataN.field (BarsAgo)

Field is any of the of data series functions we talked about in the previous tutorial. That is, you can access open, high, low, close, volume, openinterest, date, time, datetime of all the linked series by attaching the proper prefix dataN. to those function names.

For example, to access the high of 1 bar ago of the second linked series, you can use data2.high (1) or data2.h (1).

You may have guessed this already, when you use data1.open or data1.o it is exactly the same as using open or o. The prefix data1. is optional.

When the function dataN is used all by itself with no field suffix, it points to the specific field of the linked series you have designated. Usually, we link the close field of a data series to an indicator, then it means the linked series is the close of the data series we have chosen. If we switch to link the high of a data series to the indicator, then the default value returned by the function is the high of the data series as oppose to the close series.

For the parameter BarsAgo, if it is equal to 0, you can omit this parameter completely.

You can download the indicator here, Simple Spread. Use indicator manager to install the downloaded script file.

Using the Indicator Within a Chart

Create a chart, and then add 2 data series to the chart. Continue from previous tutorials, I will use the daily emini S&P as the first data series in the chart, and then adding emini NQ to the chart as the second data series.

Now, add our Simple Spread indicator,

formula201 part3 indicator params

I have changed the paramters to make them match more closely in terms of actual dollar value.

We need to check the Links tab to ensure the correctness of the linked items.

formula201 part3 indicator links

Here is how the chart looks like,

formula201 part3 chart

Multiple-Link Indicators Cannot Be Used Within Quote Formulas

Multiple-link indicators are not designed for quote formulas. Thus you cannot use multiple-link indicators in quote windows, dynamic grids, etc.

(Lawrence – In the future NeoTicker may allow multiple links in quote formulas.)

Summary

Working with linked series other than the primary series is simply an extension of what we already know.

Exercise

1. Create an indicator that takes 5 links and calculate the weighted average among the linked series.

2. If you do not know what boolean expressions are, review Formula 101 – Part 4.

3. After reviewing #2, create an indicator with one time parameter than your indicator returns 1 when the primary series just crossed the time, and returns 0 for all other cases.

Discuss this article.

Leave a Comment

Blog Developed
By ContentRobot