+ Multi-timeframe Multiple Moving Average Lines
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ClassicScott

//This is a pretty simple script that plots lines for various moving averages (what I think are the most commonly used across all markets) of varying lengths of
//timeframes of the user's choosing. Timeframes range from 5 minutes up to one month, so regardless if you're a scalper or a swing trader there should be something
//here for you.

//There are 8 lines (that can be turned on/off individually), which may seem like a lot, but if you use two averages and want to display four different timeframes
//for each, you can do that. The nice thing is that because the lines start plotting from the current bar they won't clutter up the screen. And obviously having
//moving averages from different timeframes on your chart makes price action more difficult to read (I mean sure, you can make them invisible, but who wants to do
//that all the time).

//For each line there are two labels. One with the moving average type, and the other with its specific timeframe. I can't include the moving average length because
//it's not a string input. If anyone has a workaround for this, let me know, otherwise I would simply recommend setting different colors depending on the length,
//or if you only use one or two lenghts and one or two moving averages this shouldn't be an issue. I had to use two labels because for the label text I couldn't
//include more than one string input, this is why there is an input for the 'moving average type label distance.'' You will want to adjust this depending on if you
//are trading crypto, futures, or forex because in some cases there may still be label overlap.

//Pretty much everything else is self-explanatory.

//I've added alerts. I might need to modify them if I can, because it would be nice for them to state the name and timeframe of the moving average. But I think
//this will do for now.

//Enjoy!


//@version=5
indicator('+ Multi-timeframe Multiple Moving Average Lines', shorttitle='+ MTFMA Lines', overlay=true)
bar_index_duration = time - time[1]

////INPUTS FOR FIRST MOVING AVERAGE
//DISPLAY LINES AND LABELS?
onoff = input(defval=true, title='Display Line and Label?', group='Moving Average #1')


//LOOKBACK
i_ma1len = input.int(defval=9, title='Lookback', group='Moving Average #1')


//TYPE
i_ma1 = input.string(defval='EMA', options=['EMA', 'HMA', 'SMA', 'SMMA', 'VWMA', 'WMA'], title='Moving Average Type', group='Moving Average #1')
ma1 = i_ma1 == 'EMA' ? ta.ema(close, i_ma1len) : i_ma1 == 'HMA' ? ta.hma(close, i_ma1len) : i_ma1 == 'SMA' ? ta.sma(close, i_ma1len) : i_ma1 == 'SMMA' ? ta.rma(close, i_ma1len) : i_ma1 == 'VWMA' ? ta.vwma(close, i_ma1len) : i_ma1 == 'WMA' ? ta.wma(close, i_ma1len) : na

//RESOLUTION
i_ma1res = input.string(defval='1h', options=['5m', '12m', '15m', '30m', '1h', '4h', '8h', '12h', 'D', '3D', '4D', 'W', 'M'], title='Resolution', group='Moving Average #1')
ma1res = i_ma1res == '5m' ? '5' : i_ma1res == '12m' ? '12' : i_ma1res == '15m' ? '15' : i_ma1res == '30m' ? '30' : i_ma1res == '1h' ? '60' : i_ma1res == '4h' ? '240' : i_ma1res == '8h' ? '480' : i_ma1res == '12h' ? '720' : i_ma1res == 'D' ? 'D' : i_ma1res == '3D' ? '3D' : i_ma1res == '4D' ? '4D' : i_ma1res == 'W' ? 'W' : i_ma1res == 'M' ? 'M' : na 

//
line_color = input(color.purple, title='Line Color', group='Moving Average #1')
line_style = input.string(defval='Solid', options=['Dashed', 'Dotted', 'Solid'], title='Line Style', group='Moving Average #1')
line_width = input.int(defval=1, maxval=4, title="Line Width", group='Moving Average #1')
line_term = input(defval=25, title='Line Length', group='Moving Average #1')
label_term = input(defval=20, title='MA Type Label Distance', group='Moving Average #1')


