Hx 9 Moving Averages
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HDrbx

//@version=5
indicator(title='Hx 9 Moving Averages', shorttitle='Hx 9 MA', overlay=true, timeframe='')
// (c) - HDrbx 2021

ma1Show = input.bool(title='', defval=true, inline='1')
ma1Type = input.string(title='MA1', defval='Hull', inline='1', options=['Sma', 'Ema', 'VWma', 'Wma', 'Rma', 'Hull', 'Smma'])
ma1Length = input.int(title='', defval=9, inline='1')
ma1Source = input.source(title='', defval=close, inline='1')
ma1Color = input.color(title='', defval=color.gray, inline='1')

ma2Show = input.bool(title='', defval=true, inline='2')
ma2Type = input.string(title='MA2', defval='Ema', inline='2', options=['Sma', 'Ema', 'VWma', 'Wma', 'Rma', 'Hull', 'Smma'])
ma2Length = input.int(title='', defval=10, inline='2')
ma2Source = input.source(title='', defval=close, inline='2')
ma2Color = input.color(title='', defval=color.red, inline='2')

ma3Show = input.bool(title='', defval=true, inline='3')
ma3Type = input.string(title='MA3', defval='Sma', inline='3', options=['Sma', 'Ema', 'VWma', 'Wma', 'Rma', 'Hull', 'Smma'])
ma3Length = input.int(title='', defval=10, inline='3')
ma3Source = input.source(title='', defval=close, inline='3')
ma3Color = input.color(title='', defval=color.orange, inline='3')

ma4Show = input.bool(title='', defval=true, inline='4')
ma4Type = input.string(title='MA4', defval='Ema', inline='4', options=['Sma', 'Ema', 'VWma', 'Wma', 'Rma', 'Hull', 'Smma'])
ma4Length = input.int(title='', defval=20, inline='4')
ma4Source = input.source(title='', defval=close, inline='4')
ma4Color = input.color(title='', defval=color.yellow, inline='4')

ma5Show = input.bool(title='', defval=true, inline='5')
ma5Type = input.string(title='MA5', defval='Ema', inline='5', options=['Sma', 'Ema', 'VWma', 'Wma', 'Rma', 'Hull', 'Smma'])
ma5Length = input.int(title='', defval=50, inline='5')
ma5Source = input.source(title='', defval=close, inline='5')
ma5Color = input.color(title='', defval=color.lime, inline='5')

ma6Show = input.bool(title='', defval=true, inline='6')
ma6Type = input.string(title='MA6', defval='Sma', inline='6', options=['Sma', 'Ema', 'VWma', 'Wma', 'Rma', 'Hull', 'Smma'])
ma6Length = input.int(title='', defval=50, inline='6')
ma6Source = input.source(title='', defval=close, inline='6')
ma6Color = input.color(title='', defval=color.green, inline='6')

ma7Show = input.bool(title='', defval=true, inline='7')
ma7Type = input.string(title='MA7', defval='Sma', inline='7', options=['Sma', 'Ema', 'VWma', 'Wma', 'Rma', 'Hull', 'Smma'])
ma7Length = input.int(title='', defval=100, inline='7')
ma7Source = input.source(title='', defval=close, inline='7')
ma7Color = input.color(title='', defval=color.blue, inline='7')

ma8Show = input.bool(title='', defval=true, inline='8')
ma8Type = input.string(title='MA8', defval='Sma', inline='8', options=['Sma', 'Ema', 'VWma', 'Wma', 'Rma', 'Hull', 'Smma'])
ma8Length = input.int(title='', defval=200, inline='8')
ma8Source = input.source(title='', defval=close, inline='8')
ma8Color = input.color(title='', defval=color.navy, inline='8')

ma9Show = input.bool(title='', defval=true, inline='9')
ma9Type = input.string(title='MA9', defval='VWma', inline='9', options=['Sma', 'Ema', 'VWma', 'Wma', 'Rma', 'Hull', 'Smma'])
ma9Length = input.int(title='', defval=200, inline='9')
ma9Source = input.source(title='', defval=close, inline='9')
ma9Color = input.color(title='', defval=color.purple, inline='9')

