Search code examples
rchartsshinyquantmodtechnical-indicator

Quantmod addMACD() remove line plot


I was currently using Quantmod to visualize technical analysis of equity data. When I came across the addMACD() functions for adding MACD graph and it works fine, except when I need to visualize the histogram only instead of the line graph.

addMACD(fast = display$macdFast, slow = display$macdSlow, signal = display$macdSignal, histogram = TRUE)

After reading through the documentation, I cannot figure out a way to remove the line plot of MACD graph. Is is possible to remove line plot while retaining histogram plot for MACD?

enter image description here


Solution

  • I always seem have problems with creating complicated newTA objects with quantmod, but here is an SO example. I find it easier to use rtsplot. That is a plotting package for xts objects but based on the base plots.

    Since the macd histogram is nothing but the difference between the macd and the macd signal you can create your own histogram values:

    library(quantmod)
    goog <- getSymbols("GOOGL", from = "2019-01-01", auto.assign = F)
    goog_macd <- MACD(goog$GOOGL.Close)
    goog_macd_his <- goog_macd$macd - goog_macd$signal
    
    
    library(rtsplot)
    layout(c(1,1,1,2))
    rtsplot(goog, type = "candle")
    rtsplot(goog_macd_his , type = "h", lwd = 2)
    

    enter image description here