Experiments in Technical Analysis

SGM

Active Member
Hello

A few days back TANewBee (Yash) had proposed / discussed a crossover system that he was testing / using for intraday timeframe.

Buy = Cross (EMA(C,3),EMA(C,5));
Sell = Cross (EMA(C,5),EMA(C,3));


I decided to test it with EoD data. Imagine my astonishment when the report of Automatic Analysis in AB threw up these results (results Summary File attached: 35Open_Stats.html).

All trades --- 207
Winners ---- 168 (81.16 %)
Losers ------ 39 (18.84 %)

Annual Return % ------ 2879.86 %
Risk Adjusted Return % 4933.60 %

The results looked too good to be true, I was sure there had to be some problem. Then I kept back testing the system on different data sets, but continued to get similar results. (Was I happy to have found the Gold Mine? :D )

It took me about a week to figure out the mistake in setting :mad: (refer to image attached: Backtester_Setting.PNG)

Instead of executing the trade at close of the day the auto tester was set to execute it at opening price. In effect I had ended up configuring the system to work as Look-Ahead system; the trades were being executed taking into account future data.

Simply put the signal was generated based on the close of the day but the buy/sell prices were taken as opening prices.

After changing the settings the profit % dropped by 40 times :). This is what I got (results Summary File attached: 35Close_Stats.html).

All trades --- 205
Winners ----- 79 (38.54 %)
Losers ------ 126 (61.46 %)

Annual Return % -------- 72.90 %
Risk Adjusted Return % 116.07 %

Max. trade % drawdown -89.72 %

The 35EMA_Bk_Test.rar file also contains the afl with 3-5 EMA Crossover code.

The system does work in trending markets and would have made decent profits (100% annual) if was used during last 3 years. On the other hand the system is also capable of loosing 100% if used in a market which is sideway or is drifting downwards.

Happy Trading

Regards
Sanjay
 

asnavale

Well-Known Member
Dear Sanjay,

Before I post the second part of my studies I thought I would answer on of the points you raised regarding the crash periods. Initially I thought of answering it in the second part of my post but that part II has already become quite long and I do not want to extend it further. As you pointed out the entry at beginning of crash is really the worst thing to do. But my idea was to test exactly the same condition. Even in down trend I am adopting the same. To test the system under worst situations. In uptrend almost all systems give very good results. The details of entry are being posted today after some time. Also, imagine a new amateur trader making entry into the market. He would be itching to start trading and the market has reached the peak and about crash. But there is no information available on the impending crash. Then at the first fall of prices, our amateur trader would just grab the stocks. Then the crash continues. What he would do? Just watch his money vanish. But suppose he follows one of these strategies then where he will end up? Which strategy can take him out of troubles, if it can? This is exactly what I wanted to test. So I chose the peak of market as beginning of test period, continuing till there is recovery. I hope I made the point clear. No doubt, an entry with some open positions befor the crash gives entirely different rersults. Partly this situation is taken care in the long term test period. Jan 2005 to Sep 2006 does include the May crash. We can take these results and study.

Regards

-Anant
 

asnavale

Well-Known Member
Dear friends,

Now I explain the details of the study. I am giving a very detailed explanation. It may be boring for some of you who just want to see the results and the program codes. But you have to wait till the third part for that. These details help in two ways: firstly, for all those seniors with vast knowledge of trading and TA, it gives a chance to critically go through the results and the testing methodology. In turn they will be able to guide us more effectively by pointing out any flaws in the strategies and also suggest more effective steps to be incorporated. Secondly, for all those new entrants and those who want to take up similar studies, it gives them an opportunity to create their scenarios more effectively.

1. SELECTION OF DATABASE:

EOD data of NSE stocks is used. No BSE stocks.

2. SELECTION OF STOCKS:

I have selected 30 stocks. The selection was random. I listed all the NSE stocks alphabetically. Then I generated 30 random numbers. Random numbers can be generated easily by any programming language. Some calculators also generate random numbers. I selected those stocks whose serial number in my list matched with the random number generated. The list consists of:

ABB, ACC, ALEMBIC, AMARAJA, ASIANELEC, BAJAJAUTO, CADILLAHC, CENTBOP, COMSYS, CRANESSOFT, DABUR, DHAMPURSUG, EDUCOMP, EICHER, ESCORTS, GRASIM, HEROHONDA, HIMACHALFUT, INDSWFTLTD, INFOSYSTCH, LT, LUPIN, MASTEK, RELIANCE, SATYAMCOMP, SBIN, TAJGVK, TATASTEEL, VSNL, ZEETELE.

A couple of these stocks do not have sufficient historical data. But I have still included them because:
a) As random selection is adopted, I do not want to reject some of the selected stocks as it introduces bias in selection.
b) It also gives us a chance to see how the strategies work with a limited amount of data.

3. SELECTION OF TIME PERIODS FOR TESTING:

There are seven different conditions:
i) Long Term-I: This is from Jan 05 to Sep 06. The reason for selecting this period is my personal choice.
ii) Long Term-II: This is from Jan 02 to Jun 03. This was suggested by Sanjay. He has already explained why he suggested this period.
iii) Range bound: Every stock goes through a phase of no trend and trades in a narrow range. For each of the 30 selected stocks, I have manually scanned through the charts and selected the time period by visual inspection. No indicators like RAVI, MACD, TRENDCHK etc. were used. The only condition was that the range bound period should be at least two months.
iv) Down Trend: Again, every stock goes through a phase where its price goes on falling. For each stock this time period was also selected by visual inspection of the charts. Same condition as above, that the downtrend period should be at least two months and it should be outside the market crash period (explained below).
v) Three market crash time periods: When market crashes (the index falls rapidly) almost all stocks follow the same downtrend.
I have selected three such crashes. This selection was based on the fall in the SENSEX. The period starts with the day when the SENSEX reaches a peak value before the crash and ends with the day when it raches the lowest value and thereafter starts recovering without major falls. The following three periods were selected:
a) Feb 14, 2000 to May 23, 2000 (SENSEX fell from 6150.69 on 14-2-2000 to 3831.86 on 23-5-2000).
b) Apr 23, 04 to Jun 24, 04 (SENSEX fell from 5979.25 on 23-4-04 to 4613.94 on 24-6-04. On 15-5-04 it reached 4227.5 but the down trend continued till Jun 24).
c) The most recent fall from May 10, 2006 to Jun 14, 2006 (SENSEX fell from 12624.4 on 10-5-06 to 8799.01 on 14-6-06).

4. RULES TO BE ADHERED TO DURING TESTING:

I have imposed the following rules for the testing procedure.

a) As Karthik has already mentioned in the beginning of this thread, the strategy should be simple. I have also followed this principle. No complicated conditions or indicators for BUY or SELL.
b) All BUY and SELL signals will be strictly followed. However, the original MABIUTS of Karthik gives consecutives BUY or SELL signals without giving the opposite signal in between. In such multiple signals of same kind only the first signal will be taken, all subsequent signals ignored and wait for the opposite signal to generate. In the remaining three strategies alternate BUY and SELL signals are always generated.
c) NO STOP LOSS. As I have imposed the condition to trade all signals I have not put a stop loss condition. A stop loss can be incorporated later if it is beneficial.
d) All trades will be cash segment, delivery based trades.
e) For each time period we start with only cash. No stocks in our portfolio. Also, NO SHORT SELLING. So, our entry is always by buying the stock. At the end of the period, we come out with only cash. No open positions. So, our last trade will be a SELL. Even if a BUY condition comes at the end of the period, we ignore it as we cannot close it. If we get only BUY signals (or only SELL signals) in the testing time zone we discard them and note this as NVS (No Valid Signals) Similarly, if there is only one SELL and only one BUY in the entire period occuring in reverse order (SELL followed by BUY), this also is taken as NVS.
f) If there is no data for the testing period it is noted as NDA (No Data Available). This happens for the stocks listed recently.
g) No complete reinvesting of profits. After selling a stock with profit, we buy the same number of stocks back when a BUY condition comes. We take out the required money from the previous sale proceedings and keep the excess money. If we incur loss in previous selling then we provide additional funds for next BUY so that same number of shares can be purchased. This makes calculation of profits easy (By following this rule the percent profit/loss will be based on the first buying price only).

5. WHEN TO BUY AND SELL:

