MTF MA Ribbon and Bands + BB, Gaussian F. and R. VWAP with StDev
// 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)

// ------------------------------
groupMA = "Moving Average Ribbon"
// ------------------------------

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)
only_fill		= input.bool	(false					, title="Hide MA Lines"			, inline="MA02", group=groupMA)

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

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

visible1		= input.bool(true , title="MA 1:"		, inline="MA1"	, group=groupMA)
visiblefill1	= input.bool(false, title="Show MA Fill", inline="MA1A"	, group=groupMA)
visible2		= input.bool(true , title="MA 2:"		, inline="MA2"	, group=groupMA)
visiblefill2	= input.bool(false, title="Show MA Fill", inline="MA2A"	, group=groupMA)
visible3		= input.bool(true , title="MA 3:"		, inline="MA3"	, group=groupMA)
visiblefill3	= input.bool(false, title="Show MA Fill", inline="MA3A"	, group=groupMA)
visible4		= input.bool(true , title="MA 4:"		, inline="MA4"	, group=groupMA)
visiblefill4	= input.bool(false, title="Show MA Fill", inline="MA4A"	, group=groupMA)
visible5		= input.bool(true , title="MA 5:"		, inline="MA5"	, group=groupMA)
visiblefill5	= input.bool(false, title="Show MA Fill", inline="MA5A"	, group=groupMA)
visible6		= input.bool(true , title="MA 6:"		, inline="MA6"	, group=groupMA)
visiblefill6	= input.bool(false, title="Show MA Fill", inline="MA6A"	, group=groupMA)
visible7		= input.bool(false, title="MA 7:"		, inline="MA7"	, group=groupMA)
visiblefill7	= input.bool(false, title="Show MA Fill", inline="MA7A"	, group=groupMA)
visible8		= input.bool(false, title="MA 8:"		, inline="MA8"	, group=groupMA)
visiblefill8	= input.bool(false, title="Show MA Fill", inline="MA8A"	, group=groupMA)
visible9		= input.bool(false, title="MA 9:"		, inline="MA9"	, group=groupMA)
visiblefill9	= input.bool(false, title="Show MA Fill", inline="MA9A"	, group=groupMA)

//visible10		= input.bool(false, title="MA A:"		, inline="MA10"	, group=groupMA)
//visiblefill10 = input.bool(false, title="Show MA Fill", inline="MA10A", group=groupMA)
//visible11		= input.bool(false, title="MA B:"		, inline="MA11"	, group=groupMA)
//visiblefill11 = input.bool(false, title="Show MA Fill", inline="MA11A", group=groupMA)
//visible12		= input.bool(false, title="MA C:"		, inline="MA12"	, group=groupMA)
//visiblefill12 = input.bool(false, title="Show MA Fill", inline="MA12A", group=groupMA)
//visible13		= input.bool(false, title="MA D:"		, inline="MA13"	, group=groupMA)
//visiblefill13 = input.bool(false, title="Show MA Fill", inline="MA13A", group=groupMA)
//visible14		= input.bool(false, title="MA E:"		, inline="MA14"	, group=groupMA)
//visiblefill14 = input.bool(false, title="Show MA Fill", inline="MA14A", group=groupMA)
//visible15		= input.bool(false, title="MA F:"		, inline="MA15"	, group=groupMA)
//visiblefill15 = input.bool(false, title="Show MA Fill", inline="MA15A", group=groupMA)

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

len1 = input.int(9		, minval=1, title="", inline="MA1", group=groupMA)
len2 = input.int(21		, minval=1, title="", inline="MA2", group=groupMA)
len3 = input.int(34		, minval=1, title="", inline="MA3", group=groupMA)
len4 = input.int(55		, minval=1, title="", inline="MA4", group=groupMA)
len5 = input.int(100	, minval=1, title="", inline="MA5", group=groupMA)
len6 = input.int(200	, minval=1, title="", inline="MA6", group=groupMA)
len7 = input.int(400	, minval=1, title="", inline="MA7", group=groupMA)
len8 = input.int(800	, minval=1, title="", inline="MA8", group=groupMA)
len9 = input.int(1600	, minval=1, title="", inline="MA9", group=groupMA)

//len10 = input.int(9	, minval=1, title="", inline="MA10", group=groupMA)
//len11 = input.int(21	, minval=1, title="", inline="MA11", group=groupMA)
//len12 = input.int(34	, minval=1, title="", inline="MA12", group=groupMA)
//len13 = input.int(55	, minval=1, title="", inline="MA13", group=groupMA)
//len14 = input.int(100	, minval=1, title="", inline="MA14", group=groupMA)
//len15 = input.int(200	, minval=1, title="", inline="MA15", group=groupMA)

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

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

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

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

