0

Please help me write the syntax and use the RSI Divergence value from 15 minutes to the 1-minute timeframe.

Here is the original code. I want to use this expression in the 1minute Strategy:
"divergence > 0" from the 15-minute timeframe

study(title="RSI Divergence", shorttitle="RSI Divergence")
src_fast = close, len_fast = input(5, minval=1, title="Length Fast RSI")
src_slow = close, len_slow = input(14,minval=1, title="Length Slow RSI")
up_fast = rma(max(change(src_fast), 0), len_fast)
down_fast = rma(-min(change(src_fast), 0), len_fast)
rsi_fast = down_fast == 0 ? 100 : up_fast == 0 ? 0 : 100 - (100 / (1 + up_fast / down_fast))
up_slow = rma(max(change(src_slow), 0), len_slow)
down_slow = rma(-min(change(src_slow), 0), len_slow)
rsi_slow = down_slow == 0 ? 100 : up_slow == 0 ? 0 : 100 - (100 / (1 + up_slow / down_slow))
//plotfast = plot(rsi_fast, color=blue)
//plotslow = plot(rsi_slow, color=orange)
divergence = rsi_fast - rsi_slow
plotdiv = plot(divergence, color = divergence > 0 ? lime:red, linewidth = 2)
//band1 = hline(70,color=green)
//band0 = hline(30,color=red)
band = hline(0)

I know the security function needs to be used like this perhaps

divergence15minutes = security("syminfo.tickerid", "15", divergence)

John Smith
  • 55
  • 1
  • 1
  • 3

2 Answers2

1

You were almost there :)

You are using older version of pine script (v1), so you'll need:

divergence15minutes = security(tickerid, "15", divergence)
mr_statler
  • 1,913
  • 2
  • 3
  • 14
0
//@version=5
indicator("RSI Divergence", shorttitle="RSI Div")
src_fast = close
len_fast = input.int(5, title="Length Fast RSI", minval=1)
src_slow = close
len_slow = input.int(14, title="Length Slow RSI", minval=1)
up_fast = ta.rma(math.max(ta.change(src_fast), 0), len_fast)
down_fast = ta.rma(-math.min(ta.change(src_fast), 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_slow), 0), len_slow)
down_slow = ta.rma(-math.min(ta.change(src_slow), 0), len_slow)
rsi_slow = down_slow == 0 ? 100 : up_slow == 0 ? 0 : 100 - (100 / (1 + up_slow / down_slow))
divergence = rsi_fast - rsi_slow
plotdiv = plot(divergence, color = divergence > 0 ? color.lime:color.red, linewidth = 2)
band = hline(0)  // comment out to remove zero line
plot_fast = plot(rsi_fast, color=color.blue)  // plot fast RSI line
plot_slow = plot(rsi_slow, color=color.orange)  // plot slow RSI line
band1 = hline(70,color=color.green)  // uncomment to plot upper band
band0 = hline(30,color=color.red)  // uncomment to plot lower band

divergence15minutes = request.security(syminfo.tickerid, "15", divergence, lookahead=barmerge.lookahead_on)