当您绘制每周点时,NA 值将在合并到原始每日数据之间填充。每周 RSI 图希望将点和 NA 连接在一起作为线图,但是在有 NA 的地方没有画线,最后也没有画线。
试试这个:
chartSeries(JNUG, subset = 'last 4 months', dn = 'red', TA = 'addRSI(n=14); addLines(h = c(30, 70), on = 2, col = "red"); addTA(RSI(Cl(to.weekly(JNUG)), n =2), type = "p")')
或者,如果你想要换行,试试这个(见最低add_TA
调用):
library(quantmod)
chart_Series(JNUG, subset = '2016-11/')
add_RSI(n= 14)
v <- to.weekly(JNUG)
add_TA(merge(xts(order.by = index(JNUG)), RSI(Cl(v))), type = 'p')
#na.spline interpolates between points smoothly. Could also use fill = na.locf (produces a step function), etc ...
add_TA(merge(xts(order.by = index(JNUG)), RSI(Cl(v)), fill = na.spline), type = 'l')
产生这个:
![在此处输入图像描述](https://i.stack.imgur.com/PpphT.png)
编辑:在子图上添加水平线的一种方法add_TA
:
chart_Series(JNUG, subset = '2016-01/')
add_RSI(n= 14)
v <- to.weekly(JNUG)
# Note: na.locf does not introduce 'lookforward bias' in visualised technical indicator plots, while na.spline does.
add_TA(merge(xts(order.by = index(JNUG)), RSI(Cl(v)), fill = na.locf), type = 'l')
low_rsi <- 30
hi_rsi <- 70
xrsi_low <- xts(order.by = index(JNUG), x = rep(low_rsi, NROW(JNUG)))
xrsi_hi <- xts(order.by = index(JNUG), x = rep(hi_rsi, NROW(JNUG)))
add_TA(xrsi_low, col = "purple", type = 'l', on = 3, lty = 2)
add_TA(xrsi_hi, col = "purple", type = 'l', on = 3, lty = 4)
![在此处输入图像描述](https://i.stack.imgur.com/KSIuB.png)