问题
I tried to plot with chartSeries in the R package quantmod, and add SMI lines using the addSMI() method. SMI generates two lines - the solid line is visible while the dotted line is not. Can anybody propose a way to change the color of the dotted line so that it is more noticeable? Here are the codes. I also attached an image generated.
library(quantmod)
x<-getSymbols("IBM", src='yahoo', from="2014-11-20", to="2015-05-20", auto.assign=FALSE)
chartSeries(x, name=paste(stockFirmName,"(",stock,")"), line.type = "l",
TA=c(addSMI()), theme = chartTheme("white", up.col='red',dn.col="blue"), major.ticks="months", color.vol=FALSE, multi.col = FALSE)
title(main="", cex.main=2.5, font.main=4, col.main="gold",
sub="", cex.sub=1.5, font.sub=4, col.sub="blue",
xlab="", ylab="",col.lab="blue", cex.lab=1)
See below for the two lines in the bottom SMI chart.
!
Edits: Robert's method made it work. Here is latest code and chart.
library(quantmod)
x<-getSymbols("IBM", src='yahoo', from="2014-11-20", to="2015-05-20", auto.assign=FALSE)
chartSeries(x, name=paste("IBM"), line.type = "l",
TA=NULL,
theme = chartTheme("white", up.col='red',dn.col="blue"),
major.ticks="months", color.vol=FALSE, multi.col = FALSE)
addTA(SMI(HLC(x)),col=2:3)
title(main="", cex.main=2.5, font.main=4, col.main="gold",
sub="", cex.sub=1.5, font.sub=4, col.sub="blue",
xlab="", ylab="",col.lab="blue", cex.lab=1)
The chart is as follows.
The question now is: the chart can be generated by running line by line. If I "source" the source codes in a batch mode, The SMI subchart does not show up at all. Any ideas?
回答1:
Try this:
chartSeries(x, name=paste(stockFirmName,"(",stock,")"), line.type = "l",
TA=NULL, theme = chartTheme("white", up.col='green',dn.col='red'), major.ticks="months", color.vol=FALSE)
addTA(SMI(HLC(x)),col=2:3)
来源:https://stackoverflow.com/questions/30381639/change-line-colors-of-technical-indicators-made-by-r-quantmod-ttr