A Recursive Indicator Building Indicator

The point and click Indicator Wizard cannot create recursive indicators, that is, indicators that use previous values of that same indicator being built in the formula for new values. Therefore you may have to program the indicator (as most other software products require for ALL indicators, even though they don’t usually call their languages “programming”). Recursion is part of most modern programming languages. However, here we provide another alternative, an indicator building indicator we have created, which we have named “Recursive”. If you feel you cannot program yourself, Recursive may help you build recursive indicators, but it is not guaranteed to build ALL recursive indicators.

First let’s talk about recursion. Suppose there is an indicator formula like:

X = (close + X one bar ago + X two bars ago) / 3

This cannot be calculated in the Indicator Wizard because there is no way to represent X some number of bars ago within the formula that is actually building X. This is a recursive formula, and we’ll have to use 0 for the first two calculations of X. So the calculation bar by bar becomes:

bar 1 X1 = (close1+0+0)/3 = close1/3
bar 2 X2 = (close2+X1+0)/3 = (close2+X1)/3
bar 3 X3 = (close3+X2+X1)/3
bar 4 X4 = (close4+X3+X2)/3
etc.

The Recursive indicator is a general “template”

Recursive = (c1*series1 + c2*series2 + c3*series3 + c4*R1 + c5*R2 + c6*R3)/c7

where

   * means "times" (multiplication)
   / means "divided by"
   c1, c2, ... , c7 are numeric constants
   series1, series2, and series3 are any time series or indicators
   R1 is the value of Recursive one bar ago
   R2 is the value of Recursive two bars ago
   R3 is the value of Recursive three bars ago

Note1: for maximum flexibility, c1, …, c7 can be indicators or other time series as well as constants. Likewise series1, series2, and series3 can be constants if you want.

Note2: If c7 = 0 then the result from Recursive will be 0

Note3: If your indicator has no division just set c7=1

The Recursive indicator is called by the parameters as follows:

Recursive(c1, series1, c2, series2, c3, series3, c4, c5, c6, c7)

Example 1

If any of the parameters are not to be utilized, just set its corresponding constant parameter to zero. Therefore the X indicator above is created in Recursive as follows:

Recursive = (1*close + 0*0 + 0*0 + 1*R1 + 1*R2 + 0*R3)/3

The Recursive representation for X is actually called this way:

Recursive(1, close, 0, 0, 0, 0, 1, 1, 0, 3)

Example 2

The second example is an indicator used in the Heikin-Ashi candlestick technique (Technical Analysis of Stocks and Commodities tip December 2008):

haClose = (O+H+L+C)/4
haOpen = (haOpen (previous bar) + haClose (previous bar))/2

Using Recursive the formula for haOpen is simply:

Recursive = (1*Lag(haClose,1) + 0*0 + 0*0 + 1*R1 + 0*R2 + 0*R3)/2

and it is called like this:

Recursive(1, Lag(haClose,1), 0, 0, 0, 0, 1, 0, 0, 2)

To download the .DLL and .TPL files for recursive click here. Store them in the NeuroShell Template folder, and the Recursive Indicator will show up in the Recursive Category after you reload NeuroShell.

To download the PowerBasic source code for recursive, click here.

Was this article helpful?

Related Articles