Bogdan Ciocoiu - Code runner
// 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 - Code runner", shorttitle="BC - Code runner", format=format.price, precision=2, timeframe="", timeframe_gaps=true, explicit_plot_zorder=true)

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
// Overall
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
_All_line_1 = input(true, "Median", inline="Overall", group="Overall")

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

_All_layer_1 = hline(0, "", color=(_All_line_1) ? _All_line_color : na, linestyle=hline.style_dashed)

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
// TSI
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
_TSI_enable = input(true, "", inline="TSI", group="TSI")

_TSI_col_l = input(color.new(color.green, 50), "", inline="TSI", group="TSI")
_TSI_col_s = input(color.new(color.red, 50), "", inline="TSI", group="TSI")
_TSI_col_l_2 = input(color.new(color.green, 20), "", inline="TSI", group="TSI")
_TSI_col_s_2 = input(color.new(color.red, 20), "", inline="TSI", group="TSI")

_TSI_src = input(close, "", inline="TSI", group="TSI")
_TSI_width = input(0, title="Wid", inline="TSI", group="TSI")

_TSI_long_length = input(6, title="Lon", inline="TSI", group="TSI")
_TSI_short_length = input(13, title="Sho", inline="TSI", group="TSI")
_TSI_signal_length = input(4, title="Sig", inline="TSI", group="TSI")

_TSI_mom = ta.change(_TSI_src)
_TSI_numerator = ta.ema(ta.ema(_TSI_mom, _TSI_long_length), _TSI_short_length)
_TSI_denominator = ta.ema(ta.ema(math.abs(_TSI_mom), _TSI_long_length), _TSI_short_length)
_TSI_tsi = 100 * _TSI_numerator / _TSI_denominator
_TSI_signal = ta.ema(_TSI_tsi, _TSI_signal_length)

_TSI_trend_color = (_TSI_tsi > _TSI_signal) ? _TSI_col_l : _TSI_col_s

_TSI_tsi_plot = plot(_TSI_tsi, color=(_TSI_enable and _TSI_width>0) ? _TSI_trend_color : na, linewidth=_TSI_width)
_TSI_signal_plot = plot(_TSI_signal, color=(_TSI_enable and _TSI_width>0) ? _TSI_trend_color : na, linewidth=_TSI_width)

plot(40, title="TSI OB", color=_TSI_enable ? color.new(color.white, 0) : na, linewidth=1)
plot(-40, title="TSI OS", color=_TSI_enable ? color.new(color.white, 0) : na, linewidth=1)

fill(_TSI_tsi_plot, _TSI_signal_plot, color=(_TSI_enable) ? _TSI_trend_color : na)

plotshape(ta.crossover(_TSI_tsi, _TSI_signal) ? _TSI_tsi : na, location=location.absolute, style=shape.circle, size=size.tiny, color=(_TSI_enable) ? _TSI_col_l_2 : na)
plotshape(ta.crossunder(_TSI_tsi, _TSI_signal) ? _TSI_tsi : na, location=location.absolute, style=shape.circle, size=size.tiny, color=(_TSI_enable) ? _TSI_col_s_2 : na)

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
// Stochastic
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
_Stoch_on = input(true, "", inline="Stoch", group="Stoch")
_Stoch_col_up = input(color.new(color.yellow, 50), "", inline="Stoch", group="Stoch")
_Stoch_col_down = input(color.new(color.blue, 50), "", inline="Stoch", group="Stoch")
_Stoch_col_up_2 = input(color.new(color.yellow, 20), "", inline="Stoch", group="Stoch")
_Stoch_col_down_2 = input(color.new(color.blue, 20), "", inline="Stoch", group="Stoch")

_Stoch_wid = input(0, "Wid", inline="Stoch", group="Stoch")

_Stoch_period_K = input(8, "K per", inline="Stoch", group="Stoch")
_Stoch_smooth_K = input(3, "K smo", inline="Stoch", group="Stoch")
_Stoch_period_D = input(5, "D per", inline="Stoch", group="Stoch")

_Stoch_factor = input(1, title="Fact (scale!)", group="Stoch", inline="Stoch")
_Stoch_factor_2 = input(-50, title="Fact 2 (scale!)", group="Stoch", inline="Stoch")

_Stoch_K = (ta.sma(ta.stoch(close, high, low, _Stoch_period_K), _Stoch_smooth_K))*_Stoch_factor+_Stoch_factor_2
_Stoch_D = (ta.sma(_Stoch_K, _Stoch_period_D))

_Stoch_K_plot = plot(_Stoch_K, title="Stoch K", color=(_Stoch_on and _Stoch_wid > 0) ? (_Stoch_K > _Stoch_D ? _Stoch_col_up : _Stoch_col_down ) : na, linewidth=_Stoch_wid)
_Stoch_D_plot = plot(_Stoch_D, title="Stoch D", color=(_Stoch_on and _Stoch_wid > 0) ? (_Stoch_K > _Stoch_D ? _Stoch_col_up : _Stoch_col_down ) : na, linewidth=_Stoch_wid)

plot(80+_Stoch_factor_2, title="Stoch OB", color=(_Stoch_on) ? color.new(color.white, 0) : na, linewidth=1)
plot(20+_Stoch_factor_2, title="Stoch OS", color=(_Stoch_on) ? color.new(color.white, 0) : na, linewidth=1)

fill(_Stoch_K_plot, _Stoch_D_plot, color=(_Stoch_on) ? (_Stoch_K > _Stoch_D ? _Stoch_col_up : _Stoch_col_down ) : na)

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
// MACD
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
_MACD_enable = input(true, "", inline="MACD", group="MACD histogram")
_MACD_col = input(color.silver, "", inline="MACD", group="MACD histogram")
_MACD_src = input(close, "", inline="MACD", group="MACD histogram")
_MACD_width = input(2, title="Wid", inline="MACD", group="MACD histogram")

_MACD_factor = input(3, "Fact", inline="MACD", group="MACD histogram")

_MACD_fast_len = input(12, "Fast", inline="MACD", group="MACD histogram")
_MACD_slow_len = input(26, "Slow", inline="MACD", group="MACD histogram")
_MACD_sig_len = input(9, "Smo", inline="MACD", group="MACD histogram")
_MACD_sma_src = input.string("EMA", title="Oscillator MA", options=["SMA", "EMA"], inline="MACD", group="MACD histogram")
_MACD_sma_sig = input.string("EMA", title="Signal MA", options=["SMA", "EMA"], inline="MACD", group="MACD histogram")

_MACD_ma_f = _MACD_sma_src == "SMA" ? ta.sma(_MACD_src, _MACD_fast_len) : ta.ema(_MACD_src, _MACD_fast_len)
_MACD_ma_s = _MACD_sma_src == "SMA" ? ta.sma(_MACD_src, _MACD_slow_len) : ta.ema(_MACD_src, _MACD_slow_len)
_MACD_md = _MACD_ma_f - _MACD_ma_s
_MACD_sig = _MACD_sma_sig == "SMA" ? ta.sma(_MACD_md, _MACD_sig_len) : ta.ema(_MACD_md, _MACD_sig_len)
_MACD_his = _MACD_md - _MACD_sig
_MACD_his := _MACD_his * _MACD_factor

plot(_MACD_his, style=plot.style_line, color=(_MACD_enable and _MACD_width>0) ? _MACD_col : na, linewidth=_MACD_width)

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
// AO
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
_AO_enable = input(true, "", inline="AO", group="AO")
_AO_col = input(color.orange, "", inline="AO", group="AO")
_AO_width = input(2, title="Wid", inline="AO", group="AO")

_AO_factor = input(0.8, "Fact", inline="AO", group="AO")

_AO_ao = ta.sma(hl2,5) - ta.sma(hl2,34)
_AO_ao := _AO_ao * _AO_factor

plot(_AO_ao, color=(_AO_enable and _AO_width>0) ? _AO_col : na, style=plot.style_line, linewidth=_AO_width)

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
// CCI
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
_CCI_on = input(true, "", inline="CCI", group="CCI")
_CCI_col = input(color.blue, "", inline="CCI", group="CCI")
_CCI_width = input(2, "Wid", inline="CCI", group="CCI")

_CCI_factor = input(0.4, "Fact (scale!)", inline="CCI", group="CCI")
_CCI_factor_2 = input(-0, "Fact 2 (scale!)", inline="CCI", group="CCI")

_CCI_src = input(hlc3, "", inline="CCI", group="CCI")
_CCI_length = input(20, "Len", inline="CCI", group="CCI")

_CCI_ma = ta.sma(_CCI_src, _CCI_length)
_CCI_cci = (_CCI_src - _CCI_ma) / (0.015 * ta.dev(_CCI_src, _CCI_length))
_CCI_cci := _CCI_cci * _CCI_factor + _CCI_factor_2

plot(100*_CCI_factor + _CCI_factor_2, title="CCI OB", color=(_CCI_on and _CCI_width>0) ? color.new(_CCI_col, 0) : na, linewidth=1)
plot(_CCI_cci, "CCI", color=(_CCI_on and _CCI_width>0) ? _CCI_col : na, linewidth=_CCI_width)
plot(-100*_CCI_factor + _CCI_factor_2, title="CCI OS", color=(_CCI_on and _CCI_width>0) ? color.new(_CCI_col, 0) : na, linewidth=1)

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
// RSI
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
_RSI_on=input(false, "", inline="RSI", group="RSI")
_RSI_col=input(color.fuchsia, "", inline="RSI", group="RSI")
_RSI_len=input(14, "", inline="RSI", group="RSI")

