This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.


Moving Average Convergence/Divergence (MACD)


[macdvec,nineperma] = macd(data)
[macdvec,nineperma] = macd(data,dim)
macdts = macd(tsobj,series_name)



Data matrix


Dimension. Default = 1 (column orientation).


Financial time series object


Data series name


[macdvec,nineperma] = macd(data) calculates the Moving Average Convergence/Divergence (MACD) line, macdvec, from the data matrix, data, and the nine-period exponential moving average, nineperma, from the MACD line.

When the two lines are plotted, they can give you an indication of whether to buy or sell a stock, when an overbought or oversold condition is occurring, and when the end of a trend might occur.

The MACD is calculated by subtracting the 26-period (7.5%) exponential moving average from the 12-period (15%) moving average. The 9-day (20%) exponential moving average of the MACD line is used as the signal line. For example, when the MACD and the 20% moving average line have just crossed and the MACD line falls below the other line, it is time to sell.

[macdvec,nineperma] = macd(data,dim) lets you specify the orientation direction for the input. If the input data is a matrix, you must indicate whether each row is a set of observations (dim = 2) or each column is a set of observations (dim = 1, the default).

macdts = macd(tsobj,series_name) calculates the MACD line from the financial time series tsobj, and the nine-period exponential moving average from the MACD line. The MACD is calculated for the closing price series in tsobj, presumed to have been named Close. The result is stored in the financial time series object macdts. The macdts object has the same dates as the input object tsobj and contains only two series, named MACDLine and NinePerMA. The first series contains the values representing the MACD line and the second is the nine-period exponential moving average of the MACD line.


collapse all

This example shows how to compute the MACD for Disney stock and plot the results.

load disney.mat
dis_CloseMACD = macd(dis);
dis_OpenMACD = macd(dis, 'OPEN');
title('MACD for Disney')


[1] Achelis, Steven B. Technical Analysis From A To Z. Second Edition. McGraw-Hill, 1995, pp. 166–168.

Introduced before R2006a

Was this topic helpful?