Bogdan Ciocoiu - Coordinator
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © BogdanCiocoiu

//@version=5
indicator("Bogdan Ciocoiu - Coordinator", shorttitle="BC - Coordinator", format=format.price, precision=2, timeframe="", timeframe_gaps=true, explicit_plot_zorder=true)

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
// Overall
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
_All_line_color = input(color.new(color.white, 70), "", inline="Overall", group="Overall")

_All_line_0 = input(80, "Separator 1", inline="Overall", group="Overall")
_All_line_1 = input(50, "2", inline="Overall", group="Overall")
_All_line_2 = input(20, "3", inline="Overall", group="Overall")

_All_layer_0 = hline(_All_line_0, "", color=(_All_line_0>0) ? _All_line_color : na, linestyle=hline.style_dashed)
_All_layer_1 = hline(_All_line_1, "", color=(_All_line_1>0) ? _All_line_color : na, linestyle=hline.style_dashed)
_All_layer_2 = hline(_All_line_2, "", color=(_All_line_2>0) ? _All_line_color : na, linestyle=hline.style_dashed)

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
// RSI Clouds
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------

_RC1_enabled = input(true, "", inline="Slow RSI suite", group="Slow RSI suite")

_RC2_enabled = input(true, "", inline="Fast RSI suite", group="Fast RSI suite")

_RC1_col_1 = input(color.gray, "", inline="Slow RSI suite", group="Slow RSI suite")
_RC1_col_2 = input(color.gray, "", inline="Slow RSI suite", group="Slow RSI suite")
_RC1_col_3 = input(color.gray, "", inline="Slow RSI suite", group="Slow RSI suite")

_RC2_col_1 = input(color.green, "", inline="Fast RSI suite", group="Fast RSI suite")
_RC2_col_2 = input(color.red, "", inline="Fast RSI suite", group="Fast RSI suite")
_RC2_col_3 = input(color.yellow, "", inline="Fast RSI suite", group="Fast RSI suite")

_RC1_col_f = input(30, "Col full", inline="Slow RSI suite", group="Slow RSI suite")
_RC1_col_p = input(30, "Part", inline="Slow RSI suite", group="Slow RSI suite")

_RC2_col_f = input(0, "Col full", inline="Fast RSI suite", group="Fast RSI suite")
_RC2_col_p = input(0, "Part", inline="Fast RSI suite", group="Fast RSI suite")

_RC1_input_1 = input(60, "Fast", inline="Slow RSI suite", group="Slow RSI suite")
_RC1_input_2 = input(10, "Slow", inline="Slow RSI suite", group="Slow RSI suite") //var.: 8
_RC1_input_3 = input(60, "Imp", inline="Slow RSI suite", group="Slow RSI suite")

_RC2_input_1 = input(6, "Fast", inline="Fast RSI suite", group="Fast RSI suite")
_RC2_input_2 = input(4, "Slow", inline="Fast RSI suite", group="Fast RSI suite")
_RC2_input_3 = input(10, "Imp", inline="Fast RSI suite", group="Fast RSI suite")

_RC1_ma_enable = input(true, "", inline="Slow RSI MA", group="Slow RSI MA")
_RC1_ma_col = input(color.white, "Col", inline="Slow RSI MA", group="Slow RSI MA")
_RC1_ma_type = input.string("SMA", title="", options=["SMA", "EMA", "WMA", "VWMA", "SMMA"], inline="Slow RSI MA", group="Slow RSI MA")
_RC1_ma_len = input(30, "Len", inline="Slow RSI MA", group="Slow RSI MA")
_RC1_ma_width = input(2, "Wid", inline="Slow RSI MA", group="Slow RSI MA")

_RC2_ma_enable = input(true, "", inline="Fast RSI MA", group="Fast RSI MA")
_RC2_ma_col = input(color.yellow, "Col", inline="Fast RSI MA", group="Fast RSI MA")
_RC2_ma_type = input.string("SMA", title="", options=["SMA", "EMA", "WMA", "VWMA", "SMMA"], inline="Fast RSI MA", group="Fast RSI MA")
_RC2_ma_len = input(30, "Len", inline="Fast RSI MA", group="Fast RSI MA")
_RC2_ma_width = input(2, "Wid", inline="Fast RSI MA", group="Fast RSI MA")

_RC1_rsi_1 = ta.rsi(close, _RC1_input_1)
_RC1_rsi_2 = ta.rsi(close, _RC1_input_2)
_RC1_rsi_3 = ta.rsi(close, _RC1_input_3)

_RC2_rsi_1 = ta.rsi(close, _RC2_input_1)
_RC2_rsi_2 = ta.rsi(close, _RC2_input_2)
_RC2_rsi_3 = ta.rsi(close, _RC2_input_3)

_RC1_burst_down = (_RC1_rsi_3 > _RC1_rsi_1) and (_RC1_rsi_3 > _RC1_rsi_2)
_RC1_burst_up = (_RC1_rsi_3 < _RC1_rsi_1) and (_RC1_rsi_3 < _RC1_rsi_2)

_RC2_burst_down = (_RC2_rsi_3 > _RC2_rsi_1) and (_RC2_rsi_3 > _RC2_rsi_2)
_RC2_burst_up = (_RC2_rsi_3 < _RC2_rsi_1) and (_RC2_rsi_3 < _RC2_rsi_2)

_RC1_col_fin_1 = _RC1_burst_up ? color.new(_RC1_col_1, _RC1_col_f) : _RC1_burst_down ? color.new(_RC1_col_2, _RC1_col_f) : color.new(_RC1_col_3, _RC1_col_f)
_RC1_col_fin_2 = _RC1_rsi_2 > _RC1_rsi_1 ? color.new(_RC1_col_1, _RC1_col_p) : _RC1_rsi_2 < _RC1_rsi_1 ? color.new(_RC1_col_2, _RC1_col_p) : na

_RC2_col_fin_1 = _RC2_burst_up ? color.new(_RC2_col_1, _RC2_col_f) : _RC2_burst_down ? color.new(_RC2_col_2, _RC2_col_f) : color.new(_RC2_col_3, _RC2_col_f)
_RC2_col_fin_2 = _RC2_rsi_2 > _RC2_rsi_1 ? color.new(_RC2_col_1, _RC2_col_p) : _RC2_rsi_2 < _RC2_rsi_1 ? color.new(_RC2_col_2, _RC2_col_p) : na

_RC1_plot_1 = plot(_RC1_rsi_1, title="Fast", color=na)
_RC1_plot_2 = plot(_RC1_rsi_2, title="Slow", color=na)
_RC1_plot_3 = plot(_RC1_rsi_3, title="Impulse", color=na)

_RC2_plot_1 = plot(_RC2_rsi_1, title="Fast", color=na)
_RC2_plot_2 = plot(_RC2_rsi_2, title="Slow", color=na)
_RC2_plot_3 = plot(_RC2_rsi_3, title="Impulse", color=na)

fill(_RC1_plot_1, _RC1_plot_2, color=(_RC1_enabled) ? _RC1_col_fin_2 : na, fillgaps=false)
fill(_RC1_plot_1, _RC1_plot_3, color=(_RC1_enabled) ? _RC1_col_fin_1 : na, fillgaps=false)

fill(_RC2_plot_1, _RC2_plot_2, color=(_RC2_enabled) ? _RC2_col_fin_2 : na, fillgaps=false)
fill(_RC2_plot_1, _RC2_plot_3, color=(_RC2_enabled) ? _RC2_col_fin_1 : na, fillgaps=false)

_ma(_src, _len, _type) =>
    switch _type
        "SMA" => ta.sma(_src, _len)
        "EMA" => ta.ema(_src, _len)
        "WMA" => ta.wma(_src, _len)
        "VWMA" => ta.vwma(_src, _len)
        "SMMA" =>
            _ma = ta.sma ( _src, _len )
            _ma_final = 0.0
            _ma_final := na ( _ma_final[1] ) ? _ma : ( _ma_final[1] * ( _len - 1 ) + _src ) / _len

_RC1_ma = _ma(_RC1_rsi_3, _RC1_ma_len, _RC1_ma_type)
_RC2_ma = _ma(_RC2_rsi_3, _RC2_ma_len, _RC2_ma_type)

plot(_RC1_ma, color=(_RC1_ma_enable and _RC1_ma_width>0) ? _RC1_ma_col : na, linewidth=_RC1_ma_width)
plot(_RC2_ma, color=(_RC2_ma_enable and _RC2_ma_width>0) ? _RC2_ma_col : na, linewidth=_RC2_ma_width)

plotshape(ta.crossover(math.min(_RC1_rsi_1, _RC1_rsi_2, _RC1_rsi_3), _RC1_ma) ? _RC1_rsi_3 : na, location=location.top, style=shape.circle, size=size.small, color=(_RC1_ma_enable) ? _RC1_ma_col : na)
plotshape(ta.crossunder(math.max(_RC1_rsi_1, _RC1_rsi_2, _RC1_rsi_3), _RC1_ma) ? _RC1_rsi_3 : na, location=location.bottom, style=shape.circle, size=size.small, color=(_RC1_ma_enable) ? _RC1_ma_col : na)

plotshape(ta.crossover(math.min(_RC2_rsi_1, _RC2_rsi_2, _RC2_rsi_3), _RC2_ma) ? _RC2_rsi_3 : na, location=location.top, style=shape.triangleup, size=size.tiny, color=(_RC2_ma_enable) ? _RC2_col_1 : na)
plotshape(ta.crossunder(math.max(_RC2_rsi_1, _RC2_rsi_2, _RC2_rsi_3), _RC2_ma) ? _RC2_rsi_3 : na, location=location.bottom, style=shape.triangledown, size=size.tiny, color=(_RC2_ma_enable) ? _RC2_col_2 : na)
