Learn R Programming

TTR (version 0.13-1)

Oscillators: 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.

Value

  • The MACD function returns a matrix containing the columns:
  • macdThe MACD line.
  • signalThe MACD signal line (a moving average of the MACD).
  • The oscillator function returns a matrix containing the columns:
  • oscillatorThe price (volume, etc.) oscillator.
  • signalThe oscillator signal line (a moving average of the oscillator).

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.

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

Run this code
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)

Run the code above in your browser using DataLab