//
_ma1_security = request.security(syminfo.tickerid, ma1res, ma1)


//LINES AND LABELS
x1 = time
y1 = _ma1_security
x2 = time + (line_term * bar_index_duration)
y2 = _ma1_security
xloc = xloc.bar_time
color = line_color
style = line_style == 'Dotted' ? line.style_dotted : line_style == 'Dashed' ? line.style_dashed : line_style == 'Solid' ? line.style_solid : na

ma1_line = onoff ? line.new(x1, y1, x2, y2, xloc, color=color, style=style, width=line_width) : na
line.delete(ma1_line[1])

ma1_reslabel = onoff ? label.new(x2, y1, xloc=xloc.bar_time, style=label.style_none, text=i_ma1res, textcolor=line_color) : na
label.delete(ma1_reslabel[1])

ma1_typelabel = onoff ? label.new(x1 + (label_term * bar_index_duration), y1, xloc=xloc.bar_time, style=label.style_none, text=i_ma1, textcolor=line_color) : na
label.delete(ma1_typelabel[1])

alertcondition(ta.cross(close, _ma1_security), 'Price Crossing MA 1', 'Price has crossed multi-timeframe moving average #1')

////////////////////////////////////////////////////////////////////////////////


////INPUTS FOR SECOND MOVING AVERAGE
//DISPLAY LINES AND LABELS?
onoff2 = input(defval=true, title='Display Line and Label?', group='Moving Average #2')

//LOOKBACK
i_ma2len = input.int(defval=9, title='Lookback', group='Moving Average #2')

//TYPE
i_ma2 = input.string(defval='EMA', options=['EMA', 'HMA', 'SMA', 'SMMA', 'VWMA', 'WMA'], title='Moving Average Type', group='Moving Average #2')
ma2 = i_ma2 == 'EMA' ? ta.ema(close, i_ma2len) : i_ma2 == 'HMA' ? ta.hma(close, i_ma2len) : i_ma2 == 'SMA' ? ta.sma(close, i_ma2len) : i_ma2 == 'SMMA' ? ta.rma(close, i_ma2len) : i_ma2 == 'VWMA' ? ta.vwma(close, i_ma2len) : i_ma2 == 'WMA' ? ta.wma(close, i_ma2len) : na

//RESOLUTION
i_ma2res = input.string(defval='4h', options=['5m', '12m', '15m', '30m', '1h', '4h', '8h', '12h', 'D', '3D', '4D', 'W', 'M'], title='Resolution', group='Moving Average #2')
ma2res = i_ma2res == '5m' ? '5' : i_ma2res == '12m' ? '12' : i_ma2res == '15m' ? '15' : i_ma2res == '30m' ? '30' : i_ma2res == '1h' ? '60' : i_ma2res == '4h' ? '240' : i_ma2res == '8h' ? '480' : i_ma2res == '12h' ? '720' : i_ma2res == 'D' ? 'D' : i_ma2res == '3D' ? '3D' : i_ma2res == '4D' ? '4D' : i_ma2res == 'W' ? 'W' : i_ma2res == 'M' ? 'M' : na 

//
line_color2 = input(color.purple, title='Line Color', group='Moving Average #2')
line_style2 = input.string(defval='Solid', options=['Dashed', 'Dotted', 'Solid'], title='Line Style', group='Moving Average #2')
line_width2 = input.int(defval=1, maxval=4, title="Line Width", group='Moving Average #2')
line_term2 = input(defval=25, title='Line Length', group='Moving Average #2')
label_term2 = input(defval=20, title='MA Type Label Distance', group='Moving Average #2')


//
_ma2_security = request.security(syminfo.tickerid, ma2res, ma2)


