this
Description
The Moving Average Convergence-Divergence (MACD) measured the relative change between two moving averages. fmacd calculates the difference between a "slow" EMA and a "fast" EMA and plots the difference and an EMA of that difference as a signal line. If the MACD is above the zero line and the MACD line is above its EMA signal line an equity is said to be "trending" upwards. Some traders use MACD crossovers as entry and exit trigger points for positions. The difference between the MACD line and its EMA signal Line is plotted as a histogram on the same chart with the MACD lines. When the histogram is above zero and green the MACD line is above the EMA signal line. If it is below zero and red then the MACD is below the signal line. The MACD line is plotted as a thin red line and the signal line as a thin blue line. MACD is a momentum indicator.



The histogram is plotted at an enhanced scale for better viewing so no reliance should be placed on the histogram value. The relative scale between histogram values is correct, however. Since the relative scale is correct, the histogram can be safely used as a divergence indicator. The MACD line scales are on a 1:1 scale.

The View title displays the name of the indicator and the smoothing periods, the MACD lookback period and an EMA signal line lookback period. The Titlebar Chart Code for this indicator is macd. (see EAS Titlebar Chart Codes)

Inputs
p1
and p2 are the lookback periods for the "fast" and "slow" EMA's used to calculate the MACD line. p0 defines the EMA signal line lookback period.

Output Data & Plotting
If returnflag is set to "data" a (b-a+1)-row by 3-column matrix of data will be returned. The output is only valid for data points beyond the lookback period, p0macd+p2macd, in time. The first column of the output is the value of the MACD line at any given point in time, the second column is the value of the EMA signal line and the third column is the value of the difference between the MACD line and the signal line. The third value is what defines the MACD histogram. The MACD histogram raw data is returned, rather than the enhanced scale data.

Background Reading
Further information regarding this indicator can be found in the following resources:
Stockcharts.com MACD
Clearstation.com Reading Graphs
Equis.com MACD
"Technical Analysis Explained, 3rd Ed", by Pring, McGraw/Hill, 1991
"The Visual Investor", by Murphy, Wiley, 1996