在Quantmod中的chartSeries上绘制线条

时间:2017-03-10 22:56:43

标签: r quantmod

这很好用:

getSymbols("EBAY") 
chartSeries(EBAY,TA=NULL, theme="white")
addTA(EMA(Cl(EBAY)), on=1, col=6)
abline(h=50, col = 6) 

但这会绘制chartSeries,但不会绘制水平线。不确定我错过了什么。

S <- as.xts(read.zoo(text="date,open,high,low,close,volume
2017-03-10 18:00:00,442.50,442.50,442.50,442.50,1
2017-03-10 18:01:00,442.50,442.50,442.50,442.50,8
2017-03-10 18:02:00,442.50,442.50,442.50,442.50,2
2017-03-10 18:03:00,442.50,442.50,442.50,442.50,3
2017-03-10 18:04:00,442.50,442.50,442.50,442.50,68
2017-03-10 18:05:00,442.50,442.50,442.50,442.50,20
2017-03-10 18:06:00,442.25,442.25,442.25,442.25,10
2017-03-10 18:07:00,442.50,442.50,442.25,442.25,3
2017-03-10 18:08:00,442.25,442.50,442.25,442.50,2
2017-03-10 18:09:00,442.25,442.25,442.25,442.25,38",
FUN=paste, FUN2=as.POSIXct, header=TRUE, sep=","))

chartSeries(S, theme = chartTheme("white"), type = "candle") #subset = m,TA = NULL)
abline(h=442.3, col = 6) 
#segments(0, 442.3, 90, 442.3)

1 个答案:

答案 0 :(得分:2)

您的第一个示例有效,因为设备上只绘制了一个绘图(OHLC蜡烛)。第二个例子不起作用,因为该设备包括两个图,OHLC蜡烛和低音量条形图。

如果您想使用chartSeries之类的内容向abline添加行,则应使用addLines

chartSeries(S, theme=chartTheme("white"), type="candle")
addLines(h=442.3, col=6)