005smo PDF
005smo PDF
INDICATORS
we will refer to as n, of previous The only way a perfect moving average could be computed
closing prices, recalculated each is to have knowledge of the future, and if we had that, we
day at the close. And second, technicians use moving aver- would buy one lottery ticket a week rather than trade! That
ages because the moving average offers a smoother visual aside, we can still improve on conventional simple, weighted,
image of the market trend. In effect, the moving average or exponential moving averages.
removes the noise around the trend.
This concept of eliminating noise from the trend is similar TWO BENCHMARKS
to what engineers strive for in their application of digital We will examine two benchmark moving averages based on
filters. As R.W. Hamming observed: linear regression analysis. In both cases, a linear regression
line of length n is fitted to price data. The first benchmark
Digital filtering includes the process of smoothing, predicting,
moving average (MA) is called ILRS, which stands for inte-
differentiating, integrating, separation of signals, and removal of
noise from a signal. Thus many people who do such things are
gral of linear regression slope. In this moving average, the
actually using digital filters without realizing that they are; being slope of a linear regression line is simply integrated as it is
unacquainted with the theory, they neither understand what they fitted in a moving window of length n across the data. The
have done nor the possibilities of what they might have done. derivative of ILRS is the linear regression slope. ILRS is not the
same as a simple moving average (SMA) of length n, which is
This quote applies to the vast majority of indicators in actually the midpoint of the linear regression line as it moves
technical analysis. Moving averages, be they simple, weighted, across the data.
or exponential, are low-pass filters; low-frequency compo- We can measure the lag of moving averages with respect
nents in the signal pass through with little attenuation or to a linear trend by computing how they behave when the
reduction, while high frequencies are severely reduced. Os- input is a line with unit slope. Both SMA(n) and ILRS(n) have
cillator-type indicators, such as moving average conver- lag of n/2, but ILRS is much smoother than SMA.
gence/divergence (MACD), momentum and relative strength Our second benchmark is the end point moving average
index, are another type of digital filter referred to as a (EPMA). It is the endpoint of the linear regression line of
differentiator. length n as it is fitted across the data. EPMA hugs the data more
Early in the steps of calculating any of these indicators, the closely than a simple or exponential moving average of the
difference between today’s price and some price a number of same length. The price we pay for this? EPMA is much noisier
days ago or the difference between two moving averages are than ILRS, and it also overshoots the data when linear trends
measured — hence the term. STOCKS & COMMODITIES Con- are present, as can be seen in Figure 1.
tributing Editor Tushar Chande has observed that many However, EPMA has a lag of zero with respect to linear
popular oscillators are highly correlated, which makes sense, input! This makes sense because a linear regression line will
because they are measuring the rate of change of the under- fit linear input perfectly, and the endpoint of the LR line will
lying time series. be on the input line.
These two moving averages frame the tradeoffs that we EPMA. Can we build something that is comparable, but
ANDREW VANDERKARR
are facing. On one extreme we have ILRS , which is very smoother? Figure 1 shows ILRS, EPMA and IE/2.
smooth but has considerable phase lag. At the other ex-
treme, EPMA has zero phase lag, but it is too noisy and FILTER TECHNIQUES
overshoots. We would like to construct a better moving Any student of filter theory would be able to tell you that
average that is nearly as smooth as ILRS , but runs closer to the smoothness of a filter could be improved by running it
where EPMA lies, without the overshoot. through itself multiple times, at the cost of increasing
A easy way to do this is to split the difference — that is, phase lag.
use (ILRS(n)+EPMA(n))/2. This will give us a moving There is a complementary technique (called twicing by J.W.
average (call it IE/2) that runs in between the two, has Tukey, author of Exploratory Data Analysis) that can be used to
phase lag of n/4 but still inherits considerable noise from improve phase lag. If L stands for the operation of running data
FIXING OVERSHOOT
An n-day EMA has smoothing The problem with this approach is that multiple runs
constant alpha=2/(n+1) and a though these filters increase their tendency to overshoot† the
lag of (n-1)/2. Thus, EMA(3) data, giving an unusable result. This is because the amplitude
has lag 1, and EMA(11) has response of DEMA and EPMA is greater than 1 at certain
lag 5. Figure 2 shows that if I frequencies, giving a gain of much greater than 1 at these
am willing to incur five days of frequencies when run though themselves multiple times.
lag, I get a smoother moving average if I run EMA(3) through Figure 3 shows DEMA(7) and EPMA(7) run through them-
itself five times than if I just take EMA(11) once. This suggests selves three times. EPMA3 has serious overshoot, and DEMA3
that if EPMA and DEMA have zero or low lag, why not run fast similarly has problems.
versions (for instance, DEMA(3)) through themselves a num- The solution to the overshoot problem is to recall what we
ber of times to achieve a smooth result? are doing with twicing:
METASTOCK IMPLEMENTATIONS
MetaStock 6.5 code for ILRS: Running the filter though itself three times is equivalent to
cubing f:
{input number of lookback periods, default is 11}
periods:=Input(“Periods? “,2,63,11); –a 3 x 6+ 3a 2+3a 3 x 5+ –6a 2–3a–3a 3 x 4+ 1+3a+a 3+3a 2 x 3
f : = 1 + a x – ax 2 —T.T.
DEMA(7)3
3
EPMA(7)
EMA(3)5
EMA(11)
FIGURE 2: HEWLETT-PACKARD. In MetaStock, the EMA(11) is red versus the FIGURE 3: HEWLETT-PACKARD. In MetaStock, the DEMA(7)3 is red and EPMA(7)3
EMA(3)5, which is green. EMA(11) and EMA(3)5 both have five days of lag, but is blue. When DEMA(7) and EPMA(7) are run through themselves three times,
EMA(3)5 is smoother. DEMA3 has serious overshoot, and EPMA3 similarly has problems.
DEMA(n) = EMA(n) + EMA(time series - EMA(n)) This is algebraically the same as:
The second term is adding, in effect, a smooth version of the EMA(n) * 1.7-EMA(EMA(n)) * 0.7
derivative to the EMA to achieve DEMA. The derivative term
determines how hot the moving average’s response to linear I have chosen 0.7 as my volume factor. The general formula
trends will be. We need to simply turn down the volume to (which I refer to as “generalized DEMA”) is:
achieve our basic building block:
GD(n,v) = EMA(n) * (1+v)-EMA(EMA(n)) * v
EMA(n) + EMA(time series - EMA(n)) * 0.7