_RSI_src=input(close, "", inline="RSI", group="RSI")
_RSI_width=input(2, "Wid", inline="RSI", group="RSI")

_RSI_factor=input(1, "Fact (scale!)", inline="RSI", group="RSI")
_RSI_factor_2=input(-50, "Fact 2 (scale!)", inline="RSI", group="RSI")

_RSI_1=ta.rsi(_RSI_src, _RSI_len)*_RSI_factor+_RSI_factor_2

plot(70+_RSI_factor_2, title="RSI OB", color=(_RSI_on and _RSI_width>0) ? color.new(_RSI_col, 0) : na, linewidth=1)
plot(_RSI_1, color=(_RSI_on and _RSI_width>0) ? _RSI_col : na, linewidth=_RSI_width)
plot(30+_RSI_factor_2, title="RSI OS", color=(_RSI_on and _RSI_width>0) ? color.new(_RSI_col, 0) : na, linewidth=1)

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
// UO
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
_UO_on = input(true, "", inline="UO", group="UO (7, 14, 28 for NQ or 4, 8, 16 or 10, 20, 40)")
_UO_color = input(color.aqua, "", inline="UO", group="UO (7, 14, 28 for NQ or 4, 8, 16 or 10, 20, 40)")
_UO_width = input(2, "Wid", inline="UO", group="UO (7, 14, 28 for NQ or 4, 8, 16 or 10, 20, 40)")

_UO_factor = input(1, "Fact (scale!)", inline="UO", group="UO (7, 14, 28 for NQ or 4, 8, 16 or 10, 20, 40)")
_UO_factor_2 = input(-50, title="Fact 2 (scale!)", inline="UO", group="UO (7, 14, 28 for NQ or 4, 8, 16 or 10, 20, 40)")

_UO_length_1 = input.int(7, "Len 1", inline="UO", group="UO (7, 14, 28 for NQ or 4, 8, 16 or 10, 20, 40)")
_UO_length_2 = input.int(14, "2", inline="UO", group="UO (7, 14, 28 for NQ or 4, 8, 16 or 10, 20, 40)")
_UO_length_3 = input.int(28, "3", inline="UO", group="UO (7, 14, 28 for NQ or 4, 8, 16 or 10, 20, 40)")

_UO_average(_UO_bp, _UO_tr, _UO_length) => math.sum(_UO_bp, _UO_length) / math.sum(_UO_tr, _UO_length)
_UO_high = math.max(high, close[1])
_UO_low = math.min(low, close[1])
_UO_bp = close - _UO_low
_UO_tr = _UO_high - _UO_low
_UO_avg7 = _UO_average(_UO_bp, _UO_tr, _UO_length_1)
_UO_avg14 = _UO_average(_UO_bp, _UO_tr, _UO_length_2)
_UO_avg28 = _UO_average(_UO_bp, _UO_tr, _UO_length_3)
_UO_out = (100 * (4*_UO_avg7 + 2*_UO_avg14 + _UO_avg28)/7) * _UO_factor + _UO_factor_2

plot(70+_UO_factor_2, title="UO OB", color=(_UO_on and _UO_width>0) ? color.new(_UO_color, 0) : na, linewidth=1)
plot(_UO_out, title="UO", color=(_UO_on and _UO_width>0) ? _UO_color : na, linewidth=_UO_width)
plot(30+_UO_factor_2, title="UO OS", color=(_UO_on and _UO_width>0) ? color.new(_UO_color, 0) : na, linewidth=1)

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
// MFI
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
_MFI_on = input(true, title="", group="MFI", inline="MFI")
_MFI_color = input(color.maroon, title="", group="MFI", inline="MFI")
_MFI_width = input(2, title="Wid", group="MFI", inline="MFI")
_MFI_length = input(14, title="Len", group="MFI", inline="MFI")
_MFI_src = input(hlc3, title="", group="MFI", inline="MFI")

_MFI_factor = input(1, title="Fact (scale!)", group="MFI", inline="MFI")
_MFI_factor_2 = input(-50, title="Fact 2 (scale!)", group="MFI", inline="MFI")

_MFI_mf = ta.mfi(_MFI_src, _MFI_length)*_MFI_factor+_MFI_factor_2

plot(80+_MFI_factor_2, title="MFI OB", color=(_MFI_on) ? color.new(_MFI_color, 0) : na, linewidth=1)
plot(20+_MFI_factor_2, title="MFI OS", color=(_MFI_on) ? color.new(_MFI_color, 0) : na, linewidth=1)

plot(_MFI_mf, color=(_MFI_on and _MFI_width>0) ? _MFI_color : na, linewidth=_MFI_width)
