Learn R Programming

TTR (version 0.13-1)

stoch: Stochastic Oscillator

Description

The stochastic oscillator is a momentum indicator that relates the location of each day's close relative to the high/low range over the past n periods. Developed by George C. Lane in the late 1950s.

Usage

stoch(HLC, n.fastK=14, ma.fastD=list("SMA", n=3), ma.slowD=ma.fastD)

Arguments

HLC
High-Low-Close price series to use. If only a univariate series is given, it will be used. See details.
n.fastK
Number of periods for fast %K (i.e. the number of past periods to use).
ma.fastD
A list whose first component is a string containing the fast %D moving average function name; additional parameters may also be specified as named components.
ma.slowD
Similar to ma.fastD, but for the fast %D moving average.

Value

  • A matrix containing the columns:
  • fastKFast %K
  • fastDFast %D
  • slowDSlow %D

Details

If an High-Low-Close series is provided, the indicator is calculated using the high/low values. If a vector is provided, the calculation only uses that series. This allows stochastics to be calculated for: (1) series that have no HLC definition (e.g. foreign exchange), and (2) stochastic indicators (e.g. stochastic RSI - see examples).

References

The following site(s) were used to code/document this indicator: http://www.fmlabs.com/reference/StochasticOscillator.htm http://www.equis.com/Customer/Resources/TAAZ?c=3&p=106 http://linnsoft.com/tour/techind/stoc.htm http://stockcharts.com/education/IndicatorAnalysis/indic_stochasticOscillator.html

See Also

See EMA, SMA, etc. for moving average options; and note Warning section. See WPR to compare it's results to fast %K.

Examples

Run this code
data(ttrc)
  stoch.osc <- stoch(ttrc[,c("High","Low","Close")])
  stoch.wpr <- WPR(ttrc[,c("High","Low","Close")])

  plot(tail(stoch.osc[,"fastK"], 100), type="l", main="Fast %K and Williams %R",
    ylab="", ylim = range(cbind(stoch.osc, stoch.wpr), na.rm=TRUE) )
  lines(tail(stoch.wpr, 100), col="blue")
  lines(tail(1-stoch.wpr, 100), col="red", lty="dashed")

  stoch.rsi <- stoch( RSI(ttrc[,"Close"]) )

Run the code above in your browser using DataLab