Oscillators {TTR}R Documentation

Oscillators

Description

The oscillators documented in this page compare a fast moving average (MA) of a series with a slow MA of the same series. The most popular price oscillator is probably the MACD, which was developed by Gerald Appel.

Usage

  oscillator(x, ma.slow = list("EMA", n=20), ma.fast = list("EMA", n=10),
             ma.sig = list("EMA", n=10), percent = FALSE)
        MACD(x)

Arguments

x Series to use; usually price, but can be volume, etc.
ma.slow A list whose first component is a string containing the slow moving average function name; additional parameters may also be specified as named components.
ma.fast Similar to ma.slow, but for the fast moving average.
ma.sig Similar to ma.slow, but for the signal line moving average.
percent logical; if TRUE, the percentage difference between the slow and fast moving averages is returned, otherwise the difference between the respective averages is returned.

Details

The oscillator function either subtracts the short MA from the long MA, or finds the rate of change between the short MA and the long MA.

Value

The MACD function returns a matrix containing the columns:

macd The MACD line.
signal The MACD signal line (a moving average of the MACD).
oscillator The price (volume, etc.) oscillator.
signal The oscillator signal line (a moving average of the oscillator).

Note

The MACD is a special case of the general oscillator applied to price. The MACD function is provided for convenience. 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.

Author(s)

Josh Ulrich

References

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 Also

See EMA, SMA, etc. for moving average options; and note Warning section.

Examples

  data(ttrc)

  macd <- MACD(ttrc[,"Close"])
  osc  <- oscillator( ttrc[,"Close"], ma.slow = list("EMA",n=26),
                      ma.fast = list("EMA",n=12), ma.sig = list("EMA", n=9) )

  # Should be TRUE
  identical(macd,osc)

[Package TTR version 0.13-1 Index]