Moving Averages + BB & R.VWAP StDev (multi-tf)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=5

indicator("MA • Yata", 
     overlay = true)

// ------------------------------------------------
groupRV = "Rolling VWAP & Standard Deviation Bands"
// ------------------------------------------------

show_rVWAP		= input(false, title="VWAP:"			, inline="RV1", group=groupRV)
showSTDEV		= input(false, title="St. Dev. Bands |"	, inline="RV2", group=groupRV)

rolling_period	= input(200, title=""	, inline="RV1", group=groupRV)
src_rVWAP		= input(hlc3, title=""	, inline="RV1", group=groupRV)

fillSTDEV		= input(true			, title="Fill |", inline="RV2", group=groupRV)
showrL			= input(false			, title="Lines:", inline="RV2", group=groupRV)
Lwidth_rVWAP	= input.int(1, minval=0	, title="Width"	, inline="RV2", group=groupRV)

showrLC			= showrL ? display.all : display.none

stDevMultiplier_1 = input.float(0.5		, step=0.1, title="Deviation 1", inline="StDev1", group=groupRV)
stDevMultiplier_2 = input.float(0.618	, step=0.1, title="Deviation 2", inline="StDev1", group=groupRV)
stDevMultiplier_3 = input.float(1		, step=0.1, title="Deviation 3", inline="StDev2", group=groupRV)
stDevMultiplier_4 = input.float(1.5		, step=0.1, title="Deviation 4", inline="StDev2", group=groupRV)
stDevMultiplier_5 = input.float(1.618	, step=0.1, title="Deviation 5", inline="StDev3", group=groupRV)
stDevMultiplier_6 = input.float(2		, step=0.1, title="Deviation 6", inline="StDev3", group=groupRV)

rVWAP_color		= input.color(color.new(color.silver, 70)	, title="Colors: VWAP"	, inline="RV3", group=groupRV)
up_color		= input.color(color.red						, title="Upper"			, inline="RV3", group=groupRV)
lw_color		= input.color(color.blue					, title="Lower"			, inline="RV3", group=groupRV)

Vstyle = input(true, title="Circles line", inline="RV3", group=groupRV)
VstyleC = Vstyle ? plot.style_circles : plot.style_line

// ------------------------------------------------

rVWAP(length) =>
    float p = na
    float vol = na
    float sn = na
    p_ = src_rVWAP * volume
    p := nz(p[1]) + p_ - nz(p_[length])
    vol := nz(vol[1]) + volume - nz(volume[length])
    v = p / vol
    sn_ = volume * (src_rVWAP - nz(v[1])) * (src_rVWAP - v)
    sn := nz(sn[1]) + sn_ - nz(sn_[length])
    std = math.sqrt(sn / vol)
    [v, std]

[vwap_r, std_r] = rVWAP(rolling_period)

// ------------------------------------------------

resrVWAP = input.timeframe("", title="", inline="RV1", group=groupRV)

mtfrVWAP = request.security(syminfo.tickerid, resrVWAP, vwap_r, gaps=barmerge.gaps_off)
mtfSTD	 = request.security(syminfo.tickerid, resrVWAP, std_r, gaps=barmerge.gaps_off)

plot(show_rVWAP ? mtfrVWAP : na, title = "VWAP - Rolling", color=rVWAP_color, linewidth=Lwidth_rVWAP, style=VstyleC)

// ------------------------------------------------

fb_transp = input.float(100, minval=0, maxval=100, title="Transparency", inline="RV4", group=groupRV)
fb_step = input.float(5, minval=0, maxval=100, title="Step", inline="RV4", group=groupRV)

fill_col_up5	= color.new(up_color, fb_transp - fb_step * 5)
fill_col_up4	= color.new(up_color, fb_transp - fb_step * 4)
fill_col_up3	= color.new(up_color, fb_transp - fb_step * 3)
fill_col_up2	= color.new(up_color, fb_transp - fb_step * 2)
fill_col_up		= color.new(up_color, fb_transp - fb_step * 1)

//fill_col_mid	= color.new(color.silver, fb_transp)

fill_col_down	= color.new(lw_color, fb_transp - fb_step * 1)
fill_col_down2	= color.new(lw_color, fb_transp - fb_step * 2)
fill_col_down3	= color.new(lw_color, fb_transp - fb_step * 3)
fill_col_down4	= color.new(lw_color, fb_transp - fb_step * 4)
fill_col_down5	= color.new(lw_color, fb_transp - fb_step * 5)

// ------------------------------------------------

