Swiss Army Knife Indicator
Swiss Army Knife Indicator
Swiss Army Knife Indicator
John F. Ehlers
The indicator I describe in this article does all the common functions of the usual
indicators, such as smoothing and momentum generation. It also does some
unusual things, such as band stop and band reject filtering. Once you program
this indicator into your trading platform you can do virtually any technical analysis
technique with it. This unique general indicator results from general Digital
Signal Processing (DSP) concepts for discrete signal networks that appear in
various forms in technical analysis.1
The Transfer Function of a discrete linear system is the ratio of the output of the
system divided by the input. Since both the output and input can be described in
terms of polynomials in the Z domain, we can write the Transfer Function of a
very simple indicator where as:
Output b 0 b1 Z 1
Input a 0 a 1 Z 1
In this case, both the input and output involve only a constant term and a term
having one unit of delay. By cross multiplying and factoring, we can describe the
output in terms of the input as:
1
Output
a0
* b0 * Input b1Z 1 * Input a1Z 1 * Output
This equation is easily converted to indicator programming languages. For
example, in EasyLanguage, “N” units of delay is denoted by [N] after the variable.
Thus the Transfer Function programs to:
1
Output * b0 * Input b1 * Input [1] a1 * Output [1]
a0
1
This article was inspired by “The Swiss Army Knife of Digital Networks”, Richard Lyons and Amy
Bell, IEEE Signal Processing Magazine, May 2004, pp 90-100
Suppose that a0=1, b0=, b1=0, and a1=-(1-). In this case, the programmed
equation is:
With this introduction, you are ready for the Swiss Army Knife Indicator. The
transfer response is a rational expression of two second order polynomials as:
Output b b1 Z 1 b 2 Z 2 N
c 0 0 1
c 1 Z
Input 1 a 1Z a 2 Z 2
You have already been exposed to the EMA. The complete coefficient set is
c0 c1 N b0 b1 b2 a1 a2
EMA 1 0 0 0 0 (1-) 0
But what does mean? Alpha is commonly related to the equivalent smoothing
of a Simple Moving Average (SMA) of length L as:
2
L 1
If you tend to think of the market data in terms of its frequency content as I do,
the relationship between alpha and the cycle period where the corner of the
attenuation starts is:
2 2
Cos Period Sin Period 1
2
Cos
Period
In EasyLanguage, Sines and Cosines are computed in degrees rather than in
radians, and therefore 360 should be substituted for 2. As a check on your
math, if we want to attenuate all cycle components shorter than 20 bars, we
compute = .2735. This is roughly equivalent to a six bar SMA.
A simple moving average sums “N” samples of data and divides the sum by N. A
more efficient method of computing a SMA is to drop off the oldest term and add
the newest data value divided by N. To implement this method of computing an
SMA of length N, the coefficients of the Swiss Army Knife Indicator are:
c0 c1 N b0 b1 B2 a1 a2
SMA 1 1/N N 0 0 1 0
A Gaussian Filter offers a very low lag compared to other smoothing filters of like
order. (The order is the largest exponent in the transfer equation). It can be
implemented by taking an EMA of an EMA, but that method leaves the
computation of the correct alpha to be a little nebulous. The double EMA is the
equivalent of squaring the Transfer Response of an EMA. Therefore, the
coefficients of the Swiss Army Knife Indicator for the two pole Gaussian Filter
are:
c0 c1 N b0 b1 B2 a1 a2
Gauss 0 0 0 0 2(1-) -(1-)2
The correct value of alpha is related to the cutoff period that you wish to
attenuate. It can be computed as2:
2
John Ehlers, “Rocket Science for Traders”, John Wiley & Sons, page 161
2
2
2
where 2 . 415 1 Cos
Period
Please note that alpha has a different meaning than it did in the EMA equation.
The same is true for beta in subsequent calculations.
c0 c1 N b0 b1 b2 a1 a2
Butter 0 0 2 1 2(1-) -(1-)2
While trivial, but shown for completeness, a low lag three tap smoothing filter is
obtained by eliminating the higher order terms in the denominator of the Transfer
Response. This smoother is implemented using the coefficients:
c0 c1 N b0 b1 b2 a1 a2
Smooth 0 0 2 1 0 0
The smoothing realized from this filter is extremely modest, rejecting only the 2
bar cycle component.
A High Pass Filter is the more general version of a momentum function. Its
purpose is to eliminate the constant (DC) term and lower frequency (longer
period) terms that do not contribute to the shorter term cycles in the data.
c0 c1 N b0 b1 b2 a1 a2
HP 1-/2 0 0 -1 0 (1-) 0
Alpha for the High Pass Filter is computed exactly the same as it is for the EMA.
That is:
2 2
Cos Sin 1
Period Period
2
Cos
Period
Two Pole High Pass Filter
Just as we got sharper filtering by squaring the Transfer Response of the EMA to
get a Gaussian Low Pass Filter, we can square the Transfer Response of the
High Pass filter to improve the filtering. In general, there is an approximate one
bar lag penalty for obtaining the improved filtering. The Swiss Army Knife
Indicator coefficients are:
c0 c1 N b0 b1 b2 a1 a2
2PHP (1-)2 0 0 -2 1 2(1-) -(1-)2
Alpha is computed exactly the same as for the Gaussian response. That is:
2
2
2
where 2 . 415 1 Cos
Period
Figure 2 shows the same theoretical “chirped” sinewave and the 2PHP response.
The Period for the 2PHP Filter is set at 20, which is near the center of the screen.
Figure 2 shows that the 2PHP Filter is a High Pass filter, allowing the higher
frequencies to pass and attenuating the lower frequencies.
This is where the Swiss Army Knife Indicator really starts to get interesting! It
can generate bandpass response to extract only the frequency component of
interest. For example, if you want to examine the weekly cycle in the data, just
set the period to 5. Monthly data can be extracted by setting the period to 20, 21,
or 22. Since the passband of the filter is finite, the exact setting of the center
period is not crucial.
Another way to use the BandPass Filter is to create a bank of them, separated by
a fixed percentage, and display all of the filter outputs as an indicator set. Doing
this, you can see at which filter the data peaks the strongest. For filters tuned to
periods shorter than the dominant cycle in the data, the filter response will peak
before the peak in the data. Filters tuned to periods longer than the dominant
cycle in the data, the filter response will peak after the peak in the data. This
way, you can estimate the current dominant cycle and, if the data are stationary,
you can even predict the turning point.
The Swiss Army Knife Indicator coefficients for the BandPass Filter are:
c0 c1 N b0 b1 b2 a1 a2
BP (1-)/2 0 0 0 -1 (1-)
In this case,
2
Cos
Period
Don’t forget to substitute 360 for 2 in some languages. So, if you wanted to
examine monthly data, the value of Beta would be 0.951.
The selectivity of the BandPass filter is established by the variable alpha. Alpha
is a function of the center frequency of the filter as well as the width of the
passband. Letting be the descriptor of the filter passband, where is a
percentage of the center, we can compute alpha as:
1 1
2
1
4
where Cos
Period
It is easy to get carried away with trying to make the BandPass Filter passband
either be too narrow or too wide. As a guideline, I suggest keeping the half
bandwidth between 5 percent and 50 percent. That is 0.05 < < 0.5.
Figure 3 shows the same theoretical “chirped” sinewave and the Bandpass
response of the Swiss Army Knife Indicator. The Period for the BandPass Filter is
set at 20, which is near the center of the screen. The BandPass response
speaks for itself.
BandStop Filter
c0 c1 N b0 b1 b2 a1 a2
BS (1+)/2 0 0 -2 1 (1+)
Figure 4 again shows the same theoretical “chirped” sinewave, but with the
BandStop response of the Swiss Army Knife Indicator. The Period for the
BandStop Filter is set at 20, which is near the center of the screen. The
BandStop response speaks for itself.
Figure 4. BandStop Response Blocks a Range of Frequencies
Fourier Transforms are useless for Technical Analysis because the data are
simply not stationary for a sufficient duration to make a valid estimate of the
spectrum. Vastly superior spectrum estimates can be made with the MESA 3
algorithm or measurements of the dominant cycle can be made using the Hilbert
Transform4. I include the description of the DFT here simply to show that it can
be done with the Swiss Army Knife Indicator. The coefficients are:
c0 c1 N b0 b1 b2 a1 a2
DFT rej rN rej N 0 0 0
For stability, r is any number slightly less than unity – like 0.999. As with all
Fourier Transforms, analysis is performed only at discrete periods. Those
periods are “k” where k <= N, and the variable theta is computed as = 2k/N.
3
John Ehlers, “MESA, and Trading Market Cycles, 2nd Ed”, John Wiley and Sons
4
John Ehlers, “Cybernetic Analysis for Stocks and Futures”, John Wiley and Sons
SUMMARY
The Swiss Army Knife Indicator is a versatile approach that creates a wide
variety of responses that range from smoothers to oscillators. Novel BandPass
and BandStop filters can also be produced. All of this can be done with one line
of code in most platforms. The various responses come from the coefficients
that can be called – as functions if you prefer. In Figure 5 the EasyLanguage
formulation shows the coefficients as variables that are initialized to the default
values and are changed in block conditional statements. This makes indicator
programming extremely simple. Table 1 summarizes the coefficients for the ten
separate and distinct responses that can be generated from the single Swiss
Army Knife Indicator.
Inputs:
Price((H+L)/2),
Type("BP"),
N(0),
Period(20),
delta1(.1);
Vars:
c0(1),
c1(0),
b0(1),
b1(0),
b2(0),
a1(0),
a2(0),
alpha(0),
beta1(0),
gamma1(0),
Filt(0);
Combinations of several Swiss Army Knife outputs can also make a wide variety
of new and unique indicators. For example, a MACD is just the difference of two
EMAs. Why not try the difference of two Gaussian Filters to get sharper filtering
in the indicators? Even more interesting, why not try the difference of two
BandPass filters – one a longer period center and the other a shorter period
center – to eliminate even more unwanted junk from the data? An interesting
predictive oscillator can be obtained by plotting two BandPass filter differences,
one having a slightly shorter set of periods than the other. The list goes on and
on. For example, the difference of two BandStop filters is exactly out of phase
with the difference of two BandPass filters with the same settings. Novel
combinations of BandPass and BandStop filters could produce some highly
illuminating indicators.
I hope I have met my goal of giving you an interesting new tool to use in your
Technical Analysis, and perhaps some ideas on how you can make your own
unique indicator.