RSI + Fibonacci HH LL Support Resistance 
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © hayashipallu

//@version=5
indicator("RSI + Fibonacci HH LL Support Resistance ",shorttitle = "RSI+FIB HH,LL,SR", overlay = true)
//Fibonacci Number is 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 620, 987, 1597, ...
//FIbonacci Ratio is 0.236, 0.382, 0.5, 0.618, 1, 1.618, 2.618, 4.236, ...
src1 = high
src2 = low 
length = input(55)


ama1 = 0.
ama2 = 0.
hh = math.max(math.sign(ta.change(ta.highest(length))), 0)
ll = math.max(math.sign(ta.change(ta.lowest(length))  *  -1), 0)
tc = math.pow(ta.sma(hh or ll ? 1 : 0, length), 2)
ama1 := nz(ama1[1] + tc  *  (high - ama1[1]), high)
ama2 := nz(ama2[1] + tc  *  (low - ama2[1]), low)

//Midline
mah = ama1
mal = ama2

m = (mah + mal)/2

//Half Mean Range
dist = (mah - mal)/2

//Levels
h6 = m + dist * 11.089
h5 = m + dist * 6.857
h4 = m + dist * 4.235
h3 = m + dist * 2.618
h2 = m + dist * 1.618
h1 = m + dist * 0.618
l1 = m - dist * 0.618
l2 = m - dist * 1.618
l3 = m - dist * 2.618
l4 = m - dist * 4.235
l5 = m - dist * 6.857
l6 = m - dist * 11.089

plot(m, linewidth = 3, color = m > m[5] ? color.lime : color.red)

ph6 = plot(h6, color = color.new(color.lime,40))
ph5 = plot(h5, color = color.new(color.lime,50))
ph4 = plot(h4, color = color.new(color.lime,60))
ph3 = plot(h3, color = color.new(color.lime,70))
ph2 = plot(h2, color = color.new(color.lime,80))
ph1 = plot(h1, color = color.new(color.lime,90))
pl6 = plot(l6, color = color.new(color.red,90))
pl5 = plot(l5, color = color.new(color.red,80))
pl4 = plot(l4, color = color.new(color.red,70))
pl3 = plot(l3, color = color.new(color.red,60))
pl2 = plot(l2, color = color.new(color.red,50))
pl1 = plot(l1, color = color.new(color.red,40))

fill(ph6, ph5, color = color.new(color.lime, 87),  editable = true)
fill(pl6, pl5, color = color.new(color.red, 87),  editable = true)
fill(ph5, ph4, color = color.new(color.lime, 90),  editable = true)
fill(pl5, pl4, color = color.new(color.red, 90),  editable = true)
fill(ph4, ph3, color = color.new(color.lime, 93),  editable = true)
fill(pl4, pl3, color = color.new(color.red, 93),  editable = true)
fill(ph3, ph2, color = color.new(color.lime, 96),  editable = true)
fill(pl3, pl2, color = color.new(color.red, 96),  editable = true)
fill(ph2, ph1, color = color.new(color.lime, 99),  editable = true)
fill(pl2, pl1, color = color.new(color.red, 99),  editable = true)


lookback_bars = input(defval = 144)
lookback_bars2 = input(defval = 144)

ema_len1 = input(defval = 2)
ema_len2 = input(defval = 2)

slide = input(defval = 13)

highest_ema = ta.ema(ta.highest(high, lookback_bars), ema_len1)
highest_ema2 = ta.ema(ta.highest(high, lookback_bars2), ema_len2)[slide]

lowest_ema = ta.ema(ta.lowest(low, lookback_bars), ema_len1)
lowest_ema2 = ta.ema(ta.lowest(low, lookback_bars2), ema_len2)[slide]

len = input(defval = 5)
ema = ta.ema(close, len)

rsi_len = input(defval = 13)
rsi = ta.rsi(ema, rsi_len)

ob = input(70)
os = input(40)

p1 = plot(highest_ema,title = "Highest High", color =color.new(color.red, 80), linewidth = 2)
p2 = plot(highest_ema2,title = "Delay Highest High", color =color.new(color.red, 80), linewidth = 2)

p3 = plot(lowest_ema, title = "Lowest Low", color =color.new(color.lime , 80), linewidth = 2)
p4 = plot(lowest_ema2, title = "Delay Lowest Low", color =color.new(color.lime, 80), linewidth = 2)

hh_color = highest_ema[1] < highest_ema2 ? color.red:color.red
ll_color = lowest_ema[1] > lowest_ema2 ?  color.lime : color.lime

fill(p1, p2, color = color.new(hh_color, 80), editable = true)
fill(p3, p4, color = color.new(ll_color, 80), editable = true)

cc =  rsi > ob and close > h3 ? color.new(color.red,60) :  rsi > ob and close > h4 ? color.new(color.red,40) : rsi > ob and close > h5 ? color.new(color.red,20) : rsi > ob and close > h6 ? color.new(color.red,0) : rsi < os and close < h3 ? color.new(color.lime,60) : rsi < os and close < l4 ? color.new(color.lime,40) : rsi < os and close < l5 ? color.new(color.lime,20) : rsi < os and close < l6 ? color.new(color.lime,0) : color.gray

barcolor(color = cc, title = "RSI Bar Over Bought/Sold Color")

crsi = rsi > ob and close < h6 ? color.red : rsi < os and close < h6 ? color.lime : color.new(color.gray,90)

plotshape(rsi, color = crsi, style = shape.square, size = size.tiny, location =  location.bottom)