rV_stdevU1 = plot(showSTDEV ? mtfrVWAP + stDevMultiplier_1 * mtfSTD : na, title="rVWAP - STDEV +1", color=color.new(color.silver, 85), style=plot.style_line, linewidth=Lwidth_rVWAP, display=showrLC)
rV_stdevU2 = plot(showSTDEV ? mtfrVWAP + stDevMultiplier_2 * mtfSTD : na, title="rVWAP - STDEV +2", color=color.new(color.silver, 85), style=plot.style_line, linewidth=Lwidth_rVWAP, display=showrLC)
rV_stdevU3 = plot(showSTDEV ? mtfrVWAP + stDevMultiplier_3 * mtfSTD : na, title="rVWAP - STDEV +3", color=color.new(color.silver, 85), style=plot.style_line, linewidth=Lwidth_rVWAP, display=showrLC)
rV_stdevU4 = plot(showSTDEV ? mtfrVWAP + stDevMultiplier_4 * mtfSTD : na, title="rVWAP - STDEV +4", color=color.new(color.silver, 85), style=plot.style_line, linewidth=Lwidth_rVWAP, display=showrLC)
rV_stdevU5 = plot(showSTDEV ? mtfrVWAP + stDevMultiplier_5 * mtfSTD : na, title="rVWAP - STDEV +5", color=color.new(color.silver, 85), style=plot.style_line, linewidth=Lwidth_rVWAP, display=showrLC)
rV_stdevU6 = plot(showSTDEV ? mtfrVWAP + stDevMultiplier_6 * mtfSTD : na, title="rVWAP - STDEV +6", color=color.new(color.silver, 85), style=plot.style_line, linewidth=Lwidth_rVWAP, display=showrLC)

rV_stdevD1 = plot(showSTDEV ? mtfrVWAP - stDevMultiplier_1 * mtfSTD : na, title="rVWAP - STDEV -1", color=color.new(color.silver, 85), style=plot.style_line, linewidth=Lwidth_rVWAP, display=showrLC)
rV_stdevD2 = plot(showSTDEV ? mtfrVWAP - stDevMultiplier_2 * mtfSTD : na, title="rVWAP - STDEV -2", color=color.new(color.silver, 85), style=plot.style_line, linewidth=Lwidth_rVWAP, display=showrLC)
rV_stdevD3 = plot(showSTDEV ? mtfrVWAP - stDevMultiplier_3 * mtfSTD : na, title="rVWAP - STDEV -3", color=color.new(color.silver, 85), style=plot.style_line, linewidth=Lwidth_rVWAP, display=showrLC)
rV_stdevD4 = plot(showSTDEV ? mtfrVWAP - stDevMultiplier_4 * mtfSTD : na, title="rVWAP - STDEV -4", color=color.new(color.silver, 85), style=plot.style_line, linewidth=Lwidth_rVWAP, display=showrLC)
rV_stdevD5 = plot(showSTDEV ? mtfrVWAP - stDevMultiplier_5 * mtfSTD : na, title="rVWAP - STDEV -5", color=color.new(color.silver, 85), style=plot.style_line, linewidth=Lwidth_rVWAP, display=showrLC)
rV_stdevD6 = plot(showSTDEV ? mtfrVWAP - stDevMultiplier_6 * mtfSTD : na, title="rVWAP - STDEV -6", color=color.new(color.silver, 85), style=plot.style_line, linewidth=Lwidth_rVWAP, display=showrLC)

// ------------------------------------------------

fill(rV_stdevU1, rV_stdevD1, title="rVWAP - STDEV +-1", color=color.new(color.silver, 95), display=display.none)

fill(rV_stdevU2, rV_stdevU1, title="rVWAP - STDEV +2", color= fillSTDEV ? fill_col_up  : na)
fill(rV_stdevU3, rV_stdevU2, title="rVWAP - STDEV +3", color= fillSTDEV ? fill_col_up2 : na)
fill(rV_stdevU4, rV_stdevU3, title="rVWAP - STDEV +4", color= fillSTDEV ? fill_col_up3 : na)
fill(rV_stdevU5, rV_stdevU4, title="rVWAP - STDEV +5", color= fillSTDEV ? fill_col_up4 : na)
fill(rV_stdevU6, rV_stdevU5, title="rVWAP - STDEV +6", color= fillSTDEV ? fill_col_up5 : na)

fill(rV_stdevD2, rV_stdevD1, title="rVWAP - STDEV -2", color= fillSTDEV ? fill_col_down  : na)
fill(rV_stdevD3, rV_stdevD2, title="rVWAP - STDEV -3", color= fillSTDEV ? fill_col_down2 : na)
fill(rV_stdevD4, rV_stdevD3, title="rVWAP - STDEV -4", color= fillSTDEV ? fill_col_down3 : na)
fill(rV_stdevD5, rV_stdevD4, title="rVWAP - STDEV -5", color= fillSTDEV ? fill_col_down4 : na)
fill(rV_stdevD6, rV_stdevD5, title="rVWAP - STDEV -6", color= fillSTDEV ? fill_col_down5 : na)