//LINES AND LABELS
x1_2 = time
y1_2 = _ma2_security
x2_2 = time + (line_term * bar_index_duration)
y2_2 = _ma2_security
xloc2 = xloc.bar_time
color2 = line_color2
style2 = line_style2 == 'Dotted' ? line.style_dotted : line_style2 == 'Dashed' ? line.style_dashed : line_style2 == 'Solid' ? line.style_solid : na


ma2_line = onoff2 ? line.new(x1_2, y1_2, x2_2, y2_2, xloc2, color=color2, style=style2, width=line_width2) : na
line.delete(ma2_line[1])

ma2_reslabel = onoff2 ? label.new(x2_2, y1_2, xloc=xloc.bar_time, style=label.style_none, text=i_ma2res, textcolor=line_color2) : na
label.delete(ma2_reslabel[1])

ma2_typelabel = onoff2 ? label.new(x1_2 + (label_term2 * bar_index_duration), y1_2, xloc=xloc.bar_time, style=label.style_none, text=i_ma2, textcolor=line_color2) : na
label.delete(ma2_typelabel[1])

alertcondition(ta.cross(close, _ma2_security), 'Price Crossing MA 2', 'Price has crossed multi-timeframe moving average #2.')


////////////////////////////////////////////////////////////////////////////////


////INPUTS FOR THIRD MOVING AVERAGE
//DISPLAY LINES AND LABELS?
onoff3 = input(defval=true, title='Display Line and Label?', group='Moving Average #3')

//LOOKBACK
i_ma3len = input.int(defval=9, title='Lookback', group='Moving Average #3')

//TYPE
i_ma3 = input.string(defval='EMA', options=['EMA', 'HMA', 'SMA', 'SMMA', 'VWMA', 'WMA'], title='Moving Average Type', group='Moving Average #3')
ma3 = i_ma3 == 'EMA' ? ta.ema(close, i_ma3len) : i_ma3 == 'HMA' ? ta.hma(close, i_ma3len) : i_ma3 == 'SMA' ? ta.sma(close, i_ma3len) : i_ma3 == 'SMMA' ? ta.rma(close, i_ma3len) : i_ma3 == 'VWMA' ? ta.vwma(close, i_ma3len) : i_ma3 == 'WMA' ? ta.wma(close, i_ma3len) : na

//RESOLUTION
i_ma3res = input.string(defval='8h', options=['5m', '12m', '15m', '30m', '1h', '4h', '8h', '12h', 'D', '3D', '4D', 'W', 'M'], title='Resolution', group='Moving Average #3')
ma3res = i_ma3res == '5m' ? '5' : i_ma3res == '12m' ? '12' : i_ma3res == '15m' ? '15' : i_ma3res == '30m' ? '30' : i_ma3res == '1h' ? '60' : i_ma3res == '4h' ? '240' : i_ma3res == '8h' ? '480' : i_ma3res == '12h' ? '720' : i_ma3res == 'D' ? 'D' : i_ma3res == '3D' ? '3D' : i_ma3res == '4D' ? '4D' : i_ma3res == 'W' ? 'W' : i_ma3res == 'M' ? 'M' : na 

//
line_color3 = input(color.purple, title='Line Color', group='Moving Average #3')
line_style3 = input.string(defval='Solid', options=['Dashed', 'Dotted', 'Solid'], title='Line Style', group='Moving Average #3')
line_width3 = input.int(defval=1, maxval=4, title="Line Width", group='Moving Average #3')
line_term3 = input(defval=25, title='Line Length', group='Moving Average #3')
label_term3 = input(defval=20, title='MA Type Label Distance', group='Moving Average #3')


//
_ma3_security = request.security(syminfo.tickerid, ma3res, ma3)


//LINES AND LABELS
x1_3 = time
y1_3 = _ma3_security
x2_3 = time + (line_term * bar_index_duration)
y2_3 = _ma3_security
xloc3 = xloc.bar_time
color3 = line_color3
style3 = line_style3 == 'Dotted' ? line.style_dotted : line_style3 == 'Dashed' ? line.style_dashed : line_style3 == 'Solid' ? line.style_solid : na


