Experiments in Technical Analysis

asnavale

Well-Known Member
CONTINUING WITH MACD

Dear friends,

Thank you all, specially to Asish, John, Karthik, Amit, for your interest, the encouraging words, appreciation and the response you have given to my efforts.

In his exhaustive posts on MACD Karthik has shown how MACD by itself can be used as a trading system. Today I am giving examples of using MACD to improve existing trading setups. I am using standard parameters for MACD (12, 26 and 9).

The first system I am taking is a simple setup where two moving averages cross-over to generate BUY-SELL signals. There are several setups of this type, most of them based on MA or EMA of CLOSE price. I am taking a slightly different one which is also quite popular. It is based on 5-period EMA of Close and 6-period EMA of Open. This setup can be used for intraday trading also.

The BUY signal is generated when the 5-period EMA of close crosses and goes above the 6-period EMA of Open. Similarly the SELL signal is generated when the 5-period EMA of CLOSE crosses and goes below the 6-period EMA of OPEN.

Upper portion of the attached Chart-16 shows the BUY-SELL signals generated by this setup. You can see that though the system gives good signals it gives too many signals. This is because in any Moving average based system the signals generated increase as the averaging period decreases. in addition as the difference between the two averaging periods decreases the number of signals increases. In the system described here we have two very short periods and the difference between them is 1. So, this system is bound to give too many signals.

But when we combine this system with MACD the whole scenario changes dramatically. What we do is accept only those BUY signals when MACD is in BUY mode and SELL signals when MACD is in SELL mode. We already know that when MACD is above its Signal line it indicates positive momentum which means it is in BUY mode. Similarly when MACD is below its Signal line it is in SELL mode.

The lower part of chart-16 shows the BUY-SELL signals generated when MACD is combined with the EMA Cross-Over system. Almost all the whipsaws are removed and we get a few signals which are very powerful.

The AFL for this system is given below. Just copy it into your AmiBroker Custom indicators directory. You can just drag and drop this indicator on any price chart and you get the signals. The AFL has a switch setting which can be toggled to generate the signals with MACD or without MACD. The default is without MACD.

Code:
("Moving Average Cross-over Trading System");

MACDswitch = ParamToggle("Use MACD?", "No | Yes", 0); 
ShortEMA   = EMA(C, 5);
LongEMA    = EMA(O, 6);

 M = MACD();
 S = Signal();

 Buy  = Cross(ShortEMA, LongEMA);
 Sell = Cross(LongEMA, ShortEMA);

if (MACDswitch)
	{
		Buy  = Cross(ShortEMA, LongEMA) AND M > S;
		Sell = Cross(LongEMA, ShortEMA) AND M < S;
	}

Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);

Marker = Buy * shapeUpArrow + Sell * shapeDownArrow;
MarkerColor = IIf(Buy, colorBrightGreen, colorRed);
MarkerDist = IIf(Buy, L, H);
//You can uncomment next two lines if you want to plot the EMAs also

//Plot(ShortEMA, "EMA5 Close", colorGreen);
//Plot(LongEMA, "EMA6 Open", colorRed);

