[_ParkF]MA_Package
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ParkF

//@version=5
indicator("[_ParkF]MA_Package", overlay=true)

// Function
src = input.source(close, 'Source', group='_____Moving Average Setting')
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)

// Input
switch1 = input.bool(true, 'ON / OFF',                                                               group='_____MA1')
maType1 = input.string("SMA", title="MA Type", options=["SMA",  "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="_____MA1")
len_1   = input.int( 10, 'Length',                                                     inline='MA1', group='_____MA1')
col_1   = input.color(color.new(#ff0000, 0), '',                                       inline='MA1', group='_____MA1')
width1  = input.int(2, 'Width',                                                        inline='MA1', group='_____MA1')

switch2 = input.bool(true, 'ON / OFF',                                                               group='_____MA2')
maType2 = input.string("SMA", title="MA Type", options=["SMA",  "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="_____MA2")
len_2   = input.int( 20, 'Length',                                                     inline='MA2', group='_____MA2')
col_2   = input.color(color.new(#ff9800, 0), '',                                       inline='MA2', group='_____MA2')
width2  = input.int(2, 'Width',                                                        inline='MA2', group='_____MA2')

switch3 = input.bool(true, 'ON / OFF',                                                               group='_____MA3')
maType3 = input.string("SMA", title="MA Type", options=["SMA",  "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="_____MA3")
len_3   = input.int( 60, 'Length',                                                     inline='MA3', group='_____MA3')
col_3   = input.color(color.new(#ffe500, 0), '',                                       inline='MA3', group='_____MA3')
width3  = input.int(3, 'Width',                                                        inline='MA3', group='_____MA3')

switch4 = input.bool(true, 'ON / OFF',                                                               group='_____MA4')
maType4 = input.string("SMA", title="MA Type", options=["SMA",  "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="_____MA4")
len_4   = input.int(100, 'Length',                                                     inline='MA4', group='_____MA4')
col_4   = input.color(color.new(#4caf50, 0), '',                                       inline='MA4', group='_____MA4')
width4  = input.int(2, 'Width',                                                        inline='MA4', group='_____MA4')

switch5 = input.bool(true, 'ON / OFF',                                                               group='_____MA5')
maType5 = input.string("SMA", title="MA Type", options=["SMA",  "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="_____MA5")
len_5   = input.int(200, 'Length',                                                     inline='MA5', group='_____MA5')
col_5   = input.color(color.new(#2962ff, 0), '',                                       inline='MA5', group='_____MA5')
width5  = input.int(2, 'Width',                                                        inline='MA5', group='_____MA5')

switch6 = input.bool(true, 'ON / OFF',                                                               group='_____MA6')
maType6 = input.string("SMA", title="MA Type", options=["SMA",  "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="_____MA6")
len_6   = input.int(300, 'Length',                                                     inline='MA6', group='_____MA6')
col_6   = input.color(color.new(#9c27b0, 0), '',                                       inline='MA6', group='_____MA6')
width6  = input.int(2, 'Width',                                                        inline='MA6', group='_____MA6')

// Get Moving Average
ma1 = ma(src, len_1, maType1)
ma2 = ma(src, len_2, maType2)
ma3 = ma(src, len_3, maType3)
ma4 = ma(src, len_4, maType4)
ma5 = ma(src, len_5, maType5)
ma6 = ma(src, len_6, maType6)

// Plot
plot(switch1 ? ma1 : na,   'MA(5)', color=col_1, linewidth=width1, editable=false)
plot(switch2 ? ma2 : na,  'MA(10)', color=col_2, linewidth=width2, editable=false)
plot(switch3 ? ma3 : na,  'MA(20)', color=col_3, linewidth=width3, editable=false)
plot(switch4 ? ma4 : na,  'MA(60)', color=col_4, linewidth=width4, editable=false)
plot(switch5 ? ma5 : na, 'MA(120)', color=col_5, linewidth=width5, editable=false)
plot(switch6 ? ma6 : na, 'MA(240)', color=col_6, linewidth=width6, editable=false)

// Prdictive Monvig Average
PreMA_width = input(2, 'Width', group='_____Predictv MA')
// Function
tf = timeframe.period
sym = syminfo.tickerid

// Predivtive MA1
p_ma1_1 = request.security(sym, tf, (ma(src, len_1-1, maType1) * (len_1 - 1) + src * 1) / len_1)
p_ma1_2 = request.security(sym, tf, (ma(src, len_1-2, maType1) * (len_1 - 2) + src * 2) / len_1)
p_ma1_3 = request.security(sym, tf, (ma(src, len_1-3, maType1) * (len_1 - 3) + src * 3) / len_1)
p_ma1_4 = request.security(sym, tf, (ma(src, len_1-4, maType1) * (len_1 - 4) + src * 4) / len_1)
plot(switch1 ? p_ma1_1 : na, title='pMA1_1', color=col_1, style=plot.style_circles, linewidth=PreMA_width, offset=+1, show_last=1, editable=false)  
plot(switch1 ? p_ma1_2 : na, title='pMA1_2', color=col_1, style=plot.style_circles, linewidth=PreMA_width, offset=+2, show_last=1, editable=false)  
plot(switch1 ? p_ma1_3 : na, title='pMA1-3', color=col_1, style=plot.style_circles, linewidth=PreMA_width, offset=+3, show_last=1, editable=false) 
plot(switch1 ? p_ma1_4 : na, title='pMA1-4', color=col_1, style=plot.style_circles, linewidth=PreMA_width, offset=+4, show_last=1, editable=false) 

// Predivtive MA2
p_ma2_1 = request.security(sym, tf, (ma(src, len_2-1, maType2) * (len_2 - 1) + src * 1) / len_2)
p_ma2_2 = request.security(sym, tf, (ma(src, len_2-2, maType2) * (len_2 - 2) + src * 2) / len_2)
p_ma2_3 = request.security(sym, tf, (ma(src, len_2-3, maType2) * (len_2 - 3) + src * 3) / len_2)
p_ma2_4 = request.security(sym, tf, (ma(src, len_2-4, maType2) * (len_2 - 4) + src * 4) / len_2)
plot(switch2 ? p_ma2_1 : na, title='pMA2-1', color=col_2, style=plot.style_circles, linewidth=PreMA_width, offset=+1, show_last=1, editable=false)  
plot(switch2 ? p_ma2_2 : na, title='pMA2-2', color=col_2, style=plot.style_circles, linewidth=PreMA_width, offset=+2, show_last=1, editable=false)  
plot(switch2 ? p_ma2_3 : na, title='pMA2-3', color=col_2, style=plot.style_circles, linewidth=PreMA_width, offset=+3, show_last=1, editable=false) 
plot(switch2 ? p_ma2_4 : na, title='pMA2-4', color=col_2, style=plot.style_circles, linewidth=PreMA_width, offset=+4, show_last=1, editable=false) 

// Predivtive  MA3
p_ma3_1 = request.security(sym, tf, (ma(src, len_3-1, maType3) * (len_3 - 1) + src * 1) / len_3)
p_ma3_2 = request.security(sym, tf, (ma(src, len_3-2, maType3) * (len_3 - 2) + src * 2) / len_3)
p_ma3_3 = request.security(sym, tf, (ma(src, len_3-3, maType3) * (len_3 - 3) + src * 3) / len_3)
p_ma3_4 = request.security(sym, tf, (ma(src, len_3-4, maType3) * (len_3 - 4) + src * 4) / len_3)
plot(switch3 ? p_ma3_1 : na, title='pMA3-1', color=col_3, style=plot.style_circles, linewidth=PreMA_width, offset=+1, show_last=1, editable=false)  
plot(switch3 ? p_ma3_2 : na, title='pMA3-2', color=col_3, style=plot.style_circles, linewidth=PreMA_width, offset=+2, show_last=1, editable=false)  
plot(switch3 ? p_ma3_3 : na, title='pMA3-3', color=col_3, style=plot.style_circles, linewidth=PreMA_width, offset=+3, show_last=1, editable=false) 
plot(switch3 ? p_ma3_4 : na, title='pMA3-4', color=col_3, style=plot.style_circles, linewidth=PreMA_width, offset=+4, show_last=1, editable=false) 

// Predivtive MA4
p_ma4_1 = request.security(sym, tf, (ma(src, len_4-1, maType4) * (len_4 - 1) + src * 1) / len_4)
p_ma4_2 = request.security(sym, tf, (ma(src, len_4-2, maType4) * (len_4 - 2) + src * 2) / len_4)
p_ma4_3 = request.security(sym, tf, (ma(src, len_4-3, maType4) * (len_4 - 3) + src * 3) / len_4)
p_ma4_4 = request.security(sym, tf, (ma(src, len_4-4, maType4) * (len_4 - 4) + src * 4) / len_4)
plot(switch4 ? p_ma4_1 : na, title='pMA4-1', color=col_4, style=plot.style_circles, linewidth=PreMA_width, offset=+1, show_last=1, editable=false)  
plot(switch4 ? p_ma4_2 : na, title='pMA4-2', color=col_4, style=plot.style_circles, linewidth=PreMA_width, offset=+2, show_last=1, editable=false)  
plot(switch4 ? p_ma4_3 : na, title='pMA4-3', color=col_4, style=plot.style_circles, linewidth=PreMA_width, offset=+3, show_last=1, editable=false) 
plot(switch4 ? p_ma4_4 : na, title='pMA4-4', color=col_4, style=plot.style_circles, linewidth=PreMA_width, offset=+4, show_last=1, editable=false) 

// Predivtive  MA5
p_ma5_1 = request.security(sym, tf, (ma(src, len_5-1, maType5) * (len_5 - 1) + src * 1) / len_5)
p_ma5_2 = request.security(sym, tf, (ma(src, len_5-2, maType5) * (len_5 - 2) + src * 2) / len_5)
p_ma5_3 = request.security(sym, tf, (ma(src, len_5-3, maType5) * (len_5 - 3) + src * 3) / len_5)
p_ma5_4 = request.security(sym, tf, (ma(src, len_5-4, maType5) * (len_5 - 4) + src * 4) / len_5)
plot(switch5 ? p_ma5_1 : na, title='pMA5-1', color=col_5, style=plot.style_circles, linewidth=PreMA_width, offset=+1, show_last=1, editable=false)  
plot(switch5 ? p_ma5_2 : na, title='pMA5-2', color=col_5, style=plot.style_circles, linewidth=PreMA_width, offset=+2, show_last=1, editable=false)  
plot(switch5 ? p_ma5_3 : na, title='pMA5-3', color=col_5, style=plot.style_circles, linewidth=PreMA_width, offset=+3, show_last=1, editable=false) 
plot(switch5 ? p_ma5_4 : na, title='pMA5-4', color=col_5, style=plot.style_circles, linewidth=PreMA_width, offset=+4, show_last=1, editable=false) 

// Predivtive MA6
p_ma6_1 = request.security(sym, tf, (ma(src, len_6-1, maType6) * (len_6 - 1) + src * 1) / len_6)
p_ma6_2 = request.security(sym, tf, (ma(src, len_6-2, maType6) * (len_6 - 2) + src * 2) / len_6)
p_ma6_3 = request.security(sym, tf, (ma(src, len_6-3, maType6) * (len_6 - 3) + src * 3) / len_6)
p_ma6_4 = request.security(sym, tf, (ma(src, len_6-4, maType6) * (len_6 - 4) + src * 4) / len_6)
plot(switch6 ? p_ma6_1 : na, title='pMA6-1', color=col_6, style=plot.style_circles, linewidth=PreMA_width, offset=+1, show_last=1, editable=false)  
plot(switch6 ? p_ma6_2 : na, title='pMA6-2', color=col_6, style=plot.style_circles, linewidth=PreMA_width, offset=+2, show_last=1, editable=false)  
plot(switch6 ? p_ma6_3 : na, title='pMA6-3', color=col_6, style=plot.style_circles, linewidth=PreMA_width, offset=+3, show_last=1, editable=false) 
plot(switch6 ? p_ma6_4 : na, title='pMA6-4', color=col_6, style=plot.style_circles, linewidth=PreMA_width, offset=+4, show_last=1, editable=false) 