We are dealing with EOD data. All of the strategies use Close price for generating the signals. Therefore, a BUY/SELL signal is available only at the end of the trading day, when the market closes. So, we can only trade on the next trading day. Therefore, the prices on the next trading day are used.

6. WHAT IS THE BUY/SELL PRICE:

This is difficult to decide. Ideally, we want to SELL at the highest and BUY at the lowest price. But we cannot predict these prices. For back testing we can use these values, as the data is already available. But in real life it is not possible. I have seen people using the Closing price or average price or some such derived price. These are also difficult to get in real situation. Therefore, I use the Opening Price for all my calculations. I would also give a somewhat vague explanation for using Open price: A SELL signal means the prices are going to fall. Naturally we try to sell as early as possible before further fall in prices. A BUY signal means the prices are going to rise and we try to buy as early as possible before the prices go up further. In both cases the Open price would be more suitable. The choice of BUY or SELL price is open for discussion.

7. CALCULATION OF PROFIT/LOSS:

For comparing the results percent gain or loss is used. The percentage of profit/loss is based on the price at which the initial purchase was made (Explained above in Para 4 (g)). Although the percent profit/loss can be used for comparison, there is one more problem in real situations. This is brokerage and taxes. As we pay brokerage and taxes for both buying and selling, our real profits are reduced by the sum of these additional costs. It is not possible to fix a brokerage and tax component as different brokers charge different amounts. For my calculations I have taken a moderate rate of brokerage of 0.5% which is quite common. Add to this the STT and service charges etc. So, I take an overall figure of 0.65%. Using this I have calculated net profit/loss. I am giving both these figures, the total profit/loss excluding brokerage and taxes and the net profit/loss after accounting for the additional costs. This makes the comparison of the results more effective. From the results that I would be giving later, you can see that in some cases although there is substantial profit in gross terms, in real terms there is considerable loss due to the transaction charges.

This is all for the Details of my "Experiments in TA". This post has already become quite lengthy. So, I stop here and post the details of the strategies, the AFL codes and results in my next part of this series. The next parts will not be so lengthy.

I once again call for your comments, suggestions and evaluation.

Regards and Happy trading.

-Anant
 
Hi All,

This is probably the best thread I have ever read and I have gained lot of knowledge from this.

The credit for this goes karthikmarar and other Senior members of the group who have taken their precious time to discuss on such an important topic.

Shortly, I would be mention about my system, which is indeed not as perfect as the ones mentioned in this thread. But definitely I would require your help to tune it up further.

Regards,
a$h.investor
 

murthymsr

Well-Known Member
dear asnavale,

firstly thanks for your series of posts on the detailed procedure adopted while testing, which is generally found only research papers. the reaon is obvious, as you yourself are in the field of research. very rarely research in this subject is published for the obvious reason that for every set of gainers, there should be a matching set of loosers to foot the bill ;)

i have a few queries/comments on your posts which i will try to present. i said 'try to' because i am not a pofessional writer! but please remember that my intention in some comments is not to criticise any of the methods adopted, but only represent my opinion, which may not be correct at all.

A couple of these stocks do not have sufficient historical data. But I have still included them because:
a) As random selection is adopted, I do not want to reject some of the selected stocks as it introduces bias in selection.
b) It also gives us a chance to see how the strategies work with a limited amount of data.
the random selection may have been done after rejection of all those stocks that are not regularly traded and are thinly traded. by thinly traded, i mean all those stocks whose average closing price is less than Rs 20/- or whose average volume is less than 20000 shares or whose average turnover is less than Rs 100 lakhs. these stocks do not show some understandable / interpretable logic behind their movements.

the data purity is very important. impurity may occur because of changes in symbols and splits/bonuses. the period selected being very large ( almost 5 years), such cases may be innumerable. hope the database selectd is free from all these imperfections, so that the results obtained are reliable.

b) All BUY and SELL signals will be strictly followed. However, the original MABIUTS of Karthik gives consecutives BUY or SELL signals without giving the opposite signal in between. In such multiple signals of same kind only the first signal will be taken, all subsequent signals ignored and wait for the opposite signal to generate. In the remaining three strategies alternate BUY and SELL signals are always generated.
this could be achieved by adding the code in the AFL:

Buy = ExRem( Buy, Sell ); // Consequitive Buy / Sell exclusions
Sell = ExRem( Sell, Buy ); // Consequitive Buy / Sell exclusions

