Moving Average Convergence/Divergence (MACD) - MATLAB macd (2024)

Moving Average Convergence/Divergence (MACD)

collapse all in page

Syntax

[MACDLine,SignalLine] = macd(Data)

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

Calculate the Moving Average Convergence/Divergence for a Stock

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

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

Moving Average Convergence/Divergence (MACD) - MATLAB macd (1)

Input Arguments

collapse all

DataData with high, low, open, close information
matrix | table | timetable

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

MACDLine — MACD series
matrix | table | timetable

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.

SignalLine — Nine-period exponential series
matrix | table | timetable

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.

More About

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.

References

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

Version History

Introduced before R2006a

expand all

fints object support for the Data input argument is removed.

The Data input accepts negative prices.

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Moving Average Convergence/Divergence (MACD) - MATLAB macd (2)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

Europe

Asia Pacific

Contact your local office

Moving Average Convergence/Divergence (MACD) - MATLAB macd (2024)
Top Articles
Latest Posts
Article information

Author: Dan Stracke

Last Updated:

Views: 6134

Rating: 4.2 / 5 (63 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Dan Stracke

Birthday: 1992-08-25

Address: 2253 Brown Springs, East Alla, OH 38634-0309

Phone: +398735162064

Job: Investor Government Associate

Hobby: Shopping, LARPing, Scrapbooking, Surfing, Slacklining, Dance, Glassblowing

Introduction: My name is Dan Stracke, I am a homely, gleaming, glamorous, inquisitive, homely, gorgeous, light person who loves writing and wants to share my knowledge and understanding with you.