ma3_line = onoff3 ? line.new(x1_3, y1_3, x2_3, y2_3, xloc3, color=color3, style=style3, width=line_width3) : na
line.delete(ma3_line[1])

ma3_reslabel = onoff3 ? label.new(x2_3, y1_3, xloc=xloc.bar_time, style=label.style_none, text=i_ma3res, textcolor=line_color3) : na
label.delete(ma3_reslabel[1])

ma3_typelabel = onoff3 ? label.new(x1_3 + (label_term3 * bar_index_duration), y1_3, xloc=xloc.bar_time, style=label.style_none, text=i_ma3, textcolor=line_color3) : na
label.delete(ma3_typelabel[1])

alertcondition(ta.cross(close, _ma3_security), 'Price Crossing MA 3', 'Price has crossed multi-timeframe moving average #3.')


////////////////////////////////////////////////////////////////////////////////


////INPUTS FOR FOURTH MOVING AVERAGE
//DISPLAY LINES AND LABELS?
onoff4 = input(defval=true, title='Display Line and Label?', group='Moving Average #4')

//LOOKBACK
i_ma4len = input.int(defval=9, title='Lookback', group='Moving Average #4')

//TYPE
i_ma4 = input.string(defval='EMA', options=['EMA', 'HMA', 'SMA', 'SMMA', 'VWMA', 'WMA'], title='Moving Average Type', group='Moving Average #4')
ma4 = i_ma4 == 'EMA' ? ta.ema(close, i_ma4len) : i_ma4 == 'HMA' ? ta.hma(close, i_ma4len) : i_ma4 == 'SMA' ? ta.sma(close, i_ma4len) : i_ma4 == 'SMMA' ? ta.rma(close, i_ma4len) : i_ma4 == 'VWMA' ? ta.vwma(close, i_ma4len) : i_ma4 == 'WMA' ? ta.wma(close, i_ma4len) : na

//RESOLUTION
i_ma4res = input.string(defval='D', options=['5m', '12m', '15m', '30m', '1h', '4h', '8h', '12h', 'D', '3D', '4D', 'W', 'M'], title='Resolution', group='Moving Average #4')
ma4res = i_ma4res == '5m' ? '5' : i_ma4res == '12m' ? '12' : i_ma4res == '15m' ? '15' : i_ma4res == '30m' ? '30' : i_ma4res == '1h' ? '60' : i_ma4res == '4h' ? '240' : i_ma4res == '8h' ? '480' : i_ma4res == '12h' ? '720' : i_ma4res == 'D' ? 'D' : i_ma4res == '3D' ? '3D' : i_ma4res == '4D' ? '4D' : i_ma4res == 'W' ? 'W' : i_ma4res == 'M' ? 'M' : na 

//
line_color4 = input(color.purple, title='Line Color', group='Moving Average #4')
line_style4 = input.string(defval='Solid', options=['Dashed', 'Dotted', 'Solid'], title='Line Style', group='Moving Average #4')
line_width4 = input.int(defval=1, maxval=4, title="Line Width", group='Moving Average #4')
line_term4 = input(defval=25, title='Line Length', group='Moving Average #4')
label_term4 = input(defval=20, title='MA Type Label Distance', group='Moving Average #4')


//
_ma4_security = request.security(syminfo.tickerid, ma4res, ma4)


//LINES AND LABELS
x1_4 = time
y1_4 = _ma4_security
x2_4 = time + (line_term * bar_index_duration)
y2_4 = _ma4_security
xloc4 = xloc.bar_time
color4 = line_color4
style4 = line_style4 == 'Dotted' ? line.style_dotted : line_style4 == 'Dashed' ? line.style_dashed : line_style4 == 'Solid' ? line.style_solid : na


ma4_line = onoff4 ? line.new(x1_4, y1_4, x2_4, y2_4, xloc4, color=color4, style=style4, width=line_width4) : na
line.delete(ma4_line[1])

