Reputation: 5
I'm creating a script for TradingView using a previous public indicator. I added a couple things, but having issues with the multi time frame input not working when I try setting the indicator on the chart. It just stays on the same chart (for instance, the 1m) but does not change when I set it to something else (let's say the 5m).
I already added the code:
timeframe = input.timeframe(title="Time Frame", defval="1")
This saves and compiles just fine but doesn't change the indicator when I'm using it. So I'm assuming it's a small error. Could anyone help me tweak this please? Here is the full script:
//@version=5
indicator(title="Relative Strength Index x2", shorttitle="MTF RSIx2")
src = close
len_fast = input(14, title="Fast RSI Length")
len_slow = input(28, title="Slow RSI Length")
timeframe = input.timeframe(title="Time Frame", defval="1")
up_fast = ta.rma(math.max(ta.change(src), 0), len_fast)
down_fast = ta.rma(-math.min(ta.change(src), 0), len_fast)
rsi_fast = down_fast == 0 ? 100 : up_fast == 0 ? 0 : 100 - (100 / (1 + up_fast / down_fast))
up_slow = ta.rma(math.max(ta.change(src), 0), len_slow)
down_slow = ta.rma(-math.min(ta.change(src), 0), len_slow)
rsi_slow = down_slow == 0 ? 100 : up_slow == 0 ? 0 : 100 - (100 / (1 + up_slow / down_slow))
diff = rsi_fast - rsi_slow + 50
diff_color = diff > diff[1] ? color.new(color.green, 50) : color.new(color.red, 50)
diff_plot = plot(diff, title="Difference", color=diff_color, style=plot.style_columns, histbase=50)
rsi_slow_plot = plot(rsi_slow, title="RSI Slow", color=color.white)
rsi_fast_plot = plot(rsi_fast, title="RSI Fast", color=color.blue)
level1 = 70
level2 = 60
level3 = 40
level4 = 30
hline(level1, "Level 1", color.new(color.red, 50), linewidth=1)
hline(level2, "Level 2", color.new(color.white, 50), linewidth=1)
hline(level3, "Level 3", color.new(color.white, 50), linewidth=1)
hline(level4, "Level 4", color.new(color.lime, 50), linewidth=1)
I already tried added the code snippet I mentioned...
timeframe = input.timeframe(title="Time Frame", defval="1")
I was expecting that would allow me to use the indicator on the 1m chart, but the indicator could be set to sow 5m data/plot points instead of 1m to get a larger view of the move.
Upvotes: 0
Views: 3010
Reputation: 21332
input.timeframe()
is just an input function so the user can select a timeframe to be used. It does not magically make the indicator multi timeframe. You still need to code for it using the security() function.
Alternatively, you can try adding timeframe="", timeframe_gaps=true
to your indicator()
call.
Upvotes: 0