Experiments in Technical Analysis

karthikmarar

Well-Known Member
Dear Ananth

I am amazed at the depth of analysis being done by you.. truly befitting a scientist. Great post by sanjay and murthy.

It is sad that I am unable to fully participate in the discussion now as I am too preoccupied with my work. Though it is well past midnight and my weary eyes are clsoing automatically could not resist plotting the MABIUTS-H strategy.. :)
Chart of MABIUTS-H and MABIUTS-K enclosed.... comments later.. it is time to crash.. to be ready for another hard day...

warm regards

Karthik
 
Last edited:

SGM

Active Member
Dear Anant

Your histogram concept is excellent. Let me congratulate you for a fresh approach on cross-overs.

Just thinking about the concept, the first impression was, it should give lots of wipsaws. But the data you have presented suggests otherwise, just shows to go how deceptive perceptions are.

I would do some testing of my own, before making any further comments.

Just a seed of a thought for the portfolio part of the experimentation, if we could incorporate stock selection based on relative strength the overall performance of the folio can be improved, we can come back to this later...

Thanks a lot, for sharing your findings and code.

Regards
Sanjay
 
Last edited:

SGM

Active Member
Chart of MABIUTS-H and MABIUTS-K enclosed.... comments later.. it is time to crash.. to be ready for another hard day...

warm regards

Karthik
Hello Karthik

Special Thanks to you, for taking us on this path and guiding us along the way.

Do take good care of your health.

Warm Regards
Sanjay
 

murthymsr

Well-Known Member
dear asnavale,

thanks for the AFL's for the different strategies adopted. based on posted results, everybody will be eager to go through the MABIUTS-H logic, and me too. a few of my responses on the write-up:

4. MABIUTS-H Strategy:

This is what most people are waiting for. But it needs some explanation. Not because it is complicated. The code is as simple as the others. This is a modification of the Cross Over strategy, MABIUTS-X. What I have done is look at the cross over from a different angle. Any crossover method based on Moving Averages gives the signal after a delay. This is because the Moving Averages are lagging indicators. The delay can be upto half the period of Moving Average. This can be proved. If any of you want the proof, please post a message. I will explain it. It is simple.
i fully agree with what you said that 'The delay can be upto half the period of Moving Average'. actually about a year back, i have read a very novel method to remove the delay. this is by adding (or is it by substracting?) the HALF period EMA from the normal period EMA. after reading your post, i tried to locate the reference by googling, but couldn't find. i will continue my search and post the link if i could find. by your scientific approach, this could be easily rebuilt.

Now let us study the cross over from my angle. When two curves cross over what happens is they start coming closer and at the cross over point they meet.
the crossover method has another limitation that sometimes stocks crossover 'too often', as, inspite of the cross over, enough strength may not be there in the move and they reverse crossover in a very short period.

another way of putting the crossovers is:

buy= EMASHORT/EMALONG>1
sell= EMASHORT/EMALONG<1

if this is modified to:

buy= EMASHORT/EMALONG>1.02
sell= EMASHORT/EMALONG<0.98

this 2% (or another such small value) 'dead--band' could possibly exclude such weak crossovers. this dead-band can be optimised.

Thereafter they move away. If one more cross over occurs they have to come closer again and meet. It means, between the two cross over points they initially go apart upto some distance and then come closer. Put in a different way, the difference between the two moving averages after a cross over goes on increasing, reaches a maximum and then starts decreasing till the cross over. At cross over point the difference is zero. Now, if we plot this difference as a bar graph we get a histogram similar to the MACD histogram. The tallest bar is the maximum point. So, I tried to trade with this maximum bar. When the maximum bar appears SELL and when it is minimum (NOT ZERO) SELL. It worked wonders. It was able to catch the trend change and price reversals very early compared to the Cross over.
here again, sometimes, we may come across 'weak reversals'. to exclude such weak signals, we may go for the 3day EMA of that difference than the difference itself.

i am aware that my comments 2 & 3 will incorporate delays and possibly may reduce the RETURNS. but they may reduce the RISK too. these may eat away part of the benefits of the removed delay by the method hinted in my first comment.

these comments of mine are more hypothetical in nature and request your comments on these. if your time permits, you may substanciate / negate by back testing.

not a big issue, but, if you add a column to show the date of crossover in the exploration window, it may help to know from the window itself how old is the cross-over and the most recent cross-overs.

thanks asnavale for your posts with the professional aproach to trading research.

all the best.
murthymsr
 
Last edited:

uma_k

Well-Known Member
Hi,

MABIUTS-H is a very innovative and novel approach. Very scientific explanation too. Please explain the proof of Moving average delay.

***Uma***
 

uma_k

Well-Known Member
Hello SGM,

It wold have been better if the price chart also was overlayed with the histogram. Just my opinion. No degrading of your effort.

Regards

***Uma***
 
Hello friends,

