Indicator: SMA/EMA (Multi timeframes)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © DojiEmoji

//@version=5
indicator('MA on Alternative Timeframe', shorttitle='MA - Alt. TF [KL]', overlay=true)

tf_1W = input.timeframe('1M', title='For 1-week chart, show MA of: ')
tf_1D = input.timeframe('1W', title='For 1-day chart, show MA of: ')
tf_60 = input.timeframe('D', title='For 1-hour chart, show MA of: ')
tf_default = input.timeframe('D', title='For others (Default)')

tf = timeframe.period                                                               // tf = timeframe of the viewed chart
tf_alt = tf == '1W' ? tf_1W : tf == 'D' ? tf_1D : tf == '60' ? tf_60 : tf_default   // alternative timeframe depends on 'tf'

type = input.string(defval='EMA', options=['EMA', 'SMA'], title='EMA/SMA')
len = input.int(defval=20, title='Moving Average Period', minval=1)
_data = type == 'EMA' ? ta.ema(close, len) : ta.sma(close, len)
data = request.security(syminfo.tickerid, tf_alt, _data)
plot(data, title='MA', color=color.new(color.orange, 50), linewidth=1, style=plot.style_line)
