Documentation

macd

Moving Average Convergence/Divergence (MACD)

macd has been partially removed and will no longer accept a fints object (tsobj) argument. Use a matrix, timetable, or table instead for financial time series.

Use fts2timetable to convert a fints object to a timetable object.

Description

example

[MACDLine,SignalLine] = macd(Data) calculates the Moving Average Convergence/Divergence (MACD) line from the series of data and the nine-period exponential moving average from the MACDLine.

Examples

collapse all

Load the file SimulatedStock.mat, which provides a timetable (TMW) for financial data for TMW stock.

[MACDLine, signalLine]= macd(TMW);
plot(MACDLine.Time,MACDLine.Close,signalLine.Time,signalLine.Close);
legend('MACDLine','NinePerMA')
title('MACD for TMW') Input Arguments

collapse all

Data with high, low, open, close information, specified as a matrix, table, or timetable. For matrix input, Data is an M-by-4 matrix of high, low, opening, and closing prices. Timetables and tables with M rows must contain variables named 'High', 'Low', 'Open', and 'Close' (case insensitive).

Data Types: double | table | timetable

Output Arguments

collapse all

MACD series, returned with the same number of rows (M) and type (matrix, table, or timetable) as the input Data. The MACDLine is calculated by subtracting the 26-period (7.5%) exponential.

Nine-period exponential series, returned with the same number of rows (M) and type (matrix, table, or timetable) as the input Data. The nine-period (20%) exponential moving average of the MACDLine is used as the SignalLine.

collapse all

MACD

The MACD is calculated by subtracting the 26-period (7.5%) exponential moving average from the 12-period (15%) moving average.

The nine-period (20%) exponential moving average of the MACD line is used as the "signal" line. When the two lines are plotted, they can give you indications on when to buy or sell a stock, when overbought or oversold is occurring, and when the end of trend may occur. For example, when the MACD and the 20-day moving average line have crossed and the MACD line becomes below the other line, it is time to sell.

 Achelis, S. B. Technical Analysis from A to Z. Second Edition. McGraw-Hill, 1995, pp. 166–168.