# Moving Average Convergence/Divergence (MACD)

##### Overview

The MACD is a trend-following indicator since it is based on the relationship between the two moving averages of the closing prices. The indicator consists of two lines, the main MACD line and the signal line.

The MACD line, plotted on the MT4 as a bar chart, is calculated as the difference between two exponentially smoothed moving averages. Its most common presentation uses the difference between a 12-period and a 26-period EMA, although it is a model into which you can insert any moving average combination.

The signal line, plotted on the MT4 as a dotted line, is a 9-period simple moving average (SMA) of the MACD line.

A zero line, otherwise known as the MACD equilibrium line, represents those periods during which the two EMAs are identical. When MACD is above the equilibrium line it means that the shorter average is above the longer average and vice versa.

The system obtains its name from the fact that the two moving averages used in the calculation are continually converging and diverging from each other. Convergence - as the averages approach each other - indicates that the trend is slowing or consolidating. Divergence - as the averages move further apart - indicates an accelerating market move associated with a trend in motion.

The MACD is what we call an unbound oscillator since, unlike the RSI for example, it does not move in a pre-defined prices range.

##### Construction

The MACD line is calculated as follows:

##### MACD Line(t) = EMA_{12}(t) - EMA_{26}(t)

Where the EMA is the Exponential Moving Average:

##### EMA_{n}(t) = [2/(1 + n)] * Price + (1 - [2/(1 + n)] * EMA_{n}(t - 1))

n referring to the "averaging period"

The signal line is then derived as follows:

##### SignalLine(t): SMA_{9} of the MACD Line(t)

Where the SMA is the Simple Moving Average:

##### SMA_{n}(t) = P(t) + P(t - 1) + ... + P(t - n)/n = ∑^{n}_{i=0}P _{t-i}/n

A full guide to the calculation and construction of the MACD indicator is provided in excel format for your better understanding.

Moving Average Convergence Divergence (MACD)

##### Interpretation & Trade Signals

There are four basic principles of MACD interpretation:

- Signal line crossovers
- Equilibrium line crossovers
- Divergences
- Oversold/Overbought Levels

##### Signal line crossovers:

Traders will either look for the MACD line to cross above the signal line to buy in an uptrend or fall below the signal line to sell in a downtrend. These crossover signals are very common and should be filtered before relying on them since volatility in the underlying instrument can increase crossovers substantially. Please observe the example that follows for a practical application of this principle.

##### Equilibrium line crossovers:

The MACD crosses the zero line when the two constituent averages cross each other.

Positive MACD values indicate that the 12-day EMA is above the 26-day EMA. MACD values increase as the fast average diverges further from the longer-term average indicating an increase in short-term momentum.

Negative MACD values indicate the opposite; that is the fast average is below the longer-term average. Negative values increase as the shorter-term average diverges further below the longer-term average, signaling that the downside momentum is increasing in the short-term.

Equilibrium line crossovers are very useful provided the existence of a strong trend, since in sideway markets, consecutive crosses produce a lot of whipsaws. Please observe the example that follows for a practical application of this principle.

In general, both MACD Signal/equilibrium line crossovers work well in trending markets but produce a lot of false signals during sideways or choppy markets.

##### Divergences:

A bullish divergence is formed when the underlying instrument records a lower low while the MACD forms a higher low. The divergence can be an indication of downside momentum slowing and therefore the potential for a turnaround, provided that the market has been trending lower. The divergence should be considered more powerful when the MACD is in negative territory and near its extremes.

Similarly, a bearish divergence is formed when the underlying instrument records a higher high while the MACD forms a lower high, provided that the market has been trending higher. The divergence should be considered more powerful when the MACD is in positive territory and trading near its extremes.

Divergences should not be traded during the initial formation of a new trend since the reduction in momentum that often follows a sudden advance in prices may lead to misleading divergences with the MACD line.

##### Oversold/Overbought Levels:

Since as we said before the MACD is unbounded, it is sometimes very dangerous to try and use this indicator to produce countertrend trade signals as the trend can keep going catching us on the wrong side of the market.

However, despite the fact that MACD is boundless, the advantage of watching MACD rather than its primary components (i.e. the two underlying moving averages) is that it tends to top/bottom around the same levels and therefore, as the indicator approaches an old peak, one can interpret that as the potential for a change in the short term trend.

