Experiments in Technical Analysis

karthikmarar

Well-Known Member
Thank you Asish for your information on hindsight indicators. Do you have any clue as to what indicator could be used instead of hindsight indicators such as Zig Zag/Peak in order to establish the trend? I've found that the system (K1) will work well in trending periods, but not in ranging periods.

Karthik, I'd love to hear your thoughts on this.

Regards,
Jrgen T.
Hi Jorgen

Yes it is true that Mabiuts K1 works well in a trending market . The idea behind this system was keep one away in a ranging market. I will explain a bit. The value y in the afl is a adaptive EMA. Based on the ADX or RAVI value the EMA factor is adjusted. Below a certain value of the ADX (which indicates a non trending market) the factor is pegged to a constant so that the EMA becomes a straight line. The BUY condition is when the y is greater that a signal line which is an EMA (6) of the y itself. In a ranging market y becomes a straight line and the EMA of y along becomes a straight line. So there will be no buy condition. You can try to change the BUY condition to get better result.. for example ROC(y) > x.

Next let us see the purpose of the peak function. This function tries to ensure that the stock is making a higher high, which is the basic definition of Trend. May be we should check if the stock has already made a higher low. May be this will improve the system a bit.

I did some analysis of your test result. First I really appreciate the big effort. It was must have consumed quite a bit of your time. Looking at results the percentage of green signals is quite high compared to the orange signals. Most orange signals went down later. I wonder what happened to the green ones. Did they go up? If they did then the success rate of the system is quite OK. Of course we cannot have a 100% success rate. Fortunately the red signals are minimal. Overall the system seems to be OK and should given good results with proper MM.

A combination of EMA and ADX could be used to establish the trend. Even better the slope of the EMA line with ADX.. what do you think?

Warm regards

Karthik
 

asnavale

Well-Known Member
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
 
Last edited:
Hi Raj,

The AFL I had attached was for using as an indicator. For Exploring and backtesting you have to change it slightly. I don't know whether you have made the necessary changes. I am attaching the AFL required for Exploring/backtesting with this message. Try this AFL and give your feedback. This AFL has only Buy and Sell codes. There are no separate Short/Cover codes. Short is same as Sell and Cover is same as Buy.

Note that the attached file has .txt extension which should be changed to .afl before using in AmiBroker.

To use the AFL to include MACD also, set the MACD selection switch appropriately in Exploration window parameters before running Exploration/Back testing.

It is possible to add The price to the charts but it works only in AmiBroker version 4.8 and higher. Therefore I did not add the code so that users with lower versions can also use it. I can give you the additional code also but please let me know which price you want to display? Is it Open or Close or any other?
Regards

-Anant
Mr.Anant
Thanks for ur reply, I downloaded the file and tried backtesting it, but again i found a blank report. I have attached the report here, please guide me where i am wrong.
Raj
 

asnavale

Well-Known Member
Mr.Anant
Thanks for ur reply, I downloaded the file and tried backtesting it, but again i found a blank report. I have attached the report here, please guide me where i am wrong.
Raj
Hi Raj,

From the file attached I can not make out what you were trying out. I mean, which stocks were tested, for which period, what are the backtest settings etc. If possible please give the details and I can check the same at my end and find out what is the problem. Thanks for your interest in testing the system.

Regards

-Anant
 
Hi Raj,

From the file attached I can not make out what you were trying out. I mean, which stocks were tested, for which period, what are the backtest settings etc. If possible please give the details and I can check the same at my end and find out what is the problem. Thanks for your interest in testing the system.

Regards

-Anant
Anant
I tried to backtest nifty charts for daily periodicity. I have enclosed my backtesting settings and report, I know i am not correct, pls guide, where i am wrong.
Raj
 

asnavale

Well-Known Member
Anant
I tried to backtest nifty charts for daily periodicity. I have enclosed my backtesting settings and report, I know i am not correct, pls guide, where i am wrong.
Raj
Hi Raj,

Can you upload the last page of your report. The page labelled Symbols?

Regards

-Anant
 

Similar threads