3

I'm writing a strategy on coin A at a 1min resolution. Now I need to get the hourly RSI on coin B.

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. What am I missing?

PineCoders-LucF
  • 8,288
  • 2
  • 12
  • 21
Leigh Bicknell
  • 854
  • 9
  • 19

2 Answers2

3

But this doesn't give the results I expected: I end up with an RSI that bounces from near 0 to 100 repeatedly. 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.

Say you get 60-minute data but your chart is a 10-minute chart. In that case the higher time frame data changes only every 6 bars. 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(). But then you calculate the RSI on the lower time frame chart. That way you get a spiky RSI because you end up calculating the RSI much more than needed.

To fix this, calculate the RSI directly on that hourly time frame with security() like so:

btcusdtHour = security("BITTREX:BTCUSDT", "60", rsi(close, 14))
plot(btcusdtHour)
Jos
  • 1,732
  • 3
  • 19
  • 39
1

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')
PeterO
  • 89
  • 1
  • 1
  • 5
  • 1
    Some sort of explanation would go well here. Also, correct me if I'm wrong but I can't see how this is getting the RSI of a different chart/security to the current one? It looks like it just gets the RSI on a different timeframe? – Leigh Bicknell Mar 28 '19 at 10:17