MACD {TTR} | R Documentation |
The MACD was developed by Gerald Appel and is probably the most popular price oscillator. The MACD function documented in this page compares a fast moving average (MA) of a series with a slow MA of the same series. It can be used as a generic oscillator for any univariate series, not only price.
MACD(x, nFast=12, nSlow=26, nSig=9, maType="EMA", percent=TRUE, ...)
x |
Series to use; usually price, but can be volume, etc. |
nFast |
Number of periods for fast moving average. |
nSlow |
Number of periods for slow moving average. |
nSig |
Number of periods for signal moving average. |
maType |
Either: (1) A function or a string naming the function to be called, or (2) a list with the first component like (1) above, and additional parameters specified as named components. See Examples. |
percent |
logical; if TRUE , the percentage difference between the fast and slow moving
averages is returned, otherwise the difference between the respective averages is returned. |
... |
Other arguments to be passed to the maType function in case (1) above. |
The MACD function either subtracts the fast MA from the slow MA, or finds the rate of change between the fast MA and the slow MA.
The MACD function returns a matrix containing the columns:
macd |
The price (volume, etc.) oscillator. |
signal |
The oscillator signal line (a moving average of the oscillator). |
The MACD is a special case of the general oscillator applied to price. The MACD can be used as a general oscillator applied to any series. Time periods for the MACD are often given as 26 and 12, but the function originally used exponential constants of 0.075 and 0.15, which are closer to 25.6667 and 12.3333 periods.
Josh Ulrich
The following site(s) were used to code/document this indicator:
http://www.fmlabs.com/reference/MACD.htm
http://www.fmlabs.com/reference/PriceOscillator.htm
http://www.fmlabs.com/reference/PriceOscillatorPct.htm
http://stockcharts.com/education/IndicatorAnalysis/indic_MACD1.html
http://stockcharts.com/education/IndicatorAnalysis/indic_priceOscillator.html
See EMA
, SMA
, etc. for moving average options; and note Warning
section.
data(ttrc) macd <- MACD( ttrc[,"Close"], 12, 26, 9, maType="EMA" )