Search code examples
rquantmod

Add full stochastic curves to quantmod chart


Using R and the quantmod package, I am trying to add a full stochastic curve to the chart as it is displayed on http://www.stockta.com, which includes variables: %K(14,3) %D(3).

The documentation for addSMI lists four arguments:

n       periods
slow    slow
fast    fast
signal  signal 

I am not sure how I should translate the variables %K(14,3) %D(3) into addSMI to get the same stochastic curves as in http://www.stockta.com.

Any help would be appreciated.


Solution

  • addSMI adds the stochastic momentum index, not regular stochastics. It doesn't look like there's currently an addStoch function, but you can always use addTA

    require(quantmod)
    getSymbols("SPY")
    chartSeries(SPY, subset='2015/')
    addTA(stoch(HLC(SPY)), col=2:4)
    

    enter image description here

    The default values for stoch arguments nFastK, nFastD, and nSlowD are the same as the values you listed (14, 3, 3; respectively).