// -----------------------
groupMA = "Moving Average"
groupMA1 = "MA 0-9"
groupMA2 = "MA A-G"
// -----------------------

ma(source, length, type) =>
    switch type
        "SMA" => ta.sma(source, length)
        "EMA" => ta.ema(source, length)
        "SMMA (RMA)" => ta.rma(source, length)
        "WMA" => ta.wma(source, length)
        "VWMA" => ta.vwma(source, length)
		"LSMA" => ta.linreg(source, length, offset=0)
		"HMA" => ta.hma(source, length)
		"ALMA" => ta.alma(source, length, 0.85, 6.0)

// -----------------------

trend_flip		= input.int		(2, minval=0			, title="Flip trend periods"		, inline="MA01", group=groupMA)
src				= input			(close					, title="Source"					, inline="MA01", group=groupMA)
//ribbon_colorup	= input.color	(color.new(#00FEEF, 95)	, title="Ribbon Colors: Bullish", inline="MA02", group=groupMA)
//ribbon_colordn	= input.color	(color.new(#E21B22, 95)	, title="Bearish"				, inline="MA02", group=groupMA)
show19			= input.bool	(true					, title="Show 0-9 |"				, inline="MA02", group=groupMA)
showAF			= input.bool	(false					, title="Show A-G |"				, inline="MA03", group=groupMA)
//only_fill		= input.bool	(false					, title="Hide MA Lines"				, inline="MA04", group=groupMA)
only_fill = false

price = plot(close, title="Price", color=color.silver, display=display.none)

// -----------------------

visible0		= input.bool(false , title="MA 0:"		, inline="MA0"		, group=groupMA1)
//visiblefill0	= input.bool(false, title="Show MA Fill", inline="MA0A"		, group=groupMA1)
line_width0 = input.int(1, minval=0, title="Line: width", inline="MA0A"		, group=groupMA1)

visible1		= input.bool(true , title="MA 1:"		, inline="MA1"		, group=groupMA1)
//visiblefill1	= input.bool(false, title="Show MA Fill", inline="MA1A"		, group=groupMA1)
line_width1 = input.int(1, minval=0, title="Line: width", inline="MA1A"		, group=groupMA1)

visible2		= input.bool(true , title="MA 2:"		, inline="MA2"		, group=groupMA1)
//visiblefill2	= input.bool(false, title="Show MA Fill", inline="MA2A"		, group=groupMA1)
line_width2 = input.int(1, minval=0, title="Line: width", inline="MA2A"		, group=groupMA1)

visible3		= input.bool(true , title="MA 3:"		, inline="MA3"		, group=groupMA1)
//visiblefill3	= input.bool(false, title="Show MA Fill", inline="MA3A"		, group=groupMA1)
line_width3 = input.int(1, minval=0, title="Line: width", inline="MA3A"		, group=groupMA1)

visible4		= input.bool(true , title="MA 4:"		, inline="MA4"		, group=groupMA1)
//visiblefill4	= input.bool(false, title="Show MA Fill", inline="MA4A"		, group=groupMA1)
line_width4 = input.int(1, minval=0, title="Line: width", inline="MA4A"		, group=groupMA1)

visible5		= input.bool(true , title="MA 5:"		, inline="MA5"		, group=groupMA1)
//visiblefill5	= input.bool(false, title="Show MA Fill", inline="MA5A"		, group=groupMA1)
line_width5 = input.int(1, minval=0, title="Line: width", inline="MA5A"		, group=groupMA1)

visible6		= input.bool(true , title="MA 6:"		, inline="MA6"		, group=groupMA1)
//visiblefill6	= input.bool(false, title="Show MA Fill", inline="MA6A"		, group=groupMA1)
line_width6 = input.int(1, minval=0, title="Line: width", inline="MA6A"		, group=groupMA1)

visible7		= input.bool(true, title="MA 7:"		, inline="MA7"		, group=groupMA1)
//visiblefill7	= input.bool(false, title="Show MA Fill", inline="MA7A"		, group=groupMA1)
line_width7 = input.int(1, minval=0, title="Line: width", inline="MA7A"		, group=groupMA1)

visible8		= input.bool(false, title="MA 8:"		, inline="MA8"		, group=groupMA1)
//visiblefill8	= input.bool(false, title="Show MA Fill", inline="MA8A"		, group=groupMA1)
line_width8 = input.int(1, minval=0, title="Line: width", inline="MA8A"		, group=groupMA1)

