【问题标题】:quantmod display weekly indicator on daily chartquantmod 在日线图上显示周指标
【发布时间】:2017-08-15 06:14:26
【问题描述】:

我正在尝试在日线图上显示每日和每周 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 不会出现在图上。有人可以帮忙吗?

【问题讨论】:

    标签: r quantmod quantitative-finance technical-indicator


    【解决方案1】:

    当您绘制每周点时,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 水平线放在第三条上?
    • @geodex 查看编辑。使用on 参数(on = 1,2 或 3)来选择要添加其他曲线的绘图面板。
    • 干杯@FXQuantTrader
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 2017-10-28
    相关资源
    最近更新 更多