K`s Extreme Duration
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Sofien-Kaabar

//@version=5
indicator('K`s Extreme Duration', overlay = true)

upper_barrier = input(defval = 65, title = 'Upper Barrier')
lower_barrier = input(defval = 35, title = 'Lower Barrier')
length = input(defval = 8, title = 'Lookback')

rsi = ta.rsi(close, length)

buy  = low  < open[1] and rsi[1]  < 50 and rsi[1] > lower_barrier  and rsi[2] < lower_barrier[2] and rsi[3] < lower_barrier[3] and rsi[4] < lower_barrier[4] and rsi[5] < lower_barrier[5] and rsi[6] < lower_barrier[6]
sell = high > open[1] and rsi[1]  > 50 and rsi[1] < upper_barrier  and rsi[2] > upper_barrier[2] and rsi[3] > upper_barrier[3] and rsi[4] > upper_barrier[4] and rsi[5] > upper_barrier[5] and rsi[6] > upper_barrier[6]

plotshape(buy,  style = shape.triangleup, color = color.green, location =  location.belowbar, size = size.small)
plotshape(sell,  style = shape.triangledown, color = color.red, location =  location.abovebar, size = size.small)
