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)