5

I am trying to develop a multiple time-frame RSI using pine-script on trading view but I seem to have an issue with shorter term RSI in a longer term chart view.

For example, the following code will display 5-min RSI. It will display the RSI appropriately if I have the chart set at 5-min. But when I select a larger time-frame (e.g., 1 hour, etc) the value becomes incorrect.

study("Multi Time Frame RSI", "MTF RSI", overlay=false)
src = input(title="Source", type=source, defval=close)
_5min_rsi = security(tickerid, "5", rsi(src, 14))
plot(_5min_rsi, title="5min_RSI", color=purple, linewidth=1)

I believe the problem has to do with series data being operated on. For some reason when I use security with "5" as my resolution, its data gets lost in the higher time-frame charts and it uses the close of a different series for that time. At least that is my hypothesis. I believe I am using the "security" function wrong or possibly providing the wrong input "src" to the RSI function.

I have also tried switching RSI and security to see if I can fetch the 5 min series data and input that into my RSI function but that doesn't work any better. E.g.

_5min_rsi = rsi(security(tickerid, "5", src), 14)

Essentially, what I need to see is that no matter what time-frame I am on in trading view I should see 5 min RSI calculated correctly. In the current state, the code will only work in 1 min and 5 min time-frames which is obviously unacceptable.

PineCoders-LucF
  • 8,288
  • 2
  • 12
  • 21
LeanMan
  • 474
  • 1
  • 4
  • 18
  • how will it work ? If I'm looking at the daily chart, what data is shown 5 points in the past ? Is it 5m RSI from 25 minutes ago or 5m RSI from 5 days ago ? –  Apr 30 '19 at 07:21
  • did you solve this ? i want to show 15m, 1 hour and 1D RSI table on chart irrespective of current timeframe of the chart. but facing same issue, can't get data from lower TF. One solution i'm thinking is getting current TF of chart and only showing higher TF RSI in table. – hp2017 Aug 24 '21 at 16:08

2 Answers2

5

After playing a bit with the security() function, I don't think the security() function works this way.

If we set the resolution to "1" (that is 1 minute) and go to the 1D chart, we will get only values for the last minute bar per one daily bar.

out = security("AAPL", "1", close)

If we set them vice-versa ("D" for resolution and 1m chart), all of the minute bars will be identical - they are getting their value from the last daily bar.

out = security("AAPL", "D", close)
  • Good point! Its so obvious now. A 1 minute RSI can't exist in the daily timeframe. Hmmm...I guess when I go to a larger timeframe, I want the information of the very last length number of values of that sub-timeframe and ignore data loss due to switching timeframes. I would have expected this to be the default behavior. Is there way for me to operate on sub-timeframe data when moving to larger timeframes? This would be a universal problem for any multi-timeframe indicator. – LeanMan Apr 30 '19 at 23:45
5

According to documents:

security function was designed to request data of a timeframe higher than the current chart timeframe. On a 60 minutes chart, this would mean requesting 240, D, W, or any higher timeframe. It is not recommended to request data of a timeframe lower than the current chart timeframe, for example, 1-minute data from a 5 minutes chart. The main problem with such a case is that some part of a 1-minute data will be inevitably lost, as it’s impossible to display it on a 5 minutes chart and not to break the time axis. In such cases, the behavior of security can be rather unexpected.

Behnam Maboudi
  • 655
  • 5
  • 21