// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ //@version=5 indicator(title='Multi Time Frame Moving Averages', shorttitle="MTF MAs", overlay=true) // ======= 🔹 P A R A M E T E R S 🔹 ======= src = input.source(close, title="Source") ma1_type = input.string(title="🟢 MA1 Type", defval="EMA", options=["SMA", "EMA", "WMA", "RMA", "HMA", "DEMA", "TEMA", "VWMA", "ALMA"]) ma1_len = input.int(50, title="🟢 MA1 Length", minval=1) res1 = input.timeframe(defval="", title="🟢 MA1 Time Frame") ma2_type = input.string(title="🔵 MA2 Type", defval="EMA", options=["SMA", "EMA", "WMA", "RMA", "HMA", "DEMA", "TEMA", "VWMA", "ALMA"]) ma2_len = input.int(100, title="🔵 MA2 Length", minval=1) res2 = input.timeframe(defval="", title="🔵 MA2 Time Frame") ma3_type = input.string(title="🟠 MA3 Type", defval="EMA", options=["SMA", "EMA", "WMA", "RMA", "HMA", "DEMA", "TEMA", "VWMA", "ALMA"]) ma3_len = input.int(100, title="🟠 MA3 Length", minval=1) res3 = input.timeframe(defval="", title="🟠 MA3 Time Frame") ma4_type = input.string(title="🟣 MA4 Type", defval="EMA", options=["SMA", "EMA", "WMA", "RMA", "HMA", "DEMA", "TEMA", "VWMA", "ALMA"]) ma4_len = input.int(200, title="🟣 MA4 Length", minval=1) res4 = input.timeframe(defval="", title="🟣 MA4 Time Frame") ma5_type = input.string(title="⚫ MA5 Type", defval="EMA", options=["SMA", "EMA", "WMA", "RMA", "HMA", "DEMA", "TEMA", "VWMA", "ALMA"]) ma5_len = input.int(34, title="⚫ MA5 Length", minval=1) res5 = input.timeframe(defval="", title="⚫ MA5 Time Frame") // ======= 🔹 M O V I N G A V E R A G E S 🔹 ======= alma_fn(src_, len_, offset_, sigma_) => // ALMA implementation (fallback) m = offset_ * (len_ - 1) s = len_ / sigma_ norm = 0.0 sum_ = 0.0 for i = 0 to len_ - 1 w = math.exp(-math.pow(i - m, 2) / (2 * s * s)) norm += w sum_ += src_[i] * w sum_ / norm ma(type_, len_, src_) => if type_ == "SMA" ta.sma(src_, len_) else if type_ == "EMA" ta.ema(src_, len_) else if type_ == "WMA" ta.wma(src_, len_) else if type_ == "RMA" ta.rma(src_, len_) else if type_ == "HMA" ta.hma(src_, len_) else if type_ == "DEMA" e = ta.ema(src_, len_) 2 * e - ta.ema(e, len_) else if type_ == "TEMA" e = ta.ema(src_, len_) 3 * (e - ta.ema(e, len_)) + ta.ema(ta.ema(e, len_), len_) else if type_ == "VWMA" ta.vwma(src_, len_) else // ALMA alma_fn(src_, len_, 6.0, 0.85) // ======= 🔹 TIMEFRAME NORMALIZATION & REQUESTS 🔹 ======= tf1 = res1 == "" ? timeframe.period : res1 tf2 = res2 == "" ? timeframe.period : res2 tf3 = res3 == "" ? timeframe.period : res3 tf4 = res4 == "" ? timeframe.period : res4 tf5 = res5 == "" ? timeframe.period : res5 MA1 = request.security(syminfo.tickerid, tf1, ma(ma1_type, ma1_len, src), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off) MA2 = request.security(syminfo.tickerid, tf2, ma(ma2_type, ma2_len, src), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off) MA3 = request.security(syminfo.tickerid, tf3, ma(ma3_type, ma3_len, src), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off) MA4 = request.security(syminfo.tickerid, tf4, ma(ma4_type, ma4_len, src), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off) MA5 = request.security(syminfo.tickerid, tf5, ma(ma5_type, ma5_len, src), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off) // ======= 🔹 P L O T T I N G 🔹 ======= up1 = color.new(#58D68D, 0) dn1 = color.new(#1D8348, 0) up2 = color.new(#3498DB, 0) dn2 = color.new(#21618C, 0) up3 = color.new(#E74C3C, 0) dn3 = color.new(#7B241C, 0) up4 = color.new(#9B59B6, 0) dn4 = color.new(#6C3483, 0) up5 = color.new(#34495E, 0) dn5 = color.new(#17202A, 0) plot_color1 = MA1 >= MA1[1] ? up1 : dn1 plot_color2 = MA2 >= MA2[1] ? up2 : dn2 plot_color3 = MA3 >= MA3[1] ? up3 : dn3 plot_color4 = MA4 >= MA4[1] ? up4 : dn4 plot_color5 = MA5 >= MA5[1] ? up5 : dn5 plot(MA1, color=plot_color1, linewidth=2, title="Moving Average 1") plot(MA2, color=plot_color2, linewidth=2, title="Moving Average 2") plot(MA3, color=plot_color3, linewidth=3, title="Moving Average 3") plot(MA4, color=plot_color4, linewidth=2, title="Moving Average 4") plot(MA5, color=plot_color5, linewidth=1, title="Moving Average 5")