CONTINUING WITH MACD
Hello friends,
In my earlier post had promised to post the Zero Lag MACD. I had prepared the write-up a few days back. Generally, I show my important write-ups to my friends for their comments before posting. When I showed the Zero Lag MACD write-up to them, they were of the opinion that I should first go into the details of MA lag and methods of removing the lag so that it helps in understanding the Zero Lag MACD. Therefore, I had to revise the write-up and there was delay. Now I am going into the details of MA lag.
MACD is made of two moving averages - one long period Exponential Moving Average and one short period Exponential Moving Average (EMA). The signal line is also a Moving Average. Although there are three EMAs we actually plot two of them, The difference of Short and Long EMAs as MACD line and the EMA as SIGNAL line. As MACD is based on Moving Averages, the advantages and disadvantages of Moving averages are also reflected in MACD. Therefore it is advantageous to study the properties of Moving Averages a little deeper.
Any trader learning Technical Analysis (TA) is first introduced to Moving Averages. Moving averages can be considered as the foundation of Technical Analysis. Two important characteristics of Moving averages are:
- They smooth the data
- They lag the data in showing peaks and troughs
Therefore, although the MAs are simple to calculate and interpret, their application is always a trade off between the above two characteristics. If we try to smooth the data more, the lag is also more and vice versa. Smoothening the data means reducing the high variations or filtering the noise. (Those who are familiar with Electrical/Electronics Engineering can consider this as a low pass filter).
The Moving Average Lag is most important characteristic which affects the traders. To reduce/remove this lag we should understand how the lag is introduced. I am explaining this with the help of attached Example-7. In this figure the black dots represent closing price of an Imaginary Stock. For the sake of simplifying the explanation we assume that the data is uniformly increasing or decreasing. That means the difference between two consecutive points is equal throughout. To calculate Simple Moving Average (SMA) for a given period 'p' at any given point we add the current value and all the PREVIOUS (p-1) values and divide the sum by 'p' and put the resulting average value under the current point (The gray colored points in Example-7). We do it for each point in the data set and join the resulting average points to get the Moving Average line. Now look at this process in a different way with the help of the Example-7. Draw a rectangle on the graph such that the current point is on the right end of the rectangle and the previous (p-1)th point is on the left end. The width of rectangle is the period 'p' of averaging. To calculate MA for each day we go on shifting this rectangle to the right one point (or price bar) at a time.
As the points are equally spaced the Average of the points included in the rectangle will be at the center of the rectangle. But we plot this average under the current point. That means we shift it horizontally from the center to the right edge of the rectangle without changing the vertical position. Therefore the shift is equal to half of the width. This shifting is nothing but the Lag of the MA. In other words the Lag is equal to half of the averaging period.
There are two ways to reduce this lag. The first is to produce an equal lag in opposite direction and add to the present lag. Opposite lag can be produced by taking the MA from right to left. That is start calculating the MA starting from latest bar and go towards previous bars. For example, to calculate today's 10-day MA, we add today's price and the prices of next 9 days. This needs future bars which are not available. So this method does not work.
Another way is as follows. Produce another MA with a lag double that of the present lag. So, If we have MA which gives a lag of 'L' days, we take MA which produces a lag of '2L' days. As lag is half of averaging period, the second MA has a period double that of first MA. This is shown in attached Example-8.
Now take difference of the two MAs and add the difference to the shorter period MA. The result is Zero Lag MA.
Code:
Short period MA gives Lag = L
Long period MA gives Lag = 2L
Difference in the Lags = L - 2L = (-L)
Add this to first Lag = L + (-L) = L - L
Total Lag = L - L = 0
The result of this calculation is shown in attached Example-9. In this figure the dashed line is MA and the continuous line is Zero Lag MA (ZLMA). We can see how nicely the Zero Lag MA fits the price chart. Only at the peaks and troughs the ZLMA deviates from the price line for a short distance and then again merges with the price.
For EMA also the same strategy can be adopted to produce Zero Lag EMA (ZLEMA). In the next post I will deal with the construction of Zero Lag MACD.
Regards
-Anant