PlotShapes(Marker, MarkerColor, 0, MarkerDist);
Chart-17 is another example of a trading system with and without MACD. This system is the MABIUTS-H system which I have described in this thread in Post No. 333. (http://www.traderji.com/64448-post333.html)

The upper portion of the chart is without MACD and the lower portion is with MACD. The difference is self evident.

Be aware that these systems involve basically the Moving Averages. Therefore they will be very good in trending markets. In sideway movement of range bound conditions they still generate whipsaws even when MACD is used. Therefore, DO NOT TAKE THESE SYSTEM AS FOOLPROOF TRADING SYSTEMS. Use caution while trading with them and use other methods to determine and validate the signals for more safe trading. You can experiment with the parameters of MACD and find out best set of values for your system.

In the next post I will describe another trading system which is based on Linear Regression.

Please post your comments, views and suggestions.

Regards

-Anant
 
Last edited:

asnavale

Well-Known Member
Hi Ananth

This is becoming more interesting. Excellant work. Thanks for sharing it with us , my friend.

warm regards

Karthik
Thank you Karthik for your encouragement.

Regards

-Anant
 

asnavale

Well-Known Member
Continuing with MACD


Hello Friends,

Today I am describing the use of MACD to enhance the performance of a trading system based on Linear Regression. Before I describe the system let me say a few words.

I have read a couple of books about TA, some articles on the Internet and some posts in various forums. So, my knowledge is limited. The system I am describing is based on Linear Regression Slope. In my limited exposure to TA I have not come across anything similar to this system. If any of you have seen or read about such a system please post the links so that I can learn. Though I have not seen a system of this type it does not mean I have invented it. A similar system might have been described by somebody earlier elsewhere.

In one of the chat room sessions on Traderji I had a discussion with Karthik about Linear Regression. At that time he had posted his R2 system which is based on Linear Regression. In that system he is using the regression coefficient (known as R-squared) for determining BUY SELL conditions. As the name suggests R-squared is a squared number which is always positive. Therefore it does not tell whether the prices are decreasing or increasing. It just tells how good is the regression line fitting the actual points. A value of 1 is perfect fit, which is almost never achieved while a value of zero means complete randomness.

But the slope of the regression line can be positive or negative. Positive slope indicates upward movement (increasing prices) and negative slope indicates downtrend. Slope can vary from minus infinity to plus infinity. A value of zero slope means a horizontal line parallel to X-axis. Higher the value of slope (positive or negative) steeper is the line.

I was suggesting Karthik that we should try to fit two regression lines, one with a longer period and the other with a shorter period. The shorter period slope catches the upward/downward movements faster and reacts by changing the value and sign of slope. If the prices have started falling the short slope turns negative while the long slope is still positive. Therefore these two lines should intersect. It should be possible to notice the point of intersection earlier than in case of moving averages.

But we could not come to a conclusion about how to frame a trading system with this. Due to his busy schedule Karthik also was not able to devote much time to this idea. However, it was always in my mind and I was trying to figure out how to make a system with regression slope. One day I just plotted the short slope and long slopes and found that the short slope crisscrossed the long slope very frequently. At first glance it appeared it was a hopeless system. When I plotted MACD below this graph of slopes I started seeing some pattern where BUY/SELL conditions could be formulated. Finally I could make a system which appears to work.

What I have done is take 10-day slope and 20-day slope and plot them. The points where these two cross-over are the BUY/SELL points, just like the Moving Average crossover. When short period slope crosses and goes above the long-period slope it is a BUY signal. Similarly when the short-period slope crosses and goes below the long-period slope it is a SELL signal. The upper portion of attached chart-18 shows these signals. For the sake of clarity I have not plotted the slopes in the chart. As you can see there are a large number of signals which can not be traded. But when I took only those BUY signals where MACD is above its signal line and SELL signals where MACD is below its signal line the graph was very clean and a few signals were left. This is shown in the lower portion of chart-18. As you can see these signals are quite profitable.

The code to generate these signals is given below. Just drag and drop it on any price chart to get the signals. This AFL by default generates signals with MACD. You can toggle the parameter switch to get signals without MACD.

Code:
("Linear Regression Slope based System");
p1 = Param("Long Reg Period", 20, 3, 100, 1);
p2 = Param("Short Reg Period", 10, 3, 100, 1);
p3 = Param("MACD Fast Period", 12, 3, 50, 1);
p4 = Param("MACD Slow Period", 26, 3, 50, 1);
p5 = Param("MACD Signal Period", 9, 3, 50, 1);

MACDswitch = ParamToggle("Use MACD?", "NO | YES", 1);

 LongSlope  = LinRegSlope(C, p1);
 ShortSlope = LinRegSlope(C, p2);

 M = MACD(p3, p4);
 S = Signal(p3, p4, p5);

Buy  = Cross(ShortSlope, LongSlope);
Sell = Cross(LongSlope, ShortSlope);

if (MACDswitch)
	{
		Buy  = Cross(ShortSlope, LongSlope) AND M > S;
		Sell = Cross(LongSlope, ShortSlope) AND M < S;
	}

Buy  = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);

Marker=Buy * shapeUpArrow + Sell * shapeDownArrow;
MarkerColor = IIf(Buy, colorSeaGreen, colorRed);
MarkerDist  = IIf(Buy, L, H);

PlotShapes(Marker, MarkerColor, 0, MarkerDist);

//To Plot the slope lines uncomment the following two lines
//Plot(LongSlope, "Long Slope", colorRed,styleOwnScale);
//Plot(ShortSlope, "Short Slope", colorGreen, styleOwnScale);
Compare the EMA cross-over system (described in my previous post) with the regression slope cross-over system in attached chart-19. The regression slope method appears to give better signals.

Please note that this regression slope method needs more study to optimize various parameters. Being a cross-over system it is prone to give some false signals. It needs exhaustive back testing and fine tuning. You are welcome to try out and experiment with this system and post your findings, refinements and suggestions.

In the next post I will briefly deal with Zero-lag MACD

Regards

-Anant
 
Last edited:

karthikmarar

Well-Known Member
Hi Ananth

Great Examples of how MACD can be great complimentary Indicator to other Trading system. The Linear regression cross over is an excellant idea. Truly a scientist's mind at work. really superlative.

Like you said the systems presented by you are very good tren following systems. But the bane of any trend following system, the whipsaw is quite evident in these too during consolidating and sideways markets.

Thanks for sharing these systems with us. I will post my studies of these system soon.

warm regards

Karthik
 

asnavale

Well-Known Member
hi anant
pl post charts with white background(easier to read with black and white printouts) will you.
cheers
Hi Roshanna,

I am posting all the earlier charts now with White Background. I have removed all colors and instead used black, white and different shades of grey in these charts so that you can print them on a printer with only Black ink. In these charts the BUY signals are Black Up Arrows and SELL signals are Grey Down Arrows. Henceforth, I will post charts in single color (Black/Grey with white background) also. These charts will have BW prefixed to the file names.

Please note that some chart titles do not have correct dates. The Date-Axis always shows correct dates.

Regards

-Anant
 
Last edited:
Dear Anant
Seems interesting, I am trying ur indicator,Linear Regression Slope based System and Moving Average Cross-over Trading System.
Can u tell me whether it suits for all periods like EOD, WEEKLY AND INTRADAY(hourly, 5,10 15 min charts in intraday). tell ur best option pls.
Raj
 

Similar threads