however, the method adopted by you may be laborious, but will not introduce any errors.

e) For each time period we start with only cash. No stocks in our portfolio. Also, NO SHORT SELLING. So, our entry is always by buying the stock. At the end of the period, we come out with only cash. No open positions. So, our last trade will be a SELL. Even if a BUY condition comes at the end of the period, we ignore it as we cannot close it. If we get only BUY signals (or only
SELL signals) in the testing time zone we discard them and note this as NVS (No Valid Signals)

Similarly, if there is only one SELL and only one BUY in the entire period occuring in reverse order (SELL followed by BUY), this also is taken as NVS.
the logic behind rejecting the buy-no sell signals and sell-buy signals is in order. i hope after such exclusions, there are sufficient pairs of buy-sell signals large enough to make the findings reliable.

f) If there is no data for the testing period it is noted as NDA (No Data Available). This happens for the stocks listed recently.
it may be preferable to eliminate such stocks, as calculations with such stocks may not give reliable and repeatable performance.

g) No complete reinvesting of profits. After selling a stock with profit, we buy the same number of stocks back when a BUY condition comes. We take out the required money from the previous sale proceedings and keep the excess money. If we incur loss in previous selling then we provide additional funds for next BUY so that same number of shares can be purchased. This makes
calculation of profits easy (By following this rule the percent profit/loss will be based on the first buying price only).
i am not sure, how far the above conditions adopted are close to reality. i feel, the following set of conditions is more realistic.

total investment=1,00,000
max stocks to be held at any time= 5 to 8
investment in each stock 10,000 to 16,000.
number stocks to be bought rounded to the nearest integer.
all profits accured during the trading period are reinvested.

6. WHAT IS THE BUY/SELL PRICE:

This is difficult to decide. Ideally, we want to SELL at the highest and BUY at the lowest price.

But we cannot predict these prices. For back testing we can use these values, as the data is already available. But in real life it is not possible. I have seen people using the Closing price or average price or some such derived price. These are also difficult to get in real situation. Therefore, I use the Opening Price for all my calculations.

I would also give a somewhat vague explanation for using Open price: A SELL signal means the prices are going to
fall. Naturally we try to sell as early as possible before further fall in prices. A BUY signal means the prices are going to rise and we try to buy as early as possible before the prices go up further. In both cases the Open price would be more suitable. The choice of BUY or SELL price is open for discussion.
i appreciate the logic presented for selling at open price of the following day. but still, i feel choice of average price (half of high & low price) on the following day is preferable. the realisable price ismost likely to be better than this average value and the prices will be highly achivable, if not better. as already pointed by Asnavale, it is a choice difficult to make.

it may appear to be illogical to comment just after reading the first part of a very long report being presented in parts. but as the responses are per point, i post my responses, otherwise i may miss to record my first feelings.

as i have already said, i have the highest regard to asnavale and to the findings of his professional approach. appologies for any discourtesy sounded in the wordings, which is totally unintentional.

all the best.
murthymsr
 

karthikmarar

Well-Known Member
Hi Ananth

Some great stuff coming from you. Unfortunately I am too tied up with my work (spending 14-16 hours at site) and hence no time to assimilate and appreciate the great posts by you. Hope to back soon to catch up with all the great stuff..

warm regards

Karthik
 

SGM

Active Member
g) No complete reinvesting of profits. After selling a stock with profit, we buy the same number of stocks back when a BUY condition comes. We take out the required money from the previous sale proceedings and keep the excess money. If we incur loss in previous selling then we provide additional funds for next BUY so that same number of shares can be purchased. This makes calculation of profits easy (By following this rule the percent profit/loss will be based on the first buying price only).
i am not sure, how far the above conditions adopted are close to reality. i feel, the following set of conditions is more realistic.

total investment=1,00,000
max stocks to be held at any time= 5 to 8
investment in each stock 10,000 to 16,000.
number stocks to be bought rounded to the nearest integer.
all profits accured during the trading period are reinvested.
Hello Murthy

Your discussion with Anant throws up an interesting point on reinvesting of profits and folio balancing.

It is natural to increase the exposure after a wining streak and reduce it after a losing one. It would be also justified as per the traditional Money Management Rules.

