简体   繁体   English

如何从 TradingView Pine Script 中的不同图表获取每小时 RSI?

[英]How to get hourly RSI from different chart in TradingView Pine Script?

I'm writing a strategy on coin A at a 1min resolution.我正在以 1 分钟的分辨率在硬币 A 上编写策略。 Now I need to get the hourly RSI on coin B.现在我需要获得代币 B 的每小时 RSI。

I've tried:我试过:

btcusdtHour = security("BITTREX:BTCUSDT", "60", close)
plot(rsi(btcusdtHour, 14))

But this doesn't give the results I expected: I end up with an RSI that bounces from near 0 to 100 repeatedly.但这并没有给出我预期的结果:我最终得到的 RSI 反复从接近 0 反弹到 100。 What am I missing?我错过了什么?

But this doesn't give the results I expected: I end up with an RSI that bounces from near 0 to 100 repeatedly.但这并没有给出我预期的结果:我最终得到的 RSI 反复从接近 0 反弹到 100。 What am I missing?我错过了什么?

When you use the security() function to fetch price data from a higher time frame, you end up with values that don't change that often.当您使用security()函数从更高的时间范围获取价格数据时,您最终会得到不经常更改的值。

Say you get 60-minute data but your chart is a 10-minute chart.假设您获得 60 分钟的数据,但您的图表是 10 分钟的图表。 In that case the higher time frame data changes only every 6 bars.在这种情况下,较高的时间框架数据仅每 6 根柱线变化一次。 But if you still calculate based on that lower time frame, the results will be off.但是,如果您仍然根据较低的时间范围进行计算,则结果将是错误的。

The same thing happens with your code:您的代码也会发生同样的事情:

btcusdtHour = security("BITTREX:BTCUSDT", "60", close)
plot(rsi(btcusdtHour, 14))

Here you fetch the hourly prices with security() .在这里,您可以使用security()获取每小时的价格。 But then you calculate the RSI on the lower time frame chart.但随后您可以在较低的时间框架图表上计算 RSI。 That way you get a spiky RSI because you end up calculating the RSI much more than needed.这样你就会得到一个尖锐的 RSI,因为你最终计算出的 RSI 比需要的要多得多。

To fix this, calculate the RSI directly on that hourly time frame with security() like so:要解决此问题,请使用security()直接在每小时时间范围内计算 RSI,如下所示:

btcusdtHour = security("BITTREX:BTCUSDT", "60", rsi(close, 14))
plot(btcusdtHour)

Here you are.你在这里。

//@version=3
study("RSI MTF by PeterO", overlay=false)

rsi_mtf(source,mtf,len) =>
    change_mtf=source-source[mtf]
    up_mtf = rma(max(change_mtf, 0), len*mtf)
    down_mtf = rma(-min(change_mtf, 0), len*mtf)
    rsi_mtf = down_mtf == 0 ? 100 : up_mtf == 0 ? 0 : 100 - (100 / (1 + up_mtf / down_mtf))

lenrsi=input(14, title='lookback of RSI')
mtf_=input(60, title="Higher TimeFrame Multiplier")
plot(rsi_mtf(close,mtf_,lenrsi), color=orange, title='RSI')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM