K's Reversal Indicator I
// 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 Reversal Indicator I", overlay = true)

fast       = input(defval = 12, title = 'Fast')
slow       = input(defval = 26, title = 'Slow')
signal     = input(defval = 9,  title = 'Signal')
length     = input(defval = 100, title = 'Bollinger Lookback')
multiplier = input(defval = 2,  title = 'Multiplier')

// MACD
macd_line   = ta.ema(close, fast) - ta.ema(close, slow)
signal_line = ta.ema(macd_line, signal)

// Bollinger
lower_boll = ta.sma(close, length) - (multiplier * ta.stdev(close, length))
upper_boll = ta.sma(close, length) + (multiplier * ta.stdev(close, length))
mid_line = ta.sma(close, length)

// Signal
buy_signal  = math.min(open[1], close[1]) <= lower_boll[1] and math.max(open[1], close[1]) <= mid_line and macd_line[1] > signal_line[1] and macd_line[2] < signal_line[2]
sell_signal = math.max(open[1], close[1]) >= upper_boll[1] and math.min(open[1], close[1]) >= mid_line and macd_line[1] < signal_line[1] and macd_line[2] > signal_line[2]

// Plotting
plotshape(buy_signal,  style = shape.triangleup, color = color.green, location =  location.belowbar, size = size.small)
plotshape(sell_signal,  style = shape.triangledown, color = color.red, location =  location.abovebar, size = size.small)

bar_size = timeframe.multiplier * (timeframe.isdaily?1440:timeframe.isweekly?7*1440:timeframe.ismonthly?30*1440:1) * 60*1000

if buy_signal == true

    line.new(time, low[1] - (high[1] - low[1]) * 2, time + bar_size * 20, low[1] - (high[1] - low[1]) * 2, xloc.bar_time, color = color.green, width = 2)
    line.new(time, open, time + bar_size * 20, open, xloc.bar_time, color = color.blue, width = 2)

if sell_signal == true

    line.new(time, high[1] + (high[1] - low[1]) * 2, time + bar_size * 20, high[1] + (high[1] - low[1]) * 2, xloc.bar_time, color = color.red, width = 2)
    line.new(time, open, time + bar_size * 20, open, xloc.bar_time, color = color.blue, width = 2)

