#rsi1_time_inx_bars
#he changed post1
#and posted #3
#https://usethinkscript.com/threads/rsi-alert-but-only-if-its-the-first-in-20-bars.15872/
#RSI alert, but only if its the first in 20 bars.
#tinfox 7/5 6:17 PM
##1
#Trying to figure out how to add this in a scan.
#Number of months or years 25
#halcyonguy
##2
#tinfox said:
#Trying to figure out how to add this in a scan.
#i think these will do it
declare lower;
def na = double.nan;
def bn = barnumber();
input level = 30;
def r = rsi();
# rsi < x
def len = 20;
def isrlo = r < level;
def rlosum = sum(isrlo, len);
plot zrlo = if isrlo and rlosum == 1 then 1 else 0;;
zrlo.SetDefaultColor(Color.red);
# rsi > x
#def len = 20;
def isrhi = r > (100 - level);
def rhisum = sum(isrhi, len);
plot zrhi = if isrhi and rhisum == 1 then 1 else 0;
zrhi.SetDefaultColor(Color.green);
#tinfox
#3
#I'm trying to weed out redundant alerts. I can't figure out how to get thinkscript to alert if rsi is under 30 or over 70 for the first time in 20 bars.
#---------------------------
input show_rsi = yes;
plot zr = if show_rsi then (rsi()/100) else na;
zr.SetDefaultColor(Color.cyan);
input test1 = no;
addchartbubble(test1, 0,
bn + "\n" +
floor(rsi()) + "\n" +
isrhi + " hi\n" +
rhisum + " sum\n" +
zrhi + "\n"
, (if isrhi then color.yellow else color.gray), yes);
# rsi levels
input show_rsi_levels = yes;
plot z1 = if show_rsi_levels and !isnan(close) then level/100 else na;
plot z2 = if show_rsi_levels and !isnan(close) then (100-level)/100 else na;
z1.SetDefaultColor(Color.light_gray);
z2.SetDefaultColor(Color.light_gray);
#