line_width1 = input.int(1, minval=0, title="| Line Width", inline="MA1A", group=groupMA)
line_width2 = input.int(1, minval=0, title="| Line Width", inline="MA2A", group=groupMA)
line_width3 = input.int(1, minval=0, title="| Line Width", inline="MA3A", group=groupMA)
line_width4 = input.int(1, minval=0, title="| Line Width", inline="MA4A", group=groupMA)
line_width5 = input.int(1, minval=0, title="| Line Width", inline="MA5A", group=groupMA)
line_width6 = input.int(1, minval=0, title="| Line Width", inline="MA6A", group=groupMA)
line_width7 = input.int(1, minval=0, title="| Line Width", inline="MA7A", group=groupMA)
line_width8 = input.int(1, minval=0, title="| Line Width", inline="MA8A", group=groupMA)
line_width9 = input.int(1, minval=0, title="| Line Width", inline="MA9A", group=groupMA)

//line_width10 = input.int(1, minval=0, title="| Line Width", inline="MA10A", group=groupMA)
//line_width11 = input.int(1, minval=0, title="| Line Width", inline="MA11A", group=groupMA)
//line_width12 = input.int(1, minval=0, title="| Line Width", inline="MA12A", group=groupMA)
//line_width13 = input.int(1, minval=0, title="| Line Width", inline="MA13A", group=groupMA)
//line_width14 = input.int(1, minval=0, title="| Line Width", inline="MA14A", group=groupMA)
//line_width15 = input.int(1, minval=0, title="| Line Width", inline="MA15A", group=groupMA)

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

