Search code examples
rchartsquantmod

Quantmod Oscillators


Utilizing the chartSeries function in the quantmod package, I want to modify the RSI oscillator. Given an xts object containing OHLC price data, here is the call that I am using:

chartSeries(plot_report[, 1:4],
        name        = substr(ticker, 1, nchar(ticker) - 4),
        theme       = chartTheme('white.mono', grid.col = NA),
        TA          = c(addRSI(n = 14, maType = "SMA")),
        type        = "line",
        bar.type    = 'ohlc',
        major.ticks = 'months',
        show.grid   = FALSE,
        log.scale   = TRUE)

Generating this chart: enter image description here

I have four questions:

  1. How can I change the default color of blue to something else? I have tried: c(addRSI(n = 14, maType = "SMA", col = "black")). However, I get the "unused argument" error.

  2. Can I draw horizontal lines in the oscillator panel? Traditional RSI's have a horizontal red line at a y-axis value of 70 and a horizontal green line at a y-axis value of 30 to indicate overbought/oversold levels.

  3. Is it possible to plot another calculation as an oscillator line below the chart? I have some proprietary oscillators that I want to visualize instead of the RSI or any of the indicators in the TTR package.

  4. How can I get involved in improving the quantmod charting functionality; is this project being actively maintained?


Solution

    1. You can't. You would need to add ... to the arguments for addRSI and modify the body of the function to use ... appropriately. A work-around is to calculate RSI manually, then call addTA as done in the answer to Change line colors of technical indicators made by R quantmod TTR?.
    2. Use addLines:

    getSymbols("SPY"); chartSeries(SPY, TA="addRSI();addLines(h=c(30,70), on=2)")

    1. Use addTA with the object containing your proprietary data.
    2. See quantmod's GitHub page. Yes, it's actively maintained. The last update was pushed to CRAN a couple months ago.