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,O,0); //Buying Price
Sprice=IIf(Sell,O,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