up_color1 = input.color(color.new(#E12D7B, 25), title="", inline="MA1A", group=groupMA)
up_color2 = input.color(color.new(#F67B52, 25), title="", inline="MA2A", group=groupMA)
up_color3 = input.color(color.new(#EDCD3B, 25), title="", inline="MA3A", group=groupMA)
up_color4 = input.color(color.new(#3BBC54, 25), title="", inline="MA4A", group=groupMA)
up_color5 = input.color(color.new(#2665BD, 25), title="", inline="MA5A", group=groupMA)
up_color6 = input.color(color.new(#481899, 25), title="", inline="MA6A", group=groupMA)
up_color7 = input.color(color.new(#B2B5BE, 50), title="", inline="MA7A", group=groupMA)
up_color8 = input.color(color.new(#B2B5BE, 50), title="", inline="MA8A", group=groupMA)
up_color9 = input.color(color.new(#B2B5BE, 50), title="", inline="MA9A", group=groupMA)

//up_color10 = input.color(color.new(#B2B5BE, 50), title="", inline="MA10A", group=groupMA)
//up_color11 = input.color(color.new(#B2B5BE, 50), title="", inline="MA11A", group=groupMA)
//up_color12 = input.color(color.new(#B2B5BE, 50), title="", inline="MA12A", group=groupMA)
//up_color13 = input.color(color.new(#B2B5BE, 50), title="", inline="MA13A", group=groupMA)
//up_color14 = input.color(color.new(#B2B5BE, 50), title="", inline="MA14A", group=groupMA)
//up_color15 = input.color(color.new(#B2B5BE, 50), title="", inline="MA15A", group=groupMA)

down_color1 = input.color(color.new(#F19A9C, 50), title="", inline="MA1A", group=groupMA)
down_color2 = input.color(color.new(#FFC29F, 50), title="", inline="MA2A", group=groupMA)
down_color3 = input.color(color.new(#FFFAAE, 50), title="", inline="MA3A", group=groupMA)
down_color4 = input.color(color.new(#CDECAD, 50), title="", inline="MA4A", group=groupMA)
down_color5 = input.color(color.new(#A0CDED, 50), title="", inline="MA5A", group=groupMA)
down_color6 = input.color(color.new(#AF8FC1, 50), title="", inline="MA6A", group=groupMA)
down_color7 = input.color(color.new(#B2B5BE, 75), title="", inline="MA7A", group=groupMA)
down_color8 = input.color(color.new(#B2B5BE, 75), title="", inline="MA8A", group=groupMA)
down_color9 = input.color(color.new(#B2B5BE, 75), title="", inline="MA9A", group=groupMA)

//down_color10 = input.color(color.new(#B2B5BE, 75), title="", inline="MA10A", group=groupMA)
//down_color11 = input.color(color.new(#B2B5BE, 75), title="", inline="MA11A", group=groupMA)
//down_color12 = input.color(color.new(#B2B5BE, 75), title="", inline="MA12A", group=groupMA)
//down_color13 = input.color(color.new(#B2B5BE, 75), title="", inline="MA13A", group=groupMA)
//down_color14 = input.color(color.new(#B2B5BE, 75), title="", inline="MA14A", group=groupMA)
//down_color15 = input.color(color.new(#B2B5BE, 75), title="", inline="MA15A", group=groupMA)

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

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)

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

res1 = input.timeframe("", title="", inline="MA1", group=groupMA)
res2 = input.timeframe("", title="", inline="MA2", group=groupMA)
res3 = input.timeframe("", title="", inline="MA3", group=groupMA)
res4 = input.timeframe("", title="", inline="MA4", group=groupMA)
res5 = input.timeframe("", title="", inline="MA5", group=groupMA)
res6 = input.timeframe("", title="", inline="MA6", group=groupMA)
res7 = input.timeframe("", title="", inline="MA7", group=groupMA)
res8 = input.timeframe("", title="", inline="MA8", group=groupMA)
res9 = input.timeframe("", title="", inline="MA9", group=groupMA)

//res10 = input.timeframe("", title="", inline="MA10", group=groupMA)
//res11 = input.timeframe("", title="", inline="MA11", group=groupMA)
//res12 = input.timeframe("", title="", inline="MA12", group=groupMA)
//res13 = input.timeframe("", title="", inline="MA13", group=groupMA)
//res14 = input.timeframe("", title="", inline="MA14", group=groupMA)
//res15 = input.timeframe("", title="", inline="MA15", group=groupMA)

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)

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

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

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

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_width9)
//map11 = plot(maT11, title="MA 11", style=plot.style_line, color= only_fill ? na : plot_color11, linewidth=line_width9)
//map12 = plot(maT12, title="MA 12", style=plot.style_line, color= only_fill ? na : plot_color12, linewidth=line_width9)
//map13 = plot(maT13, title="MA 13", style=plot.style_line, color= only_fill ? na : plot_color13, linewidth=line_width9)
//map14 = plot(maT14, title="MA 14", style=plot.style_line, color= only_fill ? na : plot_color14, linewidth=line_width9)
//map15 = plot(maT15, title="MA 15", style=plot.style_line, color= only_fill ? na : plot_color15, linewidth=line_width9)

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

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")

// ----------------------------
groupB = "Moving Average Bands"
// ----------------------------

showMAb		= input.bool		(false			, title="MA b:", inline="MAB1", group=groupB)
lengthMAb	= input.int			(34, minval=1	, title="", inline="MAB1", group=groupB)
maTypeMAb	= input.string		("EMA"			, title="", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA", "LSMA", "HMA", "ALMA"], inline="MAB1", group=groupB)
resMAb		= input.timeframe	(""				, title="", inline="MAB1", group=groupB)

h_MA		= ma(high, lengthMAb, maTypeMAb)
l_MA		= ma(low, lengthMAb, maTypeMAb)
MA_b		= ma(close, lengthMAb, maTypeMAb)

h_MAmtf		= request.security(syminfo.tickerid, resMAb, h_MA)
l_MAmtf		= request.security(syminfo.tickerid, resMAb, l_MA)
MA_bmtf		= request.security(syminfo.tickerid, resMAb, MA_b)

b_High		= ((h_MAmtf - MA_bmtf) * math.phi) * math.pi + MA_bmtf
b_Low		= (-(MA_bmtf - l_MAmtf) * math.phi) * math.pi + MA_bmtf

b_High_S	= ta.wma(b_High, 8)
b_Low_S		= ta.wma(b_Low, 8)

phi_High	= ((h_MAmtf - MA_bmtf) * math.phi) * (math.phi + 4) + MA_bmtf
phi_Low		= (-(MA_bmtf - l_MAmtf) * math.phi) * (math.phi + 4) + MA_bmtf

phi_High_S	= ta.wma(phi_High, 8)
phi_Low_S	= ta.wma(phi_Low, 8)

hi_color	= input.color(color.new(color.red, 95)		, title="Fill Colors: Upper", inline="MAB2", group=groupB)
mi_color	= input.color(color.new(color.silver, 95)	, title="Middle"			, inline="MAB2", group=groupB)
lo_color	= input.color(color.new(color.blue, 95)		, title="Lower"				, inline="MAB2", group=groupB)

highP1		= plot(showMAb ? h_MAmtf : na		, color=color.new(color.silver, 95), title = "Bands - Middle Top"	, display=display.none)
lowP1		= plot(showMAb ? l_MAmtf : na		, color=color.new(color.silver, 95), title = "Bands - Middle Bottom", display=display.none)

highP3		= plot(showMAb ? b_High_S : na		, color=color.new(color.silver, 95), title = "Bands - Upper Bottom"	, display=display.none)
lowP3		= plot(showMAb ? b_Low_S : na		, color=color.new(color.silver, 95), title = "Bands - Lower Top"	, display=display.none)

phiPlotHigh = plot(showMAb ? phi_High_S : na	, color=color.new(color.silver, 95), title = "Bands - Upper Top"	, display=display.none)
phiPlotLow	= plot(showMAb ? phi_Low_S : na		, color=color.new(color.silver, 95), title = "Bands - Lower Bottom"	, display=display.none)

fill(phiPlotHigh, highP3, hi_color, title = "Bands - Sell Zone")
fill(lowP3, phiPlotLow	, lo_color, title = "Bands - Buy Zone")
fill(highP1, lowP1		, mi_color, title = "Bands - Median Zone")

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

visibleBB	= input.bool		(false			, title="B.B.:"	, 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="StDev"	, 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="Fill Color", 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")

// ------------------------
groupGF = "Gaussian Filter"
// ------------------------

fact(int n)=>
    float a = 1
    for i = 1 to n 
        a *= i
    a

_alpha(int period, int poles)=>
    w = 2.0 * math.pi / period
    float b = (1.0 - math.cos(w)) / (math.pow(1.414, 2.0 / poles) - 1.0)
    float a = - b + math.sqrt(b * b + 2.0 * b)
    a
    
_npolegf(float src, int period, int order)=>
    coeffs = matrix.new<float>(order + 1, 3, 0.)
    float a = _alpha(period, order)
    for r = 0 to order 
        out = nz(fact(order) / (fact(order - r) * fact(r)), 1)
        matrix.set(coeffs, r, 0, out)
        matrix.set(coeffs, r, 1, math.pow(a, r))
        matrix.set(coeffs, r, 2, math.pow(1.0 - a, r))
    float filt = src * matrix.get(coeffs, order, 1)
    int sign = 1
    for r = 1 to order 
        filt += sign * matrix.get(coeffs, r, 0) * matrix.get(coeffs, r, 2) * nz(filt[r])
        sign *= -1
    filt

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

showGF		= input		(false			, title="G.F.:"	, inline="GF1", group=groupGF)
periodGF	= input.int	(144			, title=""		, inline="GF1", group=groupGF)
orderGF		= input.int	(4, minval = 1	, title="Poles"	, inline="GF2", group=groupGF)
srcGF		= input		(close			, title=""		, inline="GF1", group=groupGF)

LwidthGF	= input.int	(2, minval=0			, title="Line Width", inline="GF2", group=groupGF)
colorGF1	= input.color(color.new(#00FEEF, 25), title=""			, inline="GF2", group=groupGF)
colorGF2	= input.color(color.new(#E21B22, 25), title=""			, inline="GF2", group=groupGF)

out			= _npolegf(srcGF, periodGF, orderGF)

resGF		= input.timeframe("", title="", inline="GF1", group=groupGF)
mtfGF		= request.security(syminfo.tickerid, resGF, out, gaps=barmerge.gaps_off)

colorGF		=  mtfGF > mtfGF[1] ? colorGF1 : mtfGF < mtfGF[1] ? colorGF2 : color.silver

plot(showGF ? mtfGF : na, color=colorGF, linewidth=LwidthGF, title="Gaussian Filter")

// -------------------------------------
groupRV = "Rolling VWAP & StDev Bands"
// -------------------------------------

show_rVWAP		= input(false, title="VWAP:"		, inline="RV1", group=groupRV)
showSTDEV		= input(false, title="StDev 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.618	, step=0.1, title="StDev 0.5", inline="StDev1", group=groupRV)
stDevMultiplier_2 = input.float(1.0		, step=0.1, title="StDev 1.0", inline="StDev1", group=groupRV)
stDevMultiplier_3 = input.float(1.618	, step=0.1, title="StDev 1.5", inline="StDev2", group=groupRV)
stDevMultiplier_4 = input.float(2.0		, step=0.1, title="StDev 2.0", inline="StDev2", group=groupRV)
stDevMultiplier_5 = input.float(2.618	, step=0.1, title="StDev 2.5", inline="StDev3", group=groupRV)
//stDevMultiplier_6 = input.float(3.0	, step=0.1, title="StDev 3.0", inline="StDev6", group=groupRV)

rVWAP_color		= input.color(color.new(color.silver, 50)	, 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(false, 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, 75), 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, 75), 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, 75), 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, 75), 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, 75), 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, 75), 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, 75), 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, 75), 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, 75), 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, 75), 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, 75), 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, 75), 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)