RTH & ETH MAs [vnhilton]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © vnhilton

//@version=5
indicator("RTH & ETH MAs [vnhilton]", "RTH&ETH MAs", true)

//RTH Timezone
rth = time(timeframe.period, session.regular, syminfo.timezone)

//Parameters
partialBBLinesToggle = input.bool(false, "Enable partial BB Convergence lines?", "If disabled, will show bollinger bands in its entirety. Enabled would show the upper/lower band if candle range is above/below basis line.")
ethToggle            = input.bool(false, "ETH MAs on ETH only?")

ni1  = input.bool(false, "Show on Non-Intraday Timeframes Only?", group = "MA Pair #1")
tf1  = input.timeframe("", "MA Timeframe", group="MA Pair #1")
src1 = input(close, "Source", group="MA Pair #1")
len1 = input.int(5, "MA Length", 1, group="MA Pair #1")
maType1 = input.string("WMA", "MA Type", ["EMA", "HMA", "RMA", "SMA", "SWMA", "VWMA", "WMA"], group="MA Pair #1")

ni2  = input.bool(false, "Show on Non-Intraday Timeframes Only?", group = "MA Pair #2")
tf2  = input.timeframe("", "MA Timeframe", group="MA Pair #2")
src2 = input(close, "Source", group="MA Pair #2")
len2 = input.int(10, "MA Length", 1, group="MA Pair #2")
maType2 = input.string("SMA", "MA Type", ["EMA", "HMA", "RMA", "SMA", "SWMA", "VWMA", "WMA"], group="MA Pair #2")

ni3  = input.bool(false, "Show on Non-Intraday Timeframes Only?", group = "MA Pair #3")
tf3  = input.timeframe("", "MA Timeframe", group="MA Pair #3")
src3 = input(close, "Source", group="MA Pair #3")
len3 = input.int(20, "MA Length", 1, group="MA Pair #3")
maType3 = input.string("SMA", "MA Type", ["EMA", "HMA", "RMA", "SMA", "SWMA", "VWMA", "WMA"], group="MA Pair #3")

ni4  = input.bool(false, "Show on Non-Intraday Timeframes Only?", group = "MA Pair #4")
tf4  = input.timeframe("", "MA Timeframe", group="MA Pair #4")
src4 = input(close, "Source", group="MA Pair #4")
len4 = input.int(50, "MA Length", 1, group="MA Pair #4")
maType4 = input.string("SMA", "MA Type", ["EMA", "HMA", "RMA", "SMA", "SWMA", "VWMA", "WMA"], group="MA Pair #4")

ni5  = input.bool(false, "Show on Non-Intraday Timeframes Only?", group = "MA Pair #5")
tf5  = input.timeframe("", "MA Timeframe", group="MA Pair #5")
src5 = input(close, "Source", group="MA Pair #5")
len5 = input.int(100, "MA Length", 1, group="MA Pair #5")
maType5 = input.string("SMA", "MA Type", ["EMA", "HMA", "RMA", "SMA", "SWMA", "VWMA", "WMA"], group="MA Pair #5")

ni6  = input.bool(false, "Show on Non-Intraday Timeframes Only?", group = "MA Pair #6")
tf6  = input.timeframe("", "MA Timeframe", group="MA Pair #6")
src6 = input(close, "Source", group="MA Pair #6")
len6 = input.int(200, "MA Length", 1, group="MA Pair #6")
maType6 = input.string("SMA", "MA Type", ["EMA", "HMA", "RMA", "SMA", "SWMA", "VWMA", "WMA"], group="MA Pair #6")

mult1 = input.float(2, "Converging MA #1 STDDEV", 0, tooltip="For bollinger bands of converging MA", group="BB Parameters")
mult2 = input.float(2, "Converging MA #2 STDDEV", 0, group="BB Parameters")
mult3 = input.float(2, "Converging MA #3 STDDEV", 0, group="BB Parameters")
mult4 = input.float(2, "Converging MA #4 STDDEV", 0, group="BB Parameters")
mult5 = input.float(2, "Converging MA #5 STDDEV", 0, group="BB Parameters")
mult6 = input.float(2, "Converging MA #6 STDDEV", 0, group="BB Parameters")

//Moving Average (MA) Selection
ma(src, len, type) =>
    switch type
        "EMA" => ta.ema(src, len)
        "HMA" => ta.hma(src, len)
        "RMA" => ta.rma(src, len)
        "SMA" => ta.sma(src, len)
        "VWMA" => ta.vwma(src, len)
        "WMA" => ta.wma(src, len)

//MA & BB Assignments
ma1 = ma(src1, len1, maType1)
[bb1M, bb1U, bb1L] = ta.bb(src1, len1, mult1)
ma2 = ma(src2, len2, maType2)
[bb2M, bb2U, bb2L] = ta.bb(src2, len2, mult2)
ma3 = ma(src3, len3, maType3)
[bb3M, bb3U, bb3L] = ta.bb(src3, len3, mult3)
ma4 = ma(src4, len4, maType4)
[bb4M, bb4U, bb4L] = ta.bb(src4, len4, mult4)
ma5 = ma(src5, len5, maType5)
[bb5M, bb5U, bb5L] = ta.bb(src5, len5, mult5)
ma6 = ma(src6, len6, maType6)
[bb6M, bb6U, bb6L] = ta.bb(src6, len6, mult6)

//RTH & ETH MAs
rthMA1 = request.security(ticker.modify(syminfo.tickerid, session.regular), tf1, ma1, barmerge.gaps_on)
ethMA1 = request.security(ticker.modify(syminfo.tickerid, session.extended), tf1, ma1, barmerge.gaps_on)

rthMA2 = request.security(ticker.modify(syminfo.tickerid, session.regular), tf2, ma2, barmerge.gaps_on)
ethMA2 = request.security(ticker.modify(syminfo.tickerid, session.extended), tf2, ma2, barmerge.gaps_on)

rthMA3 = request.security(ticker.modify(syminfo.tickerid, session.regular), tf3, ma3, barmerge.gaps_on)
ethMA3 = request.security(ticker.modify(syminfo.tickerid, session.extended), tf3, ma3, barmerge.gaps_on)

rthMA4 = request.security(ticker.modify(syminfo.tickerid, session.regular), tf4, ma4, barmerge.gaps_on)
ethMA4 = request.security(ticker.modify(syminfo.tickerid, session.extended), tf4, ma4, barmerge.gaps_on)

rthMA5 = request.security(ticker.modify(syminfo.tickerid, session.regular), tf5, ma5, barmerge.gaps_on)
ethMA5 = request.security(ticker.modify(syminfo.tickerid, session.extended), tf5, ma5, barmerge.gaps_on)

rthMA6 = request.security(ticker.modify(syminfo.tickerid, session.regular), tf6, ma6, barmerge.gaps_on)
ethMA6 = request.security(ticker.modify(syminfo.tickerid, session.extended), tf6, ma6, barmerge.gaps_on)