ma4_reslabel = onoff4 ? label.new(x2_4, y1_4, xloc=xloc.bar_time, style=label.style_none, text=i_ma4res, textcolor=line_color4) : na
label.delete(ma4_reslabel[1])

ma4_typelabel = onoff4 ? label.new(x1_4 + (label_term4 * bar_index_duration), y1_4, xloc=xloc.bar_time, style=label.style_none, text=i_ma4, textcolor=line_color4) : na
label.delete(ma4_typelabel[1])

alertcondition(ta.cross(close, _ma4_security), 'Price Crossing MA 4', 'Price has crossed multi-timeframe moving average #4.')


////////////////////////////////////////////////////////////////////////////////


////INPUTS FOR FIFTH MOVING AVERAGE
//DISPLAY LINES AND LABELS?
onoff5 = input(defval=true, title='Display Line and Label?', group='Moving Average #5')

//LOOKBACK
i_ma5len = input.int(defval=20, title='Lookback', group='Moving Average #5')

//TYPE
i_ma5 = input.string(defval='SMA', options=['EMA', 'HMA', 'SMA', 'SMMA', 'VWMA', 'WMA'], title='Moving Average Type', group='Moving Average #5')
ma5 = i_ma5 == 'EMA' ? ta.ema(close, i_ma5len) : i_ma5 == 'HMA' ? ta.hma(close, i_ma5len) : i_ma5 == 'SMA' ? ta.sma(close, i_ma5len) : i_ma5 == 'SMMA' ? ta.rma(close, i_ma5len) : i_ma5 == 'VWMA' ? ta.vwma(close, i_ma5len) : i_ma5 == 'WMA' ? ta.wma(close, i_ma5len) : na

//RESOLUTION
i_ma5res = input.string(defval='1h', options=['5m', '12m', '15m', '30m', '1h', '4h', '8h', '12h', 'D', '3D', '4D', 'W', 'M'], title='Resolution', group='Moving Average #5')
ma5res = i_ma5res == '5m' ? '5' : i_ma5res == '12m' ? '12' : i_ma5res == '15m' ? '15' : i_ma5res == '30m' ? '30' : i_ma5res == '1h' ? '60' : i_ma5res == '4h' ? '240' : i_ma5res == '8h' ? '480' : i_ma5res == '12h' ? '720' : i_ma5res == 'D' ? 'D' : i_ma5res == '3D' ? '3D' : i_ma5res == '4D' ? '4D' : i_ma5res == 'W' ? 'W' : i_ma5res == 'M' ? 'M' : na 

//
line_color5 = input(color.orange, title='Line Color', group='Moving Average #5')
line_style5 = input.string(defval='Solid', options=['Dashed', 'Dotted', 'Solid'], title='Line Style', group='Moving Average #5')
line_width5 = input.int(defval=1, maxval=4, title="Line Width", group='Moving Average #5')
line_term5 = input(defval=25, title='Line Length', group='Moving Average #5')
label_term5 = input(defval=20, title='MA Type Label Distance', group='Moving Average #5')


//
_ma5_security = request.security(syminfo.tickerid, ma5res, ma5)


//LINES AND LABELS
x1_5 = time
y1_5 = _ma5_security
x2_5 = time + (line_term * bar_index_duration)
y2_5 = _ma5_security
xloc5 = xloc.bar_time
color5 = line_color5
style5 = line_style5 == 'Dotted' ? line.style_dotted : line_style5 == 'Dashed' ? line.style_dashed : line_style5 == 'Solid' ? line.style_solid : na


ma5_line = onoff5 ? line.new(x1_5, y1_5, x2_5, y2_5, xloc5, color=color5, style=style5, width=line_width5) : na
line.delete(ma5_line[1])

ma5_reslabel = onoff5 ? label.new(x2_5, y1_5, xloc=xloc.bar_time, style=label.style_none, text=i_ma5res, textcolor=line_color5) : na
label.delete(ma5_reslabel[1])

