首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >长度较大的RSI

长度较大的RSI
EN

Stack Overflow用户
提问于 2021-02-08 19:33:55
回答 1查看 123关注 0票数 0

我想将1D RSI合并到4H时间框架中。我尝试过使用分辨率或安全函数,但这两个函数都在每日时间框架接近尾声时更新,并一直保持到第二天。为了从1D图中得到大约20SMA,我会在4H图中绘制120SMA。它并不完全相同,因为输入更多,但它更精确,更具反应性。但是,如果我在4H图中绘制一个1D 14RSI作为84RSI,我只会得到一个无用的指标,它总是在50区域上下浮动。

是否有方法可以获得与SMA相似的结果?

代码语言:javascript
复制
//@version=4
study(title="Relative Strength Index", shorttitle="RSI", format=format.price, precision=2, resolution="")
len = input(14, minval=1, title="Length")
src = input(close, "Source", type = input.source)

rma_(src, length) =>
    alpha = 1/length
    sum = 0.0
    sum := na(sum[1]) ? sma(src, length) : alpha * src + (1 - alpha) * nz(sum[1])

rsi_(x, y) => 
    u = max(x - x[1], 0)
    d = max(x[1] - x, 0)
    rs = rma_(u, y) / rma_(d, y)
    res = 100 - 100 / (1 + rs)
    res

rsi = rsi_(src, len)
plot(rsi, "RSI", color=color.blue, linewidth = 1)
band1 = hline(70, "Upper Band", color=#C0C0C0)
band0 = hline(30, "Lower Band", color=#C0C0C0)
fill(band1, band0, color=#9915FF, transp=90, title="Background")

提亚

EN

回答 1

Stack Overflow用户

发布于 2021-02-14 21:33:28

代码语言:javascript
复制
//@version=4
study(title="Help (Relative Strength Index)", shorttitle="RSI", format=format.price, precision=2, resolution="")
len = input(14, minval=1, title="Length")
src = input(close, "Source", type = input.source)

rma_(src, length) =>
    alpha = 1/length
    sum = 0.0
    sum := na(sum[1]) ? sma(src, length) : alpha * src + (1 - alpha) * nz(sum[1])

rsi_(x, y) => 
    u = max(x - x[1], 0)
    d = max(x[1] - x, 0)
    rs = rma_(u, y) / rma_(d, y)
    res = 100 - 100 / (1 + rs)
    res

rsi = rsi_(src, len) //currend TF
rsiD = security(syminfo.tickerid, "D", rsi_(src, len))  // TF='D'
plot(rsi, "RSI", color=color.blue, linewidth = 1)
plot(rsiD, "RSI", color=color.green, linewidth = 1)
band1 = hline(70, "Upper Band", color=#C0C0C0)
band0 = hline(30, "Lower Band", color=#C0C0C0)
fill(band1, band0, color=#9915FF, transp=90, title="Background")

上面的窗口是时间范围D,下面的窗口是4H。RSI的值是相同的,并且实时同步变化。这有什么问题吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66100833

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档