quantmod 在日线图上显示每周指标
quantmod display weekly indicator on daily chart
我正在尝试在日线图上显示每日和每周 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。有人可以帮忙吗
绘制每周点时,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)
我正在尝试在日线图上显示每日和每周 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。有人可以帮忙吗
绘制每周点时,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)