ma5_typelabel = onoff5 ? label.new(x1_5 + (label_term5 * bar_index_duration), y1_5, xloc=xloc.bar_time, style=label.style_none, text=i_ma5, textcolor=line_color5) : na
label.delete(ma5_typelabel[1])

alertcondition(ta.cross(close, _ma5_security), 'Price Crossing MA 5', 'Price has crossed multi-timeframe moving average #5.')


////////////////////////////////////////////////////////////////////////////////


////INPUTS FOR SIXTH MOVING AVERAGE
//DISPLAY LINES AND LABELS?
onoff6 = input(defval=true, title='Display Line and Label?', group='Moving Average #6')

//LOOKBACK
i_ma6len = input.int(defval=20, title='Lookback', group='Moving Average #6')

//TYPE
i_ma6 = input.string(defval='SMA', options=['EMA', 'HMA', 'SMA', 'SMMA', 'VWMA', 'WMA'], title='Moving Average Type', group='Moving Average #6')
ma6 = i_ma6 == 'EMA' ? ta.ema(close, i_ma6len) : i_ma6 == 'HMA' ? ta.hma(close, i_ma6len) : i_ma6 == 'SMA' ? ta.sma(close, i_ma6len) : i_ma6 == 'SMMA' ? ta.rma(close, i_ma6len) : i_ma6 == 'VWMA' ? ta.vwma(close, i_ma6len) : i_ma6 == 'WMA' ? ta.wma(close, i_ma6len) : na

//RESOLUTION
i_ma6res = input.string(defval='4h', options=['5m', '12m', '15m', '30m', '1h', '4h', '8h', '12h', 'D', '3D', '4D', 'W', 'M'], title='Resolution', group='Moving Average #6')
ma6res = i_ma6res == '5m' ? '5' : i_ma6res == '12m' ? '12' : i_ma6res == '15m' ? '15' : i_ma6res == '30m' ? '30' : i_ma6res == '1h' ? '60' : i_ma6res == '4h' ? '240' : i_ma6res == '8h' ? '480' : i_ma6res == '12h' ? '720' : i_ma6res == 'D' ? 'D' : i_ma6res == '3D' ? '3D' : i_ma6res == '4D' ? '4D' : i_ma6res == 'W' ? 'W' : i_ma6res == 'M' ? 'M' : na 

//
line_color6 = input(color.orange, title='Line Color', group='Moving Average #6')
line_style6 = input.string(defval='Solid', options=['Dashed', 'Dotted', 'Solid'], title='Line Style', group='Moving Average #6')
line_width6 = input.int(defval=1, maxval=4, title="Line Width", group='Moving Average #6')
line_term6 = input(defval=25, title='Line Length', group='Moving Average #6')
label_term6 = input(defval=20, title='MA Type Label Distance', group='Moving Average #6')


//
_ma6_security = request.security(syminfo.tickerid, ma6res, ma6)


//LINES AND LABELS
x1_6 = time
y1_6 = _ma6_security
x2_6 = time + (line_term * bar_index_duration)
y2_6 = _ma6_security
xloc6 = xloc.bar_time
color6 = line_color6
style6 = line_style6 == 'Dotted' ? line.style_dotted : line_style6 == 'Dashed' ? line.style_dashed : line_style6 == 'Solid' ? line.style_solid : na


ma6_line = onoff6 ? line.new(x1_6, y1_6, x2_6, y2_6, xloc6, color=color6, style=style6, width=line_width6) : na
line.delete(ma6_line[1])

ma6_reslabel = onoff6 ? label.new(x2_6, y1_6, xloc=xloc.bar_time, style=label.style_none, text=i_ma6res, textcolor=line_color6) : na
label.delete(ma6_reslabel[1])