visible9		= input.bool(false, title="MA 9:"		, inline="MA9"		, group=groupMA1)
//visiblefill9	= input.bool(false, title="Show MA Fill", inline="MA9A"		, group=groupMA1)
line_width9 = input.int(1, minval=0, title="Line: width", inline="MA9A"		, group=groupMA1)


visible10		= input.bool(true, title="MA A:"		, inline="MA10"		, group=groupMA2)
//visiblefill10 = input.bool(false, title="Show MA Fill", inline="MA10A"	, group=groupMA2)
line_width10 = input.int(1, minval=0, title="Line: width", inline="MA10A"	, group=groupMA2)

visible11		= input.bool(true, title="MA B:"		, inline="MA11"		, group=groupMA2)
//visiblefill11 = input.bool(false, title="Show MA Fill", inline="MA11A"	, group=groupMA2)
line_width11 = input.int(1, minval=0, title="Line: width", inline="MA11A"	, group=groupMA2)

visible12		= input.bool(true, title="MA C:"		, inline="MA12"		, group=groupMA2)
//visiblefill12 = input.bool(false, title="Show MA Fill", inline="MA12A"	, group=groupMA2)
line_width12 = input.int(1, minval=0, title="Line: width", inline="MA12A"	, group=groupMA2)

visible13		= input.bool(true, title="MA D:"		, inline="MA13"		, group=groupMA2)
//visiblefill13 = input.bool(false, title="Show MA Fill", inline="MA13A"	, group=groupMA2)
line_width13 = input.int(1, minval=0, title="Line: width", inline="MA13A"	, group=groupMA2)

visible14		= input.bool(true, title="MA E:"		, inline="MA14"		, group=groupMA2)
//visiblefill14 = input.bool(false, title="Show MA Fill", inline="MA14A"	, group=groupMA2)
line_width14 = input.int(1, minval=0, title="Line: width", inline="MA14A"	, group=groupMA2)

visible15		= input.bool(true, title="MA F:"		, inline="MA15"		, group=groupMA2)
//visiblefill15 = input.bool(false, title="Show MA Fill", inline="MA15A"	, group=groupMA2)
line_width15 = input.int(1, minval=0, title="Line: width", inline="MA15A"	, group=groupMA2)

visible16		= input.bool(true, title="MA G:"		, inline="MA16"		, group=groupMA2)
//visiblefill16 = input.bool(false, title="Show MA Fill", inline="MA16A"	, group=groupMA2)
line_width16 = input.int(1, minval=0, title="Line: width", inline="MA16A"	, group=groupMA2)

// -----------------------

len0 = input.int(5		, minval=1, title="", inline="MA0", group=groupMA1)
len1 = input.int(9		, minval=1, title="", inline="MA1", group=groupMA1)
len2 = input.int(21		, minval=1, title="", inline="MA2", group=groupMA1)
len3 = input.int(34		, minval=1, title="", inline="MA3", group=groupMA1)
len4 = input.int(50		, minval=1, title="", inline="MA4", group=groupMA1)
len5 = input.int(100	, minval=1, title="", inline="MA5", group=groupMA1)
len6 = input.int(200	, minval=1, title="", inline="MA6", group=groupMA1)
len7 = input.int(400	, minval=1, title="", inline="MA7", group=groupMA1)
len8 = input.int(144	, minval=1, title="", inline="MA8", group=groupMA1)
len9 = input.int(233	, minval=1, title="", inline="MA9", group=groupMA1)

len10 = input.int(21	, minval=1, title="", inline="MA10", group=groupMA2)
len11 = input.int(34	, minval=1, title="", inline="MA11", group=groupMA2)
len12 = input.int(50	, minval=1, title="", inline="MA12", group=groupMA2)
len13 = input.int(100	, minval=1, title="", inline="MA13", group=groupMA2)
len14 = input.int(144	, minval=1, title="", inline="MA14", group=groupMA2)
len15 = input.int(200	, minval=1, title="", inline="MA15", group=groupMA2)
len16 = input.int(400	, minval=1, title="", inline="MA16", group=groupMA2)

// -----------------------

