//@version=5
indicator(title="Multi-Timeframe EMA Crossover with Average", shorttitle="MTF EMA Cross Avg", overlay=true)
// Input parameters
ema1_length = input.int(20, title="EMA 1 Length")
ema2_length = input.int(50, title="EMA 2 Length")
// Function to get EMA from different timeframes
getEma(res, length) =>
request.security(syminfo.tickerid, res, ta.ema(close, length))
// Get EMAs from different timeframes
ema20_15m = getEma("15", ema1_length)
ema50_15m = getEma("15", ema2_length)
ema20_30m = getEma("30", ema1_length)
ema50_30m = getEma("30", ema2_length)
ema20_1h = getEma("60", ema1_length)
ema50_1h = getEma("60", ema2_length)
ema20_2h = getEma("120", ema1_length)
ema50_2h = getEma("120", ema2_length)
ema20_4h = getEma("240", ema1_length)
ema50_4h = getEma("240", ema2_length)
ema20_d = getEma("D", ema1_length)
ema50_d = getEma("D", ema2_length)
// Current timeframe EMAs
ema20 = ta.ema(close, ema1_length)
ema50 = ta.ema(close, ema2_length)
// Calculate averages for each timeframe
avg_15m = (ema20_15m + ema50_15m) / 2
avg_30m = (ema20_30m + ema50_30m) / 2
avg_1h = (ema20_1h + ema50_1h) / 2
avg_2h = (ema20_2h + ema50_2h) / 2
avg_4h = (ema20_4h + ema50_4h) / 2
avg_d = (ema20_d + ema50_d) / 2
// Calculate the average of all timeframe averages
multi_timeframe_avg = (avg_15m + avg_30m + avg_1h + avg_2h + avg_4h + avg_d) / 6
// Crossover conditions for current timeframe
golden_cross = ta.crossover(ema20, ema50)
death_cross = ta.crossunder(ema20, ema50)
// Price crossover conditions with MTF average
price_above_avg = ta.crossover(close, multi_timeframe_avg)
price_below_avg = ta.crossunder(close, multi_timeframe_avg)
// Plot current timeframe EMAs
plot(ema20, color=color.new(color.blue, 0), title="EMA 1", linewidth=2)
plot(ema50, color=color.new(color.red, 0), title="EMA 2", linewidth=2)
// Plot multi-timeframe average
plot(multi_timeframe_avg, color=color.new(color.purple, 0), title="MTF EMA Average", linewidth=3)
// Plot crossover signals
plotshape(golden_cross, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="Buy Signal")
plotshape(death_cross, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Sell Signal")
// Plot price vs MTF average signals
plotshape(price_above_avg, style=shape.labelup, location=location.belowbar, color=color.green, text="AL", textcolor=color.white, size=size.small, title="Price Above Avg")
plotshape(price_below_avg, style=shape.labeldown, location=location.abovebar, color=color.red, text="SAT", textcolor=color.white, size=size.small, title="Price Below Avg")
// Display info
var table infoTable = table.new(position.top_right, 3, 8)
if barstate.islast
table.cell(infoTable, 0, 0, "Timeframe", bgcolor=color.gray, text_color=color.white)
table.cell(infoTable, 1, 0, "EMA1", bgcolor=color.gray, text_color=color.white)
table.cell(infoTable, 2, 0, "EMA2", bgcolor=color.gray, text_color=color.white)
table.cell(infoTable, 0, 1, "15m", bgcolor=color.new(color.gray, 90))
table.cell(infoTable, 1, 1, str.tostring(ema20_15m, format.mintick), bgcolor=color.new(color.blue, 90))
table.cell(infoTable, 2, 1, str.tostring(ema50_15m, format.mintick), bgcolor=color.new(color.red, 90))
table.cell(infoTable, 0, 2, "30m", bgcolor=color.new(color.gray, 90))
table.cell(infoTable, 1, 2, str.tostring(ema20_30m, format.mintick), bgcolor=color.new(color.blue, 90))
table.cell(infoTable, 2, 2, str.tostring(ema50_30m, format.mintick), bgcolor=color.new(color.red, 90))
table.cell(infoTable, 0, 3, "1H", bgcolor=color.new(color.gray, 90))
table.cell(infoTable, 1, 3, str.tostring(ema20_1h, format.mintick), bgcolor=color.new(color.blue, 90))
table.cell(infoTable, 2, 3, str.tostring(ema50_1h, format.mintick), bgcolor=color.new(color.red, 90))
table.cell(infoTable, 0, 4, "2H", bgcolor=color.new(color.gray, 90))
table.cell(infoTable, 1, 4, str.tostring(ema20_2h, format.mintick), bgcolor=color.new(color.blue, 90))
table.cell(infoTable, 2, 4, str.tostring(ema50_2h, format.mintick), bgcolor=color.new(color.red, 90))
table.cell(infoTable, 0, 5, "4H", bgcolor=color.new(color.gray, 90))
table.cell(infoTable, 1, 5, str.tostring(ema20_4h, format.mintick), bgcolor=color.new(color.blue, 90))
table.cell(infoTable, 2, 5, str.tostring(ema50_4h, format.mintick), bgcolor=color.new(color.red, 90))
table.cell(infoTable, 0, 6, "Daily", bgcolor=color.new(color.gray, 90))
table.cell(infoTable, 1, 6, str.tostring(ema20_d, format.mintick), bgcolor=color.new(color.blue, 90))
table.cell(infoTable, 2, 6, str.tostring(ema50_d, format.mintick), bgcolor=color.new(color.red, 90))
table.cell(infoTable, 0, 7, "MTF Avg", bgcolor=color.new(color.gray, 90))
table.cell(infoTable, 1, 7, "", bgcolor=color.new(color.gray, 90))
table.cell(infoTable, 2, 7, str.tostring(multi_timeframe_avg, format.mintick), bgcolor=color.new(color.purple, 90))
Bu kod, çok zaman dilimli EMA kesişimlerini ve ortalama hesaplamalarını görselleştiren bir TradingView göstergesidir