ma6_typelabel = onoff6 ? label.new(x1_6 + (label_term6 * bar_index_duration), y1_6, xloc=xloc.bar_time, style=label.style_none, text=i_ma6, textcolor=line_color6) : na
label.delete(ma6_typelabel[1])

alertcondition(ta.cross(close, _ma6_security), 'Price Crossing MA 6', 'Price has crossed multi-timeframe moving average #6.')


////////////////////////////////////////////////////////////////////////////////


////INPUTS FOR SEVENTH MOVING AVERAGE
//DISPLAY LINES AND LABELS?
onoff7 = input(defval=true, title='Display Line and Label?', group='Moving Average #7')

//LOOKBACK
i_ma7len = input.int(defval=20, title='Lookback', group='Moving Average #7')

//TYPE
i_ma7 = input.string(defval='SMA', options=['EMA', 'HMA', 'SMA', 'SMMA', 'VWMA', 'WMA'], title='Moving Average Type', group='Moving Average #7')
ma7 = i_ma7 == 'EMA' ? ta.ema(close, i_ma7len) : i_ma7 == 'HMA' ? ta.hma(close, i_ma7len) : i_ma7 == 'SMA' ? ta.sma(close, i_ma7len) : i_ma7 == 'SMMA' ? ta.rma(close, i_ma7len) : i_ma7 == 'VWMA' ? ta.vwma(close, i_ma7len) : i_ma7 == 'WMA' ? ta.wma(close, i_ma7len) : na

//RESOLUTION
i_ma7res = input.string(defval='8h', options=['5m', '12m', '15m', '30m', '1h', '4h', '8h', '12h', 'D', '3D', '4D', 'W', 'M'], title='Resolution', group='Moving Average #7')
ma7res = i_ma7res == '5m' ? '5' : i_ma7res == '12m' ? '12' : i_ma7res == '15m' ? '15' : i_ma7res == '30m' ? '30' : i_ma7res == '1h' ? '60' : i_ma7res == '4h' ? '240' : i_ma7res == '8h' ? '480' : i_ma7res == '12h' ? '720' : i_ma7res == 'D' ? 'D' : i_ma7res == '3D' ? '3D' : i_ma7res == '4D' ? '4D' : i_ma7res == 'W' ? 'W' : i_ma7res == 'M' ? 'M' : na 

//
line_color7 = input(color.orange, title='Line Color', group='Moving Average #7')
line_style7 = input.string(defval='Solid', options=['Dashed', 'Dotted', 'Solid'], title='Line Style', group='Moving Average #7')
line_width7 = input.int(defval=1, maxval=4, title="Line Width", group='Moving Average #7')
line_term7 = input(defval=25, title='Line Length', group='Moving Average #7')
label_term7 = input(defval=20, title='MA Type Label Distance', group='Moving Average #7')


//
_ma7_security = request.security(syminfo.tickerid, ma7res, ma7)


//LINES AND LABELS
x1_7 = time
y1_7 = _ma7_security
x2_7 = time + (line_term * bar_index_duration)
y2_7 = _ma7_security
xloc7 = xloc.bar_time
color7 = line_color7
style7 = line_style7 == 'Dotted' ? line.style_dotted : line_style7 == 'Dashed' ? line.style_dashed : line_style7 == 'Solid' ? line.style_solid : na


ma7_line = onoff7 ? line.new(x1_7, y1_7, x2_7, y2_7, xloc7, color=color7, style=style7, width=line_width7) : na
line.delete(ma7_line[1])

ma7_reslabel = onoff7 ? label.new(x2_7, y1_7, xloc=xloc.bar_time, style=label.style_none, text=i_ma7res, textcolor=line_color7) : na
label.delete(ma7_reslabel[1])

ma7_typelabel = onoff7 ? label.new(x1_7 + (label_term7 * bar_index_duration), y1_7, xloc=xloc.bar_time, style=label.style_none, text=i_ma7, textcolor=line_color7) : na
label.delete(ma7_typelabel[1])

