Download MetaTrader 5
To add comments, please log in or register
Are you a good trader? Become a signals provider and make even more money!
Automated-Trading 2014.06.02 11:22 

MACD Sample:

The MACD Sample EA is included in the standard pack of the MetaTrader 5 client terminal and is an example of the EA that trades using the MACD indicator.

The file of the MACD Sample.mq5 Expert Advisor is located in terminal_data_folder\MQL5\Experts\Examples\MACD\". This Expert Advisor is an example of object-oriented approach in EA development.

Figure 3. Backtesting results of the MACD Sample Expert Advisor

Author: MetaQuotes Software Corp.

Sergey Golubev
Sergey Golubev 2014.06.19 12:04  

Forum on trading, automated trading systems and testing trading strategies

Indicators: MACD Histogram, multi-color

newdigital, 2014.06.19 12:01

Moving Average Convergence Divergence (MACD)

MACD stands for Moving Average Convergence Divergence and was first developed by Gerald Appel in the late 1970s. It is an Absolute Price Oscillator (APO) and can be used in an attempt to identify changes in market direction, strength and momentum.

It calculates the convergence and divergence between a ‘fast’ and a ‘slow’ Exponential Moving Average (EMA) known as the MACD Line. A signal EMA is then plotted over the MACD Line to show buy/sell opportunities. Appel specified the MA lengths as the following percentages:
  • Slow EMA = 7.5% (25.67 period EMA)
  • Fast EMA = 15% (12.33 period EMA)
  • Signal EMA = 20% (9 period EMA)
Usually however these are rounded to EMAs of 26, 12 and 9 respectively. Many charting packages will also plot the difference between the Signal Line and MACD Line as a Histogram.

One of the biggest challenges when dealing with financial data is noise or erratic movements that cause false signals. By smoothing data out you can reduce the number of false signals. But this comes at a cost, and causes an increase in the lag of your signals. The genius of the MACD is that it begins by smoothing data (thus causing lag) and then speeds up the signals from the smoothed data. This combination helps to reduce false signals while minimising the lag.

By comparing EMAs of different lengths the MACD can help to identify subtle changes in the trend and momentum of a security. It is a great visual representation of the acceleration or rate of change in a trend.

How to Calculate a MACD

MACD Formula:

  • MACD Line = EMA,12 – EMA,26
  • Signal Line = EMA[MACD,9]
  • MACD Histogram = MACD – Signal Line
  • Histogram Trigger = EMA[MACD Histo,5]
Obviously you can change the parameters to any value of your choice.

MACD Excel File

We have put together an Excel Spreadsheet that will automatically adjust to the MACD settings you desire. Find it at the following link near the bottom of the page under Downloads – Technical Indicators: Moving Average Convergence Divergence (MACD)

Test Results

Is the MACD an effective indicator? We are putting it into the ring for the Technical Indicator Fight for Supremacy. It will be tested through 300 years of data across 16 global markets to discover which settings produce the best results and how it performs compared to other indicators:
  1. Moving Average Crossovers – Completed - Golden Cross – Which is the best?
  2. Moving Average Convergence Divergence (MACD) – Completed – Results
  3. ZeroLag MACD (ZL-MACD)
  4. MACD Z Score (MAC-Z)

To add comments, please log in or register