Furthermore, considering that forming an extreme actually means that the fast-moving average has pulled away dramatically from the longer-term average, it is likely that the underlying instrument is overextending and will soon return to more realistic levels. Therefore, trading the extremes can sometimes produce very profitable trades.

##### Example

The following example examines trading signals produced by signal line crossovers and also by Equilibrium line crossovers. To produce the signals, we use two distinct MACD systems, as per Gerald Appel’s original suggestion.

Lets mark signal line crossover trading signals as (A) and equilibrium line crossover trading signals as (B):

Long Entry signal:

- A. A buy signal is produced when MACD Line > signal line
- B. A few bars earlier MACD Line = 0 and crossing the Equilibrium line from South to North

Both entry signals are given by our entry MACD (8,17,9) system.

Change of trend warning: MACD Line approaching the empirical extreme value at about 21:00 warning for a possible top.

Long Exit signal:

- A. A Sell signal is produced when MACD Line < signal line
- B. MACD Line = 0and crossing the Equilibrium line from North to South Note that the two averages in the selling MACD system cross each other at the same time.

##### Tips and ideas

Gerald Appel recommends trying shorter-term MACD combinations for producing buy signals, such as 8-17-9 period averages while utilising longer-term combinations for producing sell signals, such as 12-25-9 period averages. This reflects the theory that markets spend more time in a rising than in a falling mode, therefore a longer time span will render a sell indication timelier.

Simple trendlines drawn on the MACD can help identify important trend changes when they are not very clear on the underlying chart. MACD crossovers have more significance when they are confirmed by a violation of a trendline.

Use weekly MACD to confirm Daily MACD, and Daily MACD to confirm intraday MACD.

##### Strengths/Weaknesses

An advantage of using MACD is that the pattern is very smooth in comparison to both the prices chart and other momentum indicators. This results in helping to identify the overall trend more clearly.

If a shock comes along, it can cause the price to vary wildly from the trend. This will render the tendency to converge or diverge as irrelevant. In this case the indicator will substantially lag any price event that will follow, like any other moving average system.

Beware of mechanically trading every MACD crossover, as it can lead to whipsaws and substantial risk, especially in choppy or sideways markets. MACD crossovers can be filtered combined with other tools.

Since both moving averages used for the construction are lagged, the peaks and troughs formed as the difference of the two EMAs will also experience some lag.

##### Suggested Combinations for EA development

Chart reversal patterns as sign of exhaustion.

Support/Resistance levels, retracement zones.

Price - Moving Average crossover signals can be used for confirmation help.

Basic trend analysis.

RSI for reversal confirmations.

##### Use in FxPro Quant

MACD can be found under the ‘Indicators’ group in our FxPro Quant menu. With FxPro Quant, we do not have to worry about the calculations and definitions behind the indicator. We just need to drag & drop the indicator in the main window and set the parameters we want to test.

##### Parameters

###### Symbol

Input: e.g. EurUsd, GbpYen | Default: Current

If left empty, the instrument symbol used in the relevant chart in MT4 will relate by default.

###### Time Frame

Input:1m,5m,15m,30m,1h | Default: Current

If set to current, the time frame used in the relevant chart in MT4 will relate by default.

###### Fast EMA

Input: number | Default: 12 periods

The fast Exponential Moving Average used in the calculation formula to derive the MACD (see excel spread sheet attached).

###### MACD SMA

Input: number | Default: 12 periods

The Simple Moving Average of the MACD line otherwise known as the signal line (see excel spread sheet attached).

###### Applied Price

Input: Close, Open, High, Low, Median, Typical, Weighted price. | Default: Close Price

Value used to derive the indicator.

###### Output Value

Input: Main Line, signal line | Default: Main Line

Indicator value required for the Expert Advisor system in question.

###### Shift Back

Input: Number | Default: 0

Selects the data used for calculating the Indicator (Number of periods back or forth).

Please note that Bands Shift=1 means shifting the Bands one period backwards (in the past).

##### References

John J. Murphy - Technical Analysis of the Financial Markets

Steven B. Achelis - Technical Analysis from A to Z

Perry J. Kaufman - Trading Systems and Methods

Martin J. Pring - Momentum Explained

Robert D. Edwards and John Magee - Technical Analysis of Stock Trends.