alertcondition(ta.cross(close, _ma7_security), 'Price Crossing MA 7', 'Price has crossed multi-timeframe moving average #7.')


////////////////////////////////////////////////////////////////////////////////


////INPUTS FOR EIGHTH MOVING AVERAGE
//DISPLAY LINES AND LABELS?
onoff8 = input(defval=true, title='Display Line and Label?', group='Moving Average #8')

//LOOKBACK
i_ma8len = input.int(defval=20, title='Lookback', group='Moving Average #8')

//TYPE
i_ma8 = input.string(defval='SMA', options=['EMA', 'HMA', 'SMA', 'SMMA', 'VWMA', 'WMA'], title='Moving Average Type', group='Moving Average #8')
ma8 = i_ma8 == 'EMA' ? ta.ema(close, i_ma8len) : i_ma8 == 'HMA' ? ta.hma(close, i_ma8len) : i_ma8 == 'SMA' ? ta.sma(close, i_ma8len) : i_ma8 == 'SMMA' ? ta.rma(close, i_ma8len) : i_ma8 == 'VWMA' ? ta.vwma(close, i_ma8len) : i_ma8 == 'WMA' ? ta.wma(close, i_ma8len) : na

//RESOLUTION
i_ma8res = input.string(defval='D', options=['5m', '12m', '15m', '30m', '1h', '4h', '8h', '12h', 'D', '3D', '4D', 'W', 'M'], title='Resolution', group='Moving Average #8')
ma8res = i_ma8res == '5m' ? '5' : i_ma8res == '12m' ? '12' : i_ma8res == '15m' ? '15' : i_ma8res == '30m' ? '30' : i_ma8res == '1h' ? '60' : i_ma8res == '4h' ? '240' : i_ma8res == '8h' ? '480' : i_ma8res == '12h' ? '720' : i_ma8res == 'D' ? 'D' : i_ma8res == '3D' ? '3D' : i_ma8res == '4D' ? '4D' : i_ma8res == 'W' ? 'W' : i_ma8res == 'M' ? 'M' : na 

//
line_color8 = input(color.orange, title='Line Color', group='Moving Average #8')
line_style8 = input.string(defval='Solid', options=['Dashed', 'Dotted', 'Solid'], title='Line Style', group='Moving Average #8')
line_width8 = input.int(defval=1, maxval=4, title="Line Width", group='Moving Average #8')
line_term8 = input(defval=25, title='Line Length', group='Moving Average #8')
label_term8 = input(defval=20, title='MA Type Label Distance', group='Moving Average #8')


//
_ma8_security = request.security(syminfo.tickerid, ma8res, ma8)


//LINES AND LABELS
x1_8 = time
y1_8 = _ma8_security
x2_8 = time + (line_term * bar_index_duration)
y2_8 = _ma8_security
xloc8 = xloc.bar_time
color8 = line_color8
style8 = line_style8 == 'Dotted' ? line.style_dotted : line_style8 == 'Dashed' ? line.style_dashed : line_style8 == 'Solid' ? line.style_solid : na


ma8_line = onoff8 ? line.new(x1_8, y1_8, x2_8, y2_8, xloc8, color=color8, style=style8, width=line_width8) : na
line.delete(ma8_line[1])

ma8_reslabel = onoff8 ? label.new(x2_8, y1_8, xloc=xloc.bar_time, style=label.style_none, text=i_ma8res, textcolor=line_color8) : na
label.delete(ma8_reslabel[1])

ma8_typelabel = onoff8 ? label.new(x1_8 + (label_term8 * bar_index_duration), y1_8, xloc=xloc.bar_time, style=label.style_none, text=i_ma8, textcolor=line_color8) : na
label.delete(ma8_typelabel[1])

alertcondition(ta.cross(close, _ma8_security), 'Price Crossing MA 8', 'Price has crossed multi-timeframe moving average #8.')


////////////////////////////////////////////////////////////////////////////////


