// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © dep0tyoxxx
//@version=4
study("STARC on RSI",overlay = false) //Volatilty bands, modified for RSI by Constance Brown, formualrs according to
//the book "Technical Analysis for the Trading Professional", 2nd edition, by Constance Brown; slightl modified; see below.
fctup = input (defval=2.3, type=input.float,title="factorUp", step=0.1)
fctdwn = input (defval=2.1, type=input.float,title="factorDown", step=0.1 )
float trRSI = abs(rsi(close,14)-rsi(close[1],14)) // In the original here an atr with 3times rsi,14 is mentioned, instead of high, low and close[-1]
float atrRSI = sma(trRSI,15) //The idea to create high, low and close for RSI with intraday doesnt work,
//because the length of the rsi refers to the new horizon then and differs from Daily RSI.
float Rup = sma(rsi(close,14),6)+(fctup*atrRSI)
float Rdwn = sma(rsi(close,14),6)-(fctdwn*atrRSI)
float Rrsi = rsi(close,14)
float alert = na
float alertup = na
float alertdwn = na
alertup:= crossover(Rrsi,Rup)?Rrsi:na
float countu =0
countu:=alertup>0?0:countu[1]+1
alertdwn:= crossunder(Rrsi,Rdwn)?Rrsi:na
float countd = 0
countd:=alertdwn>0?0:countd[1]+1
plot (Rup,color=color.lime)
plot (Rdwn,color=color.fuchsia)
plot (Rrsi,color=color.aqua)
//plotchar(alertup, location=location.absolute,size=size.tiny,color=color.green)
//plotchar(alertdwn, location=location.absolute,size=size.tiny,color=color.red)
float pivrup=pivothigh(Rup,5,1)
float pivrdwn=pivotlow(Rdwn,5,1)
float revup =na//means reversal from up; new direction:down
float revdwn =na
revup:=Rup[1]==pivrup?Rup[1]:na
revdwn:=Rdwn[1]==pivrdwn?Rdwn[1]:na
//plotchar(revup, location=location.absolute,size=size.tiny,color=color.purple,offset=-1)
float trigru =na
trigru:=revup>0 and countu<15 and (Rrsi*0.98)<Rup?Rup:na
plotshape(trigru, style=shape.triangledown,location=location.absolute,size=size.tiny,color=color.orange,offset=-1)
float trigrdn =na
trigrdn:=revdwn>0 and countd<15 and (Rrsi*0.98)>Rdwn?Rdwn:na
plotshape(trigrdn, style=shape.triangleup,location=location.absolute, size=size.tiny,color=color.green,offset=-1)