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, percent = TRUE, ...)
Object that is coercible to xts or matrix; usually price, but can be volume, etc.
Number of periods for fast moving average.
Number of periods for slow moving average.
Number of periods for signal moving average.
Either:
A function or a string naming the function to be called.
A list with the first component like (1) above, and additional parameters specified as named components. See Examples.
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.
A object of the same class as x
or a matrix (if try.xts
fails) containing the columns:
The price (volume, etc.) oscillator.
The oscillator signal line (a moving average of the oscillator).
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 following site(s) were used to code/document this indicator: Moving Average Convergence/Divergence (MACD): http://www.fmlabs.com/reference/MACD.htm https://www.metastock.com/Customer/Resources/TAAZ/?p=66 https://www.linnsoft.com/techind/macd http://www.stockcharts.com/school/doku.php?id=chart_school:technical_indicators:moving_average_convergence_divergence_macd Price Oscillator: http://www.fmlabs.com/reference/PriceOscillator.htm http://www.fmlabs.com/reference/PriceOscillatorPct.htm https://www.metastock.com/Customer/Resources/TAAZ/?p=94 http://www.stockcharts.com/school/doku.php?id=chart_school:technical_indicators:price_oscillators_ppo Volume Oscillator: http://www.fmlabs.com/reference/PVO.htm https://www.metastock.com/Customer/Resources/TAAZ/?p=122
See EMA
, SMA
, etc. for moving average
options; and note Warning section.
# NOT RUN {
data(ttrc)
macd <- MACD( ttrc[,"Close"], 12, 26, 9, maType="EMA" )
macd2 <- MACD( ttrc[,"Close"], 12, 26, 9,
maType=list(list(SMA), list(EMA, wilder=TRUE), list(SMA)) )
# }
Run the code above in your browser using DataLab