Thanks for your patience. Here are the four strategies and their AFL codes. I am giving some description and explanation followed by the code. Please go through the description and codes also so that any discrepancies which I might have missed may be brought out.

As I was playing around the original code by modifying this parameter or that, I have re-written the Karthik's original code also in a different way. The code is same, only written in different way. This allows me to change the values easily.

The four strategies are:
1. MABIUTS-K: The Karthik's original. That is why I suffix it with K.
2. MABIUTS-X: The Cross Over strategy. The X stands for Cross Over.
3. MABIUTS-M: The strategy based on Mark McRae's technique. M means McRae.
4. MABIUTS-H: The Histogram based strategy. H stands for Histogram. I will explain it in detail.

1. The Original MAIBUTS by Karthik which I named MAIBUTS-K

I need not explain this as enough has been written about this already. The code which I have re-written is:
***************************************************
("MABIUTS-K :::: Karthik's Exploration");
p1=13;p2=9;
X=EMA(C,p1);Y=EMA(X,p2);

Buy=X>Y AND Cross (C,Peak(C,5,1));
Sell=Cross (Y,X);
Bprice=IIf(Buy,Ref(O,1),0); //Buying Price
Sprice=IIf(Sell,Ref(O,1),0); //Selling Price
//Note: the last character in above two lines is zero not O.

Filter=Buy OR Sell;

SetOption("NoDefaultColumns", True );

//The following line may be commented out if testing a single stock
AddTextColumn( Name(), "Symbol", 20 , colorDefault);

AddColumn(ref(DateTime(),1), "Date", formatDateTime );
AddColumn( IIf( Buy, 66, 83 ), "Signal", formatChar, colorWhite, bkcolor =IIf (Buy,colorGreen, colorRed ));

AddColumn(Bprice,"Buy Price",6.2,colorGreen);
AddColumn(Sprice,"Sell Price",6.2,colorRed);
*******************************************************

2. The MABIUTS - X Strategy:

In the MABIUTS-X Code, I have simply removed the Cross(C,(Peak(C,5,1)) and changed the line to CROSS(X,Y). The code is:

**********************************************
("MABIUTS-X :::: Cross-over Exploration");
p1=13;p2=9;
X=EMA(C,p1);Y=EMA(X,p2);
Buy=Cross(X,Y);
Sell=Cross(Y,X);
Bprice=IIf(Buy,Ref(O,1),0); //Buying Price
Sprice=IIf(Sell,Ref(O,1),0); //Selling Price

Filter=Buy OR Sell;

SetOption("NoDefaultColumns", True );

//The following line may be commented out if testing a single stock
AddTextColumn( Name(), "Symbol", 20 , colorDefault);

AddColumn( ref(DateTime(),1), "Date", formatDateTime );
AddColumn( IIf( Buy, 66, 83 ), "Signal", formatChar, colorWhite, bkcolor =IIf (Buy,colorGreen, colorRed ));

AddColumn(Bprice,"Buy Price",6.2,colorGreen);
AddColumn(Sprice,"Sell Price",6.2,colorRed);
***************************************************************

3. MABIUTS-M Strategy:

This is based on Mark McRae's method. Here the cross-over of 5-day EMA of Close and 6-day EMA of Open are used. If the EMA(C,5) goes above EMA(O,6) it is buy and when it goes below it is Sell. I will write more about this later. The code is:
*******************************************************
("MABIUTS-M :::: Mark MacRae's method.");
p1=5;p2=6;
X=EMA(C,p1);Y=EMA(O,p2);
Buy=Cross(X,Y);
Sell=Cross(Y,X);
Bprice=IIf(Buy,Ref(O,1),0); //Buying Price
Sprice=IIf(Sell,Ref(O,1),0); //Selling Price

Filter=Buy OR Sell;

SetOption("NoDefaultColumns", True );

AddTextColumn( Name(), "Symbol", 20, colorDefault);
AddColumn( ref(DateTime(),1), "Date", formatDateTime );
AddColumn( IIf( Buy, 66, 83 ), "Signal", formatChar, colorDefault, bkcolor =IIf (Buy,colorGreen, colorRed ));
AddColumn(Bprice,"Buying Price",6.2,ColorGreen);
AddColumn(Sprice,"Selling Price",6.2,ColorRed);
***********************************************************

4. MABIUTS-H Strategy:

This is what most people are waiting for. But it needs some explanation. Not because it is complicated. The code is as simple as the others. This is a modification of the Cross Over strategy, MABIUTS-X. What I have done is look at the cross over from a different angle. Any crossover method based on Moving Averages gives the signal after a delay. This is because the Moving Averages are lagging indicators. The delay can be upto half the period of Moving Average. This can be proved. If any of you want the proof, please post a message. I will explain it. It is simple.

Now let us study the cross over from my angle. When two curves cross over what happens is they start coming closer and at the cross over point they meet. Thereafter they move away. If one more cross over occurs they have to come closer again and meet. It means, between the two cross over points they initially go apart upto some distance and then come closer. Put in a different way, the difference between the two moving averages after a cross over goes on increasing, reaches a maximum and then starts decreasing till the cross over. At cross over point the difference is zero. Now, if we plot this difference as a bar graph we get a histogram similar to the MACD histogram. The tallest bar is the maximum point. So, I tried to trade with this maximum bar. When the maximum bar appears SELL and when it is minimum (NOT ZERO) SELL. It worked wonders. It was able to catch the trend change and price reversals very early compared to the Cross over.
To identify the maximum and minimum bars you can plot this difference as histogram and visually see. You can explore and locate the bars by writing a code to identify the max and min. How do we do it? A maximum bar is identified by two smaller bars on either side. So among three consecutive bars, if the middle bar is the highest you have the maximum. Similarly Among three consecutive bars if the middle bar is the shortest then you have the minimum. This is what I have coded in the MAIBUTS-H. The Code is:
*********************************************************
("MABIUTS-H :::: Histogram Exploration");
p1=15;p2=15;
X=EMA(C,p1);Y=EMA(X,p2);
D=X-Y;

Buy=Ref(D,-2)>Ref(D,-1) AND D>Ref(D,-1);
Sell=Ref(D,-2)<Ref(D,-1) AND D<Ref(D,-1);
Bprice=IIf(Buy,Ref(O,1),0); //Buying Price
Sprice=IIf(Sell,Ref(O,1),0); //Selling Price

Filter=Buy OR Sell;

SetOption("NoDefaultColumns", True );
//The following line may be commented out if testing a single stock
AddTextColumn( Name(), "Symbol", 77 , colorDefault);

AddColumn( Ref(DateTime(),1), "Date", formatDateTime );
AddColumn( IIf( Buy, 66, 83 ), "Signal", formatChar, colorWhite, bkcolor =IIf (Buy,colorGreen, colorRed ));
AddColumn(Bprice,"Buying Price",6.2,colorGreen);
AddColumn(Sprice,"Selling Price",6.2,colorRed);
**********************************************************

I wanted to discuss these four strategies in more detail. But I have some other urgent work. Therefore I am not giving any results today. As many of you are waiting eagerly for these codes I decided to just give them and postpone the discussion to another post. I know you have many questions but I will answer them later. But post your queries, views and comments at the earliest so that you won't forget any points.

Sorry for very brief description.

As I have written this in a hurry, there may be some grammatical or spelling mistakes. I did not check. Please ignore them. If there are any errors in the program, pleasae bring to my notice.

Regards.

-Anant
Dear Anant,

Do you have MS code for your theory? I would love to try it out. If anyone else has the code I would be very appreciative.
Thanks,
TheTraderMan
 

asnavale

Well-Known Member
Dear friends,

Thanks for your views, comments and suggestions. I am sure some more will come after you run the AFLs on different stocks and under different conditions. I am waiting for your valuable inputs.

I will try to explain some of the points already posted by different members.

First of all let me thank you, Karthik, for taking such keen interest inspite of your heavy schedule. From your post I could see that you have put your test results within an hour or two after I posted the codes. Really dedicated work by you. You appear to have run the codes very late in the night or may be early hours foregoing sleep and rest. Please take care of your health.

Just thinking about the concept, the first impression was, it should give lots of wipsaws. But the data you have presented suggests otherwise, just shows to go how deceptive perceptions are.
Hi Sanjay, The Histogram does give lot of signals even inbetween actual crossover points. For example in Long Term_I, there are nearly 70-90 signals over a period of 440 trading days, several signals coming on consecutive days. Some of these may be even loss making. We must find a solution to eliminate them. But that can be done later after enough discussion in this forum, combining various ideas put forward by different members.

I have tried few methods to eliminate the small signals. But what happened was in many cases, an insignificant Buy signal just before a large upward movement got eliminated and there was no way of entering into the up trend. This is important especially at the end of a range bound movement. Therefore I just kept on trading with all the signals, however minute they were. This is also in line with my conditions posted earlier that all signals will be traded.

Just a seed of a thought for the portfolio part of the experimentation, if we could incorporate stock selection based on relative strength the overall performance of the folio can be improved, we can come back to this later...
Yes we can consider this later. But I will carry out the intial portfolio test with the same stocks, but eliminate those which have insufficient data.

Hello,

AB Code for plotting the Cross Over Histogram.

Regards
Sanjay
Thanks for the code. It appears from the code you posted that the values of p1 and p2 were changed to 13 and 9. I had posted p1=15 and p2=15. The values 15 for p1 and p2 gave slightly better results. You may try to use these values and and find out.

I had removed the histogram plotting code in order to highlight the exploration part alone. (I have a combined code which can plot and explore so that the same AFL can be used to either plot or to explore.)

Hello thetraderman, I am sorry. I have never used MS. So I cannot help you. But the members here would do that for you.

Regards and Happy trading.

-Anant
 

Similar threads