Here Anant has taken a contrarian approach, but as he has mentioned, his intention seems to be the ability to compare results and not with a focus on Money Management Rules. However it opens up a different approach to money management.

Haven’t we all wished to have the ability to top up the account after a deep drawdown. The recovery factor will be much better with the original account size restored. On the other hand we are giving up the benefits of power of compounding.

Certainly something to think about

Happy Investing

Regards
Sanjay
 

asnavale

Well-Known Member
Hi Murthy,

Thank you for your review. It is always helpful to record the views as soon as possible. At the outset I would say that your points were not at all hurting nor discurtious. Let me answer the points:

the random selection may have been done after rejection of all those stocks that are not regularly traded and are thinly traded. by thinly traded, i mean all those stocks whose average closing price is less than Rs 20/- or whose average volume is less than 20000 shares or whose average turnover is less than Rs 100 lakhs. these stocks do not show some understandable / interpretable logic behind their movements.

the data purity is very important. impurity may occur because of changes in symbols and splits/bonuses. the period selected being very large ( almost 5 years), such cases may be innumerable. hope the database selectd is free from all these imperfections, so that the results obtained are reliable
.

The stocks selected happen to be as per your criteria. May be it was by chance that stocks should be avoided were not selected. In case such a thing happened I would have rejected them. Random selection does not mean take any thing. We can put a precondition to include the selected item. This is one of the reasons I avoided BSE stocks. The BSE list is much larger and the chances of selecting wrong stocks is higher.

Data purity is indeed important. In another thread by Karthik, Database for AMIBROKER, you have stressed this point and given details of using the purify database option. You may remember that I had mentioned there that it helped me detect faulty data.

the logic behind rejecting the buy-no sell signals and sell-buy signals is in order. i hope after such exclusions, there are sufficient pairs of buy-sell signals large enough to make the findings reliable
This is where the NVS comes. In some cases, especially, in down trend there are such occurrences of NVS. This somply means the strategy keeps us out of market, no harm in it. As far as comparison is concerned, it better to be out rather than make loss. However, the H variant of MABIUTS gives least number of such NVS.

it may be preferable to eliminate such stocks, as calculations with such stocks may not give reliable and repeatable performance
I agree but I have given reasons.

i am not sure, how far the above conditions adopted are close to reality. i feel, the following set of conditions is more realistic.

total investment=1,00,000
max stocks to be held at any time= 5 to 8
investment in each stock 10,000 to 16,000.
number stocks to be bought rounded to the nearest integer.
all profits accured during the trading period are reinvested.
1) I am at present giving the results for individual stock performans. Allocating a particular amount and trading is part of portfolio testing which would be presnted later in the series.

2)Sanjay has already explained his view on this. The main purpose here is comparison of results.

2) Right from the beginning of my study I had this condition adopted. I always felt I am missing something which needs keeping the number of shares constant. I could not figure out what was missing but still kept the condition. It was only when I started preparing the report it struck me. It is a simple thing, comparison of results with BUY and HOLD strategy against continuous buy and sell. The BUY and Hold comparision, in my opinion, would be more effective if we keep the number of shares traded constant. How small things miss our attention!

Thanks once again for your healthy and constructive comments. Please do keep on posting as soon as you can. It helps me also to make the future posts take care of any missing details.

Thanks to Sanjay for answering some of the points.

Dear Karthik, we are missing you. I can understand how it feels to be away from the thread you started and encouraged others to experiment. Your inputs will be very valuable. Expecting you soon in the forum with your views and guidance.

Regard

-Anant
 
Last edited:
Hi Karthikmarar,

I have gone thourgh your trading system - "MABIUTS". It is really amazing and would definitely give profitable results. I have done some kind of back testing as well.

In MABIUTS, I understood the concept of 13, 9 EMA. But I failed to understand this condition - C>Peak(1,C,2) mentioned in your pdf file. I think this condition is make sure whether the market is in trending or whipsaw mode.

Could you please explain me what does C>Peak(1,C,2) mean? (I know this sounds very stupid of me)

I don't use MetaStock or Amibroker for Trading so I am not able to used the scripts that you had attached. (See I am so very unfortunate :()

Thanks in Advance...

Regards,
a$h.investor
 

Similar threads