RSI + FIB HH LL StopLoss Finder／Contrarian Trades
// 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 Higher Highs, Lower Lows StopLoss Finder / Contrarian Trade",shorttitle = "RSI,FHH,LL SLF/CT", overlay = true)
//Fibonacci Number is 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, ...
//FIbonacci Ratio is 0.236, 0.382, 0.5, 0.618, 1, 1.618, 2.618, 4.236, ...

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,color = color.new(#FC0400, 0), linewidth = 2)
p2 = plot(highest_ema2,color = color.new(#0022FC, 0), linewidth = 2)

p3 = plot(lowest_ema,color =color.new(#FC0400, 0), linewidth = 2)
p4 = plot(lowest_ema2,color =color.new(#0022FC, 0), linewidth = 2)

hh_color = highest_ema[1] < highest_ema2 ? #80000B :#00E60F 
ll_color = lowest_ema[1] > lowest_ema2 ?  #00E60F : #80000B

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

cc =  rsi > ob ? color.red :  rsi < os ? color.lime : color.silver

barcolor(color = cc)