var grpLw = 'Line Width'  // LINE WIDTH SECTION

hullLw = input.int(title='  hull', defval=2, minval=1, inline='0', group=grpLw)
smaLw = input.int(title='sma', defval=1, minval=1, inline='0', group=grpLw)
emaLw = input.int(title=' ema', defval=2, minval=1, inline='0', group=grpLw)
vwmaLw = input.int(title='vWma', defval=2, minval=1, inline='0', group=grpLw)
rmaLw = input.int(title='rma', defval=2, minval=1, inline='0', group=grpLw)
wmaLw = input.int(title='wma', defval=2, minval=1, inline='0', group=grpLw)
smmaLw = input.int(title='Smma', defval=1, minval=1, inline='0', group=grpLw)


smma(_src, _length) => //{
	float _smma = 0.0
	_smma := na(_smma[1]) ? ta.sma(_src, _length) : (_smma[1] * (_length - 1) + _src) / _length
	_smma
//}

maSelect(_src, _length, _type) =>  //{
    float _ma = _type == 'Sma' ? ta.sma(_src, _length) : _type == 'Ema' ? ta.ema(_src, _length) : _type == 'VWma' ? ta.vwma(_src, _length) : _type == 'Hull' ? 
     ta.hma(_src, _length) : _type == 'Wma' ? ta.wma(_src, _length) : _type == 'Rma' ? ta.rma(_src, _length) : _type == 'Smma' ? smma(_src, _length) : na
    _ma
//}

lwSelect(_type) =>  //{
    int _lineWidth = _type == 'Sma' ? smaLw : _type == 'Ema' ? emaLw : _type == 'VWma' ? vwmaLw : _type == 'Hull' ? hullLw : _type == 'Wma' ? wmaLw : _type == 'Rma' ? rmaLw :  _type == 'Smma' ? smmaLw : 1
    _lineWidth
//}

ma1 = maSelect(ma1Source, ma1Length, ma1Type)
ma2 = maSelect(ma2Source, ma2Length, ma2Type)
ma3 = maSelect(ma3Source, ma3Length, ma3Type)
ma4 = maSelect(ma4Source, ma4Length, ma4Type)
ma5 = maSelect(ma5Source, ma5Length, ma5Type)
ma6 = maSelect(ma6Source, ma6Length, ma6Type)
ma7 = maSelect(ma7Source, ma7Length, ma7Type)
ma8 = maSelect(ma8Source, ma8Length, ma8Type)
ma9 = maSelect(ma9Source, ma9Length, ma9Type)

plot(ma1Show ? ma1 : na, title='MA 1', color=ma1Color, linewidth=lwSelect(ma1Type))
plot(ma2Show ? ma2 : na, title='MA 2', color=ma2Color, linewidth=lwSelect(ma2Type))
plot(ma3Show ? ma3 : na, title='MA 3', color=ma3Color, linewidth=lwSelect(ma3Type))
plot(ma4Show ? ma4 : na, title='MA 4', color=ma4Color, linewidth=lwSelect(ma4Type))
plot(ma5Show ? ma5 : na, title='MA 5', color=ma5Color, linewidth=lwSelect(ma5Type))
plot(ma6Show ? ma6 : na, title='MA 6', color=ma6Color, linewidth=lwSelect(ma6Type))
plot(ma7Show ? ma7 : na, title='MA 7', color=ma7Color, linewidth=lwSelect(ma7Type))
plot(ma8Show ? ma8 : na, title='MA 8', color=ma8Color, linewidth=lwSelect(ma8Type))
plot(ma9Show ? ma9 : na, title='MA 9', color=ma9Color, linewidth=lwSelect(ma9Type))

// Thank You for reading my code ... hope you enjoyed or learned something :)

