%% Moving Average Convergence/Divergence (MACD)
% Moving Average Convergence/Divergence (MACD) is an oscillator function used by technical analysts to spot overbought and oversold conditions. Use the IBM® stock price data contained in the supplied file ibm9599.dat. First, create a financial time series object from the data using ascii2fts. Look at the portion of the time series covering the 3-month period between October 1, 1995 and December 31, 1995. At the same time fill any missing values due to holidays within the time period specified:

ibm = ascii2fts('ibm9599.dat', 1, 3, 2);
part_ibm = fillts(ibm('10/01/95::12/31/95'));

%
% Calculate the MACD, which when plotted produces two lines; the first line is the MACD line itself and the second is the nine-period moving average line:

macd_ibm = macd(part_ibm);

% When you call macd without giving it a second input argument to specify a particular data series name, it searches for a closing price series named Close (in all combinations of letter cases).
%
% Plot the MACD lines and the High-Low plot of the IBM stock prices in two separate plots in one window.

subplot(2, 1, 1);
plot(macd_ibm);
title('MACD of IBM Close Stock Prices, 10/01/95-12/31/95');
datetick('x', 'mm/dd/yy');
subplot(2, 1, 2);
highlow(part_ibm);
title('IBM Stock Prices, 10/01/95-12/31/95');
datetick('x', 'mm/dd/yy')

% Copyright 2015 The MathWorks, Inc.