//@version=5
strategy("EMA Kesişim Stratejisi TP/SL", overlay=true, default_qty_type=strategy.cash, default_qty_value=5000, initial_capital=2500, commission_type=strategy.commission.percent, commission_value=0.04)
// ===== İŞLEM TİPİ KONTROLLERİ =====
enableLong = input.bool(true, "Long İşlemleri Aktif", group="İşlem Ayarları")
enableShort = input.bool(true, "Short İşlemleri Aktif", group="İşlem Ayarları")
// ===== MANUEL BAŞLANGIÇ TARİHİ =====
startYear = input.int(2025, "Başlangıç Yılı", minval=2000, maxval=2100, group="Tarih Ayarları")
startMonth = input.int(1, "Başlangıç Ayı", minval=1, maxval=12, group="Tarih Ayarları")
startDay = input.int(1, "Başlangıç Günü", minval=1, maxval=31, group="Tarih Ayarları")
startTime = timestamp(startYear, startMonth, startDay, 0, 0)
// Tarih kontrol fonksiyonu
isWithinDateRange() =>
time >= startTime
// Başlangıç fiyatı hesaplama
var float startDatePrice = na
var bool startPriceSet = false
if not startPriceSet and time >= startTime
startDatePrice := close
startPriceSet := true
// Inputs
ema1_len = input.int(13, "EMA 1 Uzunluğu", minval=1, group="EMA Ayarları")
ema2_len = input.int(34, "EMA 2 Uzunluğu", minval=1, group="EMA Ayarları")
tp_percent = input.float(1.0, "Take Profit %", minval=0.1, step=0.1, group="Risk Ayarları") / 100
sl_percent = input.float(0.5, "Stop Loss %", minval=0.1, step=0.1, group="Risk Ayarları") / 100
// Calculate EMAs
ema1 = ta.ema(close, ema1_len)
ema2 = ta.ema(close, ema2_len)
// Crossover detection
bullish = ta.crossover(ema1, ema2)
bearish = ta.crossunder(ema1, ema2)
// Calculate TP/SL levels
var float long_tp = na
var float long_sl = na
var float short_tp = na
var float short_sl = na
if bullish and enableLong
long_tp := close * (1 + tp_percent)
long_sl := close * (1 - sl_percent)
short_tp := na
short_sl := na
if bearish and enableShort
short_tp := close * (1 - tp_percent)
short_sl := close * (1 + sl_percent)
long_tp := na
long_sl := na
// Strategy entries and exits
if bullish and isWithinDateRange() and enableLong
strategy.entry("Long", strategy.long)
strategy.exit("Long Exit", "Long", limit=long_tp, stop=long_sl)
if bearish and isWithinDateRange() and enableShort
strategy.entry("Short", strategy.short)
strategy.exit("Short Exit", "Short", limit=short_tp, stop=short_sl)
// Plot EMAs
plot(ema1, "EMA 1", color=color.new(color.blue, 0))
plot(ema2, "EMA 2", color=color.new(color.red, 0))
// Plot signals and levels
plotshape(bullish and isWithinDateRange() and enableLong, "Bullish", shape.triangleup, location.belowbar, color.green, size=size.small)
plotshape(bearish and isWithinDateRange() and enableShort, "Bearish", shape.triangledown, location.abovebar, color.red, size=size.small)
plot(enableLong ? long_tp : na, "Long TP", style=plot.style_linebr, color=color.green, linewidth=2)
plot(enableLong ? long_sl : na, "Long SL", style=plot.style_linebr, color=color.red, linewidth=2)
plot(enableShort ? short_tp : na, "Short TP", style=plot.style_linebr, color=color.green, linewidth=2)
plot(enableShort ? short_sl : na, "Short SL", style=plot.style_linebr, color=color.red, linewidth=2)
// ===== PERFORMANS ÖLÇÜMLERİ =====
// Performans metrikleri hesaplama
totalTrades = strategy.closedtrades
winningTrades = strategy.closedtrades > 0 ? strategy.wintrades : 0
losingTrades = totalTrades - winningTrades
winRate = totalTrades > 0 ? (winningTrades / totalTrades) * 100 : 0
avgProfit = totalTrades > 0 ? strategy.netprofit / totalTrades : 0
profitFactor = strategy.grossloss != 0 ? strategy.grossprofit / strategy.grossloss : 1
currentPrice = close
priceChange = startDatePrice != 0 ? ((currentPrice - startDatePrice) / startDatePrice) * 100 : 0
// Format the manually entered start date as Gün/Ay/Yıl (DD/MM/YYYY)
startDateStr = str.tostring(startDay, "00") + "/" + str.tostring(startMonth, "00") + "/" + str.tostring(startYear)
// Performans tablosu - 6 satırlık
var table perfTable = table.new(position.top_right, 6, 6, border_width=1)
if barstate.islast
// Satır 0: Başlık bilgileri
table.cell(perfTable, 0, 0, "Strateji:", bgcolor=color.rgb(216, 247, 44), text_color=color.black)
table.cell(perfTable, 1, 0, "EMA Crossover", bgcolor=color.rgb(216, 247, 44))
table.cell(perfTable, 4, 0, "Başlangıç Tarihi:", bgcolor=color.rgb(216, 247, 44), text_color=color.black)
table.cell(perfTable, 5, 0, startDateStr, bgcolor=color.rgb(216, 247, 44))
// Satır 1: Fiyat bilgileri
table.cell(perfTable, 0, 1, "Başlangıç Fiyatı", bgcolor=color.rgb(103, 86, 179, 35), text_color=color.white)
table.cell(perfTable, 1, 1, str.tostring(startDatePrice, "#.##") + " TL", bgcolor=color.green, text_color=color.white)
table.cell(perfTable, 2, 1, "Güncel Fiyat", bgcolor=color.rgb(103, 86, 179, 35), text_color=color.white)
table.cell(perfTable, 3, 1, str.tostring(currentPrice, "#.##") + " TL", bgcolor=priceChange >= 0 ? color.green : color.red, text_color=color.white)
table.cell(perfTable, 4, 1, "Fiyat Değişimi", bgcolor=color.rgb(103, 86, 179, 35), text_color=color.white)
table.cell(perfTable, 5, 1, str.tostring(priceChange, "#.##") + "%", bgcolor=priceChange >= 0 ? color.green : color.red, text_color=color.white)
// Satır 2: Temel metrikler
table.cell(perfTable, 0, 2, "Toplam İşlem", bgcolor=color.rgb(103, 86, 179, 35), text_color=color.white)
table.cell(perfTable, 1, 2, str.tostring(totalTrades), bgcolor=color.green, text_color=color.white)
table.cell(perfTable, 2, 2, "Kazanan", bgcolor=color.rgb(103, 86, 179, 35), text_color=color.white)
table.cell(perfTable, 3, 2, str.tostring(winningTrades), bgcolor=color.green, text_color=color.white)
table.cell(perfTable, 4, 2, "Kaybeden", bgcolor=color.rgb(103, 86, 179, 35), text_color=color.white)
table.cell(perfTable, 5, 2, str.tostring(losingTrades), bgcolor=color.red, text_color=color.white)
// Satır 3: Başarı oranı
table.cell(perfTable, 0, 3, "Başarı Oranı", bgcolor=color.rgb(103, 86, 179, 35), text_color=color.white)
table.cell(perfTable, 1, 3, str.tostring(winRate, "#.##") + "%", bgcolor=winRate >= 50 ? color.green : color.red, text_color=color.white)
table.cell(perfTable, 2, 3, "Kar Faktörü", bgcolor=color.rgb(103, 86, 179, 35), text_color=color.white)
table.cell(perfTable, 3, 3, str.tostring(profitFactor, "#.##"), bgcolor=profitFactor >= 1 ? color.green : color.red, text_color=color.white)
table.cell(perfTable, 4, 3, "Ort. Kar", bgcolor=color.rgb(103, 86, 179, 35), text_color=color.white)
table.cell(perfTable, 5, 3, str.tostring(avgProfit, "#.##"), bgcolor=avgProfit >= 0 ? color.green : color.red, text_color=color.white)
// Satır 4: Kar istatistikleri
table.cell(perfTable, 0, 4, "Net Kar", bgcolor=color.rgb(17, 214, 221, 35), text_color=color.black)
table.cell(perfTable, 1, 4, str.tostring(strategy.netprofit, "#.##"), bgcolor=strategy.netprofit >= 0 ? color.green : color.red, text_color=color.white)
table.cell(perfTable, 2, 4, "Brüt Kar", bgcolor=color.rgb(103, 86, 179, 35), text_color=color.white)
table.cell(perfTable, 3, 4, str.tostring(strategy.grossprofit, "#.##"), bgcolor=color.green, text_color=color.white)
table.cell(perfTable, 4, 4, "Brüt Zarar", bgcolor=color.rgb(103, 86, 179, 35), text_color=color.white)
table.cell(perfTable, 5, 4, str.tostring(strategy.grossloss, "#.##"), bgcolor=color.red, text_color=color.white)
Bu kod, TradingView platformu için Pine Script dilinde yazılmış EMA Kesişim Stratejisi adlı otomatik bir alım-satım robotudur. İşlevleri şunlardır:
EMA Kesişim Sinyalleri: 13 periyotluk EMA ile 34 periyotluk EMA'nın kesişimlerini kullanır (EMA değerleri değiştirilebilir)
Alış Sinyali: Kısa EMA, uzun EMA'nın üzerine çıktığında (bullish crossover)
Satış Sinyali: Kısa EMA, uzun EMA'nın altına düştüğünde (bearish crossover)
Take Profit (TP): Varsayılan %1 kar alma seviyesi
Stop Loss (SL): Varsayılan %0.5 zararı kesme seviyesi
Her iki değer kullanıcı tarafından ayarlanabilir
Manuel başlangıç tarihi seçimi (yıl/ay/gün)
Sadece belirtilen tarihten sonra işlem yapar
Uzun (long) ve kısa (short) işlemler ayrı ayrı aktif/pasif edilebilir
EMA periyotları değiştirilebilir
EMA çizgileri grafik üzerinde gösterilir
Alış/satış sinyalleri üçgen işaretlerle belirtilir
TP/SL seviyeleri grafikte çizilir
Sağ üst köşede 5 satırlık detaylı bir performans tablosu gösterir:
Temel Bilgiler: Başlangıç tarihi, strateji adı
Fiyat Bilgileri: Başlangıç fiyatı, güncel fiyat, değişim yüzdesi
İşlem İstatistikleri: Toplam işlem sayısı, kazanan/kaybeden işlemler
Başarı Metrikleri: Başarı oranı, kar faktörü, ortalama kar
Kar/Zarar: Net kar, brüt kar, brüt zarar
Bu strateji, trend takip amaçlıdır. EMA kesişimleri trend değişimlerini erken tespit etmeye çalışır ve otomatik olarak pozisyon alıp çıkış yapar. Performans tablosu sayesinde stratejinin ne kadar etkili olduğu gerçek zamanlı olarak görülebilir.