[_ParkF]ResponsiveMA
// 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]ResponsiveMA", overlay=true)

// RESPONSIVE MA
// input
group1 = '_____MOVING AVERAGE'
src = input.source(close, 'Source', group=group1)
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)
matype = input.string("SMA", title="MA Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA TYPE")

group2 = '_____RESPONSIVE MOVING AVERAGE'
tf_5 = input(25, '5m MA Length', group=group2)
tf_15 = input(25, '15m MA Length', group=group2)
tf_30 = input(25, '30m MA Length', group=group2)
tf_60 = input(60, '1H MA Length', group=group2)
tf_240 = input(100, '4H MA Length', group=group2)
tf_480 = input(60, '8H MA Length', group=group2)
tf_D = input(100, '1D MA Length', group=group2)
tf_W = input(25, '1W MA Length', group=group2)
default = input(100, 'Default MA', group=group2)

// get tf
tf = timeframe.period

// tf func
tf_len1 = switch tf 
    "5" => tf_5
    "15" => tf_15
    "30" => tf_30
    "60" => tf_60
    "240" => tf_240
    "480" => tf_480
    "D" => tf_D
    "W" => tf_W
    => default

// get ma
resp_ma = ma(src, tf_len1, matype)

// plot
plot(resp_ma, title='Responsive MA', style=plot.style_line, color=color.black, linewidth=2)