我试图在日线图上显示每日和每周RSI,但没有成功
getSymbols('JNUG')
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))')
我也尝试了以下内容:
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 =14))
每周RSI没有出现在情节中。有人可以帮忙。
答案 0 :(得分:3)
绘制每周点数时,在合并与原始日常数据之间填充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')
产生这个:
编辑:在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)