//Plots
rthPlot1 = plot(ni1 ? timeframe.isdwm ? rthMA1 : na : rth ? rthMA1 : na, "RTH MA #1", color=rthMA1 >= rthMA1[1] ? color.new(#002652, 52) : color.new(#002652, 51), style=plot.style_linebr, display=display.none)
ethPlot1 = plot(ni1 ? timeframe.isdwm ? ethMA1 : na : ethToggle ? rth ? na : ethMA1 : ethMA1, "ETH MA #1", ethMA1 >= ethMA1[1] ? color.new(#002652, 52) : color.new(#002652, 51), style=plot.style_linebr)
convPlot1 = plot(rth and rthMA1 == ethMA1 ? rthMA1 : na, "Convergence MA #1", color=color.new(#002652, 52), display=display.none)
convBandU1 = plot(rth and rthMA1 == ethMA1 ? not partialBBLinesToggle ? bb1U : high >= rthMA1 ? bb1U : na : na, "Convergence Upper BB #1", color.new(#002652, 75), style=plot.style_linebr, display=display.none)
convBandL1 = plot(rth and rthMA1 == ethMA1 ? not partialBBLinesToggle ? bb1L : low < rthMA1 ? bb1L : na : na, "Convergence Lower BB #1", color.new(#002652, 75), style=plot.style_linebr, display=display.none)

rthPlot2 = plot(ni2 ? timeframe.isdwm ? rthMA2 : na : rth ? rthMA2 : na, "RTH MA #2", color=rthMA2 >= rthMA2[1] ? color.new(#FFFF00, 0) : color.new(#FFFF00, 1), style=plot.style_linebr, display=display.none)
ethPlot2 = plot(ni2 ? timeframe.isdwm ? ethMA2 : na : ethToggle ? rth ? na : ethMA2 : ethMA2, "ETH MA #2", ethMA2 >= ethMA2[1] ? color.new(#FFFF00, 0) : color.new(#FFFF00, 1), style=plot.style_linebr)
convPlot2 = plot(rth and rthMA2 == ethMA2 ? rthMA2 : na, "Convergence MA #2", color=color.new(#FFFF00, 0), style=plot.style_linebr, display=display.none)
convBandU2 = plot(rth and rthMA2 == ethMA2 ? not partialBBLinesToggle ? bb2U : high >= rthMA2 ? bb2U : na : na, "Convergence Upper BB #2", color.new(#FFFF00, 75), style=plot.style_linebr, display=display.none)
convBandL2 = plot(rth and rthMA2 == ethMA2 ? not partialBBLinesToggle ? bb2L : low < rthMA2 ? bb2L : na : na, "Convergence Lower BB #2", color.new(#FFFF00, 75), style=plot.style_linebr, display=display.none)

rthPlot3 = plot(ni3 ? timeframe.isdwm ? rthMA3 : na : rth ? rthMA3 : na, "RTH MA #3", color=rthMA3 >= rthMA3[1] ? color.new(#00ff00, 0) : color.new(#00ff00, 1), style=plot.style_linebr, display=display.none)
ethPlot3 = plot(ni3 ? timeframe.isdwm ? ethMA3 : na : ethToggle ? rth ? na : ethMA3 : ethMA3, "ETH MA #3", ethMA3 >= ethMA3[1] ? color.new(#00ff00, 0) : color.new(#00ff00, 1), style=plot.style_linebr)
convPlot3 = plot(rth and rthMA3 == ethMA3 ? rthMA3 : na, "Convergence MA #3", color=color.new(#00ff00, 0), style=plot.style_linebr, display=display.none)
convBandU3 = plot(rth and rthMA3 == ethMA3 ? not partialBBLinesToggle ? bb3U : high >= rthMA3 ? bb3U : na : na, "Convergence Upper BB #3", color.new(#00ff00, 75), style=plot.style_linebr, display=display.none)
convBandL3 = plot(rth and rthMA3 == ethMA3 ? not partialBBLinesToggle ? bb3L : low < rthMA3 ? bb3L : na : na, "Convergence Lower BB #3", color.new(#00ff00, 75), style=plot.style_linebr, display=display.none)

rthPlot4 = plot(ni4 ? timeframe.isdwm ? rthMA4 : na : rth ? rthMA4 : na, "RTH MA #4", color=rthMA4 >= rthMA4[1] ? color.new(#3029ff, 0) : color.new(#3029ff, 1), style=plot.style_linebr, display=display.none)
ethPlot4 = plot(ni4 ? timeframe.isdwm ? ethMA4 : na : ethToggle ? rth ? na : ethMA4 : ethMA4, "ETH MA #4", ethMA4 >= ethMA4[1] ? color.new(#3029ff, 0) : color.new(#3029ff, 1), style=plot.style_linebr)
convPlot4 = plot(rth and rthMA4 == ethMA4 ? rthMA4 : na, "Convergence MA #4", color=color.new(#3029ff, 0), style=plot.style_linebr, display=display.none)
convBandU4 = plot(rth and rthMA4 == ethMA4 ? not partialBBLinesToggle ? bb4U : high >= rthMA4 ? bb4U : na : na, "Convergence Upper BB #4", color.new(#3029ff, 75), style=plot.style_linebr, display=display.none)
convBandL4 = plot(rth and rthMA4 == ethMA4 ? not partialBBLinesToggle ? bb4L : low < rthMA4 ? bb4L : na : na, "Convergence Lower BB #4", color.new(#3029ff, 75), style=plot.style_linebr, display=display.none)

rthPlot5 = plot(ni5 ? timeframe.isdwm ? rthMA5 : na : rth ? rthMA5 : na, "RTH MA #5", color=rthMA5 >= rthMA5[1] ? color.new(#8229ff, 0) : color.new(#8229ff, 1), style=plot.style_linebr, display=display.none)
ethPlot5 = plot(ni5 ? timeframe.isdwm ? ethMA5 : na : ethToggle ? rth ? na : ethMA5 : ethMA5, "ETH MA #5", ethMA5 >= ethMA5[1] ? color.new(#8229ff, 0) : color.new(#8229ff, 1), style=plot.style_linebr)
convPlot5 = plot(rth and rthMA5 == ethMA5 ? rthMA5 : na, "Convergence MA #5", color=color.new(#8229ff, 0), style=plot.style_linebr, display=display.none)
convBandU5 = plot(rth and rthMA5 == ethMA5 ? not partialBBLinesToggle ? bb5U : high >= rthMA5 ? bb5U : na : na, "Convergence Upper BB #5", color.new(#8229ff, 75), style=plot.style_linebr, display=display.none)
convBandL5 = plot(rth and rthMA5 == ethMA5 ? not partialBBLinesToggle ? bb5L : low < rthMA5 ? bb5L : na : na, "Convergence Lower BB #5", color.new(#8229ff, 75), style=plot.style_linebr, display=display.none)

rthPlot6 = plot(ni6 ? timeframe.isdwm ? rthMA6 : na : rth ? rthMA6 : na, "RTH MA #6", color=rthMA6 >= rthMA6[1] ? color.new(#ff00e8, 0) : color.new(#ff00e8, 1), style=plot.style_linebr, display=display.none)
ethPlot6 = plot(ni6 ? timeframe.isdwm ? ethMA6 : na : ethToggle ? rth ? na : ethMA6 : ethMA6, "ETH MA #6", ethMA6 >= ethMA6[1] ? color.new(#ff00e8, 0) : color.new(#ff00e8, 1), style=plot.style_linebr)
convPlot6 = plot(rth and rthMA6 == ethMA6 ? rthMA6 : na, "Convergence MA #6", color=color.new(#ff00e8, 0), style=plot.style_linebr, display=display.none)
convBandU6 = plot(rth and rthMA6 == ethMA6 ? not partialBBLinesToggle ? bb6U : high >= rthMA6 ? bb6U : na : na, "Convergence Upper BB #6", color.new(#ff00e8, 75), style=plot.style_linebr, display=display.none)
convBandL6 = plot(rth and rthMA6 == ethMA6 ? not partialBBLinesToggle ? bb6L: low < rthMA6 ? bb6L : na : na, "Convergence Lower BB #6", color.new(#ff00e8, 75), style=plot.style_linebr, display=display.none)