maType0 = input.string("EMA", title="", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA", "LSMA", "HMA", "ALMA"], inline="MA0", group=groupMA1)
maType1 = input.string("EMA", title="", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA", "LSMA", "HMA", "ALMA"], inline="MA1", group=groupMA1)
maType2 = input.string("EMA", title="", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA", "LSMA", "HMA", "ALMA"], inline="MA2", group=groupMA1)
maType3 = input.string("EMA", title="", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA", "LSMA", "HMA", "ALMA"], inline="MA3", group=groupMA1)
maType4 = input.string("EMA", title="", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA", "LSMA", "HMA", "ALMA"], inline="MA4", group=groupMA1)
maType5 = input.string("EMA", title="", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA", "LSMA", "HMA", "ALMA"], inline="MA5", group=groupMA1)
maType6 = input.string("EMA", title="", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA", "LSMA", "HMA", "ALMA"], inline="MA6", group=groupMA1)
maType7 = input.string("EMA", title="", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA", "LSMA", "HMA", "ALMA"], inline="MA7", group=groupMA1)
maType8 = input.string("EMA", title="", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA", "LSMA", "HMA", "ALMA"], inline="MA8", group=groupMA1)
maType9 = input.string("EMA", title="", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA", "LSMA", "HMA", "ALMA"], inline="MA9", group=groupMA1)

maType10 = input.string("ALMA", title="", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA", "LSMA", "HMA", "ALMA"], inline="MA10", group=groupMA2)
maType11 = input.string("ALMA", title="", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA", "LSMA", "HMA", "ALMA"], inline="MA11", group=groupMA2)
maType12 = input.string("ALMA", title="", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA", "LSMA", "HMA", "ALMA"], inline="MA12", group=groupMA2)
maType13 = input.string("ALMA", title="", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA", "LSMA", "HMA", "ALMA"], inline="MA13", group=groupMA2)
maType14 = input.string("ALMA", title="", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA", "LSMA", "HMA", "ALMA"], inline="MA14", group=groupMA2)
maType15 = input.string("ALMA", title="", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA", "LSMA", "HMA", "ALMA"], inline="MA15", group=groupMA2)
maType16 = input.string("ALMA", title="", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA", "LSMA", "HMA", "ALMA"], inline="MA16", group=groupMA2)

// -----------------------

up_color0 = input.color(color.new(#FD63B0, 70), title="", inline="MA0A", group=groupMA1)
up_color1 = input.color(color.new(#E12D7B, 70), title="", inline="MA1A", group=groupMA1)
up_color2 = input.color(color.new(#F67B52, 70), title="", inline="MA2A", group=groupMA1)
up_color3 = input.color(color.new(#EDCD3B, 70), title="", inline="MA3A", group=groupMA1)
up_color4 = input.color(color.new(#3BBC54, 70), title="", inline="MA4A", group=groupMA1)
up_color5 = input.color(color.new(#30A0F5, 70), title="", inline="MA5A", group=groupMA1)
up_color6 = input.color(color.new(#8C3ED1, 70), title="", inline="MA6A", group=groupMA1)
up_color7 = input.color(color.new(#6365CF, 70), title="", inline="MA7A", group=groupMA1)
up_color8 = input.color(color.new(#77B9E0, 70), title="", inline="MA8A", group=groupMA1)
up_color9 = input.color(color.new(#BA7DDB, 70), title="", inline="MA9A", group=groupMA1)

up_color10 = input.color(color.new(#E12D7B, 70), title="", inline="MA10A", group=groupMA2)
up_color11 = input.color(color.new(#F67B52, 70), title="", inline="MA11A", group=groupMA2)
up_color12 = input.color(color.new(#EDCD3B, 70), title="", inline="MA12A", group=groupMA2)
up_color13 = input.color(color.new(#3BBC54, 70), title="", inline="MA13A", group=groupMA2)
up_color14 = input.color(color.new(#30A0F5, 70), title="", inline="MA14A", group=groupMA2)
up_color15 = input.color(color.new(#8C3ED1, 70), title="", inline="MA15A", group=groupMA2)
up_color16 = input.color(color.new(#6365CF, 70), title="", inline="MA16A", group=groupMA2)

down_color0 = input.color(color.new(#FD63B0, 85), title="", inline="MA0A", group=groupMA1)
down_color1 = input.color(color.new(#E12D7B, 85), title="", inline="MA1A", group=groupMA1)
down_color2 = input.color(color.new(#F67B52, 85), title="", inline="MA2A", group=groupMA1)
down_color3 = input.color(color.new(#EDCD3B, 85), title="", inline="MA3A", group=groupMA1)
down_color4 = input.color(color.new(#3BBC54, 85), title="", inline="MA4A", group=groupMA1)
down_color5 = input.color(color.new(#30A0F5, 85), title="", inline="MA5A", group=groupMA1)
down_color6 = input.color(color.new(#8C3ED1, 85), title="", inline="MA6A", group=groupMA1)
down_color7 = input.color(color.new(#6365CF, 85), title="", inline="MA7A", group=groupMA1)
down_color8 = input.color(color.new(#77B9E0, 85), title="", inline="MA8A", group=groupMA1)
down_color9 = input.color(color.new(#BA7DDB, 85), title="", inline="MA9A", group=groupMA1)

down_color10 = input.color(color.new(#E12D7B, 85), title="", inline="MA10A", group=groupMA2)
down_color11 = input.color(color.new(#F67B52, 85), title="", inline="MA11A", group=groupMA2)
down_color12 = input.color(color.new(#EDCD3B, 85), title="", inline="MA12A", group=groupMA2)
down_color13 = input.color(color.new(#3BBC54, 85), title="", inline="MA13A", group=groupMA2)
down_color14 = input.color(color.new(#30A0F5, 85), title="", inline="MA14A", group=groupMA2)
down_color15 = input.color(color.new(#8C3ED1, 85), title="", inline="MA15A", group=groupMA2)
down_color16 = input.color(color.new(#6365CF, 85), title="", inline="MA16A", group=groupMA2)

// -----------------------

ma0 = ma(src, len0, maType0)
ma1 = ma(src, len1, maType1)
ma2 = ma(src, len2, maType2)
ma3 = ma(src, len3, maType3)
ma4 = ma(src, len4, maType4)
ma5 = ma(src, len5, maType5)
ma6 = ma(src, len6, maType6)
ma7 = ma(src, len7, maType7)
ma8 = ma(src, len8, maType8)
ma9 = ma(src, len9, maType9)

ma10 = ma(src, len10, maType10)
ma11 = ma(src, len11, maType11)
ma12 = ma(src, len12, maType12)
ma13 = ma(src, len13, maType13)
ma14 = ma(src, len14, maType14)
ma15 = ma(src, len15, maType15)
ma16 = ma(src, len16, maType16)

// -----------------------

tf19 = input.bool	(false, title="Override timeframe", inline="MA02", group=groupMA)
tfAF = input.bool	(false, title="Override timeframe", inline="MA03", group=groupMA)

res19 = input.timeframe("", title="", inline="MA02", group=groupMA)
resAF = input.timeframe("", title="", inline="MA03", group=groupMA)

res0 = tf19 ? res19 : input.timeframe("", title="", inline="MA0", group=groupMA1)
res1 = tf19 ? res19 : input.timeframe("", title="", inline="MA1", group=groupMA1)
res2 = tf19 ? res19 : input.timeframe("", title="", inline="MA2", group=groupMA1)
res3 = tf19 ? res19 : input.timeframe("", title="", inline="MA3", group=groupMA1)
res4 = tf19 ? res19 : input.timeframe("", title="", inline="MA4", group=groupMA1)
res5 = tf19 ? res19 : input.timeframe("", title="", inline="MA5", group=groupMA1)
res6 = tf19 ? res19 : input.timeframe("", title="", inline="MA6", group=groupMA1)
res7 = tf19 ? res19 : input.timeframe("", title="", inline="MA7", group=groupMA1)
res8 = tf19 ? res19 : input.timeframe("", title="", inline="MA8", group=groupMA1)
res9 = tf19 ? res19 : input.timeframe("", title="", inline="MA9", group=groupMA1)

res10 = tfAF ? resAF : input.timeframe("", title="", inline="MA10", group=groupMA2)
res11 = tfAF ? resAF : input.timeframe("", title="", inline="MA11", group=groupMA2)
res12 = tfAF ? resAF : input.timeframe("", title="", inline="MA12", group=groupMA2)
res13 = tfAF ? resAF : input.timeframe("", title="", inline="MA13", group=groupMA2)
res14 = tfAF ? resAF : input.timeframe("", title="", inline="MA14", group=groupMA2)
res15 = tfAF ? resAF : input.timeframe("", title="", inline="MA15", group=groupMA2)
res16 = tfAF ? resAF : input.timeframe("", title="", inline="MA16", group=groupMA2)

maT0 = request.security(syminfo.tickerid, res0, ma0, gaps=barmerge.gaps_off)
maT1 = request.security(syminfo.tickerid, res1, ma1, gaps=barmerge.gaps_off)
maT2 = request.security(syminfo.tickerid, res2, ma2, gaps=barmerge.gaps_off)
maT3 = request.security(syminfo.tickerid, res3, ma3, gaps=barmerge.gaps_off)
maT4 = request.security(syminfo.tickerid, res4, ma4, gaps=barmerge.gaps_off)
maT5 = request.security(syminfo.tickerid, res5, ma5, gaps=barmerge.gaps_off)
maT6 = request.security(syminfo.tickerid, res6, ma6, gaps=barmerge.gaps_off)
maT7 = request.security(syminfo.tickerid, res7, ma7, gaps=barmerge.gaps_off)
maT8 = request.security(syminfo.tickerid, res8, ma8, gaps=barmerge.gaps_off)
maT9 = request.security(syminfo.tickerid, res9, ma9, gaps=barmerge.gaps_off)

maT10 = request.security(syminfo.tickerid, res10, ma10, gaps=barmerge.gaps_off)
maT11 = request.security(syminfo.tickerid, res11, ma11, gaps=barmerge.gaps_off)
maT12 = request.security(syminfo.tickerid, res12, ma12, gaps=barmerge.gaps_off)
maT13 = request.security(syminfo.tickerid, res13, ma13, gaps=barmerge.gaps_off)
maT14 = request.security(syminfo.tickerid, res14, ma14, gaps=barmerge.gaps_off)
maT15 = request.security(syminfo.tickerid, res15, ma15, gaps=barmerge.gaps_off)
maT16 = request.security(syminfo.tickerid, res16, ma16, gaps=barmerge.gaps_off)

// -----------------------

plot_color0 = show19 and visible0 ? maT0 >= maT0[trend_flip] ? up_color0 : down_color0 : na
plot_color1 = show19 and visible1 ? maT1 >= maT1[trend_flip] ? up_color1 : down_color1 : na
plot_color2 = show19 and visible2 ? maT2 >= maT2[trend_flip] ? up_color2 : down_color2 : na
plot_color3 = show19 and visible3 ? maT3 >= maT3[trend_flip] ? up_color3 : down_color3 : na
plot_color4 = show19 and visible4 ? maT4 >= maT4[trend_flip] ? up_color4 : down_color4 : na
plot_color5 = show19 and visible5 ? maT5 >= maT5[trend_flip] ? up_color5 : down_color5 : na
plot_color6 = show19 and visible6 ? maT6 >= maT6[trend_flip] ? up_color6 : down_color6 : na
plot_color7 = show19 and visible7 ? maT7 >= maT7[trend_flip] ? up_color7 : down_color7 : na
plot_color8 = show19 and visible8 ? maT8 >= maT8[trend_flip] ? up_color8 : down_color8 : na
plot_color9 = show19 and visible9 ? maT9 >= maT9[trend_flip] ? up_color9 : down_color9 : na

plot_color10 = showAF and visible10 ? maT10 >= maT10[trend_flip] ? up_color10 : down_color10 : na
plot_color11 = showAF and visible11 ? maT11 >= maT11[trend_flip] ? up_color11 : down_color11 : na
plot_color12 = showAF and visible12 ? maT12 >= maT12[trend_flip] ? up_color12 : down_color12 : na
plot_color13 = showAF and visible13 ? maT13 >= maT13[trend_flip] ? up_color13 : down_color13 : na
plot_color14 = showAF and visible14 ? maT14 >= maT14[trend_flip] ? up_color14 : down_color14 : na
plot_color15 = showAF and visible15 ? maT15 >= maT15[trend_flip] ? up_color15 : down_color15 : na
plot_color16 = showAF and visible16 ? maT16 >= maT16[trend_flip] ? up_color16 : down_color16 : na

map0 = plot(maT0, title="MA 0", style=plot.style_line, color= only_fill ? na : plot_color0, linewidth=line_width0)
map1 = plot(maT1, title="MA 1", style=plot.style_line, color= only_fill ? na : plot_color1, linewidth=line_width1)
map2 = plot(maT2, title="MA 2", style=plot.style_line, color= only_fill ? na : plot_color2, linewidth=line_width2)
map3 = plot(maT3, title="MA 3", style=plot.style_line, color= only_fill ? na : plot_color3, linewidth=line_width3)
map4 = plot(maT4, title="MA 4", style=plot.style_line, color= only_fill ? na : plot_color4, linewidth=line_width4)
map5 = plot(maT5, title="MA 5", style=plot.style_line, color= only_fill ? na : plot_color5, linewidth=line_width5)
map6 = plot(maT6, title="MA 6", style=plot.style_line, color= only_fill ? na : plot_color6, linewidth=line_width6)
map7 = plot(maT7, title="MA 7", style=plot.style_line, color= only_fill ? na : plot_color7, linewidth=line_width7)
map8 = plot(maT8, title="MA 8", style=plot.style_line, color= only_fill ? na : plot_color8, linewidth=line_width8)
map9 = plot(maT9, title="MA 9", style=plot.style_line, color= only_fill ? na : plot_color9, linewidth=line_width9)

map10 = plot(maT10, title="MA 10", style=plot.style_line, color= only_fill ? na : plot_color10, linewidth=line_width10)
map11 = plot(maT11, title="MA 11", style=plot.style_line, color= only_fill ? na : plot_color11, linewidth=line_width11)
map12 = plot(maT12, title="MA 12", style=plot.style_line, color= only_fill ? na : plot_color12, linewidth=line_width12)
map13 = plot(maT13, title="MA 13", style=plot.style_line, color= only_fill ? na : plot_color13, linewidth=line_width13)
map14 = plot(maT14, title="MA 14", style=plot.style_line, color= only_fill ? na : plot_color14, linewidth=line_width14)
map15 = plot(maT15, title="MA 15", style=plot.style_line, color= only_fill ? na : plot_color15, linewidth=line_width15)
map16 = plot(maT16, title="MA 16", style=plot.style_line, color= only_fill ? na : plot_color16, linewidth=line_width16)

// -----------------------

//ma1color = (close > maT1 ? ribbon_colorup : ribbon_colordn)
//ma2color = (close > maT2 ? ribbon_colorup : ribbon_colordn)
//ma3color = (close > maT3 ? ribbon_colorup : ribbon_colordn)
//ma4color = (close > maT4 ? ribbon_colorup : ribbon_colordn)
//ma5color = (close > maT5 ? ribbon_colorup : ribbon_colordn)
//ma6color = (close > maT6 ? ribbon_colorup : ribbon_colordn)
//ma7color = (close > maT7 ? ribbon_colorup : ribbon_colordn)
//ma8color = (close > maT8 ? ribbon_colorup : ribbon_colordn)
//ma9color = (close > maT9 ? ribbon_colorup : ribbon_colordn)

//ma10color = (close > maT10 ? ribbon_colorup : ribbon_colordn)
//ma11color = (close > maT11 ? ribbon_colorup : ribbon_colordn)
//ma12color = (close > maT12 ? ribbon_colorup : ribbon_colordn)
//ma13color = (close > maT13 ? ribbon_colorup : ribbon_colordn)
//ma14color = (close > maT14 ? ribbon_colorup : ribbon_colordn)
//ma15color = (close > maT15 ? ribbon_colorup : ribbon_colordn)

//fill(price, map1, visible1 and visiblefill1 ? ma1color : na, title="MA Fill 1")
//fill(price, map2, visible2 and visiblefill2 ? ma2color : na, title="MA Fill 2")
//fill(price, map3, visible3 and visiblefill3 ? ma3color : na, title="MA Fill 3")
//fill(price, map4, visible4 and visiblefill4 ? ma4color : na, title="MA Fill 4")
//fill(price, map5, visible5 and visiblefill5 ? ma5color : na, title="MA Fill 5")
//fill(price, map6, visible6 and visiblefill6 ? ma6color : na, title="MA Fill 6")
//fill(price, map7, visible7 and visiblefill7 ? ma7color : na, title="MA Fill 7")
//fill(price, map8, visible8 and visiblefill8 ? ma8color : na, title="MA Fill 8")
//fill(price, map9, visible9 and visiblefill9 ? ma9color : na, title="MA Fill 9")

//fill(price, map10, visible10 and visiblefill10 ? ma9color : na, title="MA Fill 10")
//fill(price, map11, visible11 and visiblefill11 ? ma9color : na, title="MA Fill 11")
//fill(price, map12, visible12 and visiblefill12 ? ma9color : na, title="MA Fill 12")
//fill(price, map13, visible13 and visiblefill13 ? ma9color : na, title="MA Fill 13")
//fill(price, map14, visible14 and visiblefill14 ? ma9color : na, title="MA Fill 14")
//fill(price, map15, visible15 and visiblefill15 ? ma9color : na, title="MA Fill 15")

// ------------------------
groupBB = "Bollinger Bands"
// ------------------------

visibleBB	= input.bool		(false			, title="Boll.:"	, inline="BB1", group=groupBB)
lengthBB	= input.int			(20, minval=1	, title=""			, inline="BB1", group=groupBB)
srcBB		= input				(close			, title=""			, inline="BB1", group=groupBB)
resBB		= input.timeframe	(""				, title=""			, inline="BB1", group=groupBB)
mult		= input.float		(2.0			, title="Standard Dev."	, inline="BB2", group=groupBB)

basis		= ta.sma(srcBB, lengthBB)
dev			= mult * ta.stdev(srcBB, lengthBB)

offset		= input.int(0, minval=-500, maxval=500, title="Offset", inline="BB2", group=groupBB)
BB_color	= input.color(color.new(color.silver, 97), title="|", inline="BB2", group=groupBB)

upper = basis + dev
lower = basis - dev

MTFbasis = request.security(syminfo.tickerid, resBB, basis)
MTFupper = request.security(syminfo.tickerid, resBB, upper)
MTFlower = request.security(syminfo.tickerid, resBB, lower)

plot(visibleBB ? MTFbasis : na		, color=color.new(color.silver, 95), offset=offset, display=display.none, title="BB - Basis")
p1 = plot(visibleBB ? MTFupper : na	, color=color.new(color.silver, 95), offset=offset, display=display.none, title="BB - Upper")
p2 = plot(visibleBB ? MTFlower : na	, color=color.new(color.silver, 95), offset=offset, display=display.none, title="BB - Lower")

fill(p1, p2, color=BB_color, title="BB - Background")