//@version=5
strategy("EMA Trend Takip Stratejisi", overlay=true, initial_capital=10000, default_qty_value=100, default_qty_type=strategy.percent_of_equity, commission_value=0.04)
// EMA FİLTRESİ & STOP
// ────────────────────────────────────────
group_ema = "EMA FİLTRESİ & STOP AYARLARI"
useEmaFilter = input.bool(true, "EMA filtresini kullan?", group=group_ema)
emaPeriod = input.int(200, "EMA periyodu", minval=1, group=group_ema)
emaSource = input.source(close, "EMA kaynağı", group=group_ema)
group_tp = "TAKE PROFIT AYARLARI"
useTakeProfit = input.bool(true, "Take Profit kullan?", group=group_tp)
tpType = input.string("%", "TP tipi", options=["Sabit", "%", "ATR"], group=group_tp)
tpValue = input.float(5.0, "TP değeri", minval=0.1, step=0.1, group=group_tp)
group_stop = "STOP AYARLARI"
useEmaAsStop = input.bool(true, "EMA altı stop kullan?", group=group_stop)
useEmaPctStop = input.bool(true, "EMA % stop kullan?", group=group_stop)
emaPctStopValue = input.float(3.0, "EMA'nın % altında stop", minval=0.1, maxval=20.0, step=0.1, group=group_stop)
// EMA hesaplama
ema = ta.ema(emaSource, emaPeriod)
// EMA altı % stop seviyesi
emaStopLevel = ema * (1 - emaPctStopValue / 100)
// Görselleştirme
emaPlot = plot(ema, "EMA", color=color.new(#2962FF, 0), linewidth=2)
stopPlot = plot(useEmaPctStop ? emaStopLevel : na, "EMA % Stop Seviyesi",
color=color.new(color.red, 50), linewidth=1)
// Take Profit seviyesi hesaplama
var float takeProfitLevel = na
if strategy.position_size == 0
takeProfitLevel := na
else if strategy.position_size > 0
if tpType == "Sabit"
takeProfitLevel := strategy.position_avg_price + tpValue
else if tpType == "%"
takeProfitLevel := strategy.position_avg_price * (1 + tpValue / 100)
else // ATR
atrValue = ta.atr(14)
takeProfitLevel := strategy.position_avg_price + (atrValue * tpValue)
// Take Profit seviyesini çiz
tpPlot = plot(useTakeProfit and strategy.position_size > 0 ? takeProfitLevel : na,
"Take Profit Seviyesi", color=color.new(color.green, 0), linewidth=1)
// TP seviyesinin yanına sadece TP değeri etiketi ekle
var label tpEmaLabel = na
if barstate.islastconfirmedhistory and useTakeProfit and strategy.position_size > 0
tpEmaLabel := label.new( x = bar_index + 50, y = takeProfitLevel, text = "TP (%" + str.tostring(tpValue, "#.##") + "): " + str.tostring(takeProfitLevel, "#.##"), color = color.new(color.green, 90), textcolor = color.white, style = label.style_label_left, yloc = yloc.price, size = size.large )
// AL KOŞULU: Fiyat EMA'nın üstünde ise
longCondition = close > ema and (not useEmaFilter or close > ema)
// Take Profit koşulu
takeProfitCondition = useTakeProfit and strategy.position_size > 0 and close >= takeProfitLevel
// Stop koşulları
stopCondition = false
if useEmaAsStop
stopCondition := close < ema
if useEmaPctStop and not stopCondition
stopCondition := close < emaStopLevel
// STRATEJİ GİRİŞ ve ÇIKIŞ KURALLARI
// Uzun pozisyon aç
if strategy.position_size == 0 and longCondition
strategy.entry("UZUN", strategy.long)
// Take Profit ile çık
if takeProfitCondition
strategy.close("UZUN", comment="TP: " + str.tostring(takeProfitLevel, "#.##"))
// Stop ile çık
if stopCondition and strategy.position_size > 0
stopReason = ""
if useEmaAsStop and close < ema
stopReason := "EMA Altı"
if useEmaPctStop and close < emaStopLevel
stopReason := "EMA % Stop"
strategy.close("UZUN", comment="STOP: " + stopReason)
// ================================
// HER ZAMAN GÖRÜNEN EMA LABELLARI
// ================================
// Fiyat ile EMA arasındaki mesafe label'ı
var label distanceLabel = na
if barstate.islastconfirmedhistory
distancePct = ((close - ema) / ema) * 100
distanceLabel := label.new(
x = bar_index,
y = high * 1.001,
text = "Fiyat/EMA: " + str.tostring(distancePct, "+#.##;-#.##") + "%",
color = distancePct > 0 ? color.new(color.green, 80) : color.new(color.red, 80),
textcolor = color.white,
style = label.style_label_lower_left,
yloc = yloc.price,
size = size.normal
)
// ================================
// EKRANIN SAĞINDA SABİT LABELLAR
// ================================
// Sağ tarafta sabit duran EMA bilgi label'ları
var label rightEmaLabel = na
if barstate.islastconfirmedhistory
rightEmaLabel := label.new(
x = bar_index + 50,
y = ema,
text = "EMA " + str.tostring(emaPeriod) + ": " + str.tostring(ema, "#.##"),
color = color.new(#2962FF, 90),
textcolor = color.white,
style = label.style_label_left,
yloc = yloc.price,
size = size.large
)
var label rightStopLabel = na
if barstate.islastconfirmedhistory and useEmaPctStop
rightStopLabel := label.new(
x = bar_index + 50,
y = emaStopLevel,
text = "STOP (%" + str.tostring(emaPctStopValue, "#.##") + "): " + str.tostring(emaStopLevel, "#.##"),
color = color.new(color.red, 90),
textcolor = color.white,
style = label.style_label_left,
yloc = yloc.price,
size = size.large
)
// Alert koşulları
alertcondition(longCondition and strategy.position_size == 0,
title="AL Sinyali", message="EMA üstü AL sinyali!")
alertcondition(stopCondition and strategy.position_size > 0,
title="STOP Sinyali", message="STOP sinyali!")
alertcondition(takeProfitCondition,
title="TP Sinyali", message="TAKE PROFIT hedefi!")
ANA AMACI
Fiyat belirlenen EMA'nın üzerindeyken alış, belirli koşullar oluştuğunda da satış yaparak trend takip etmek.
TEMEL İŞLEYİŞ
1. ALIM (UZUN POZİSYON) KOŞULU
Fiyat seçilen EMA'nın (varsayılan 200) üzerine çıktığında alış yapar
EMA filtresi isteğe bağlı olarak kapatılabiliyor
2. SATIM (ÇIKIŞ) KOŞULLARI
ÜÇ FARKLI ÇIKIŞ YÖNTEMİ:
A) Take Profit (Kar Al)
Sabit: Belirli bir pip/point değerinde kar al
Yüzde: Alış fiyatından belirli yüzde karda çıkış
ATR: Ortalama True Range'den hesaplanan dinamik seviye
B) EMA Altı Stop
Fiyat EMA'nın altına düştüğünde stop
C) EMA % Stop
EMA'nın belirli bir yüzde (örn: %3) altına düşünce stop
Örnek: EMA=100, stop seviyesi=97 (EMA'nın %3 altı)
GÖRSEL ÖZELLİKLER
EMA çizgisi grafik üzerinde mavi renkte
Stop seviyesi kırmızı çizgi
Take Profit seviyesi yeşil çizgi
Sağ tarafta sabit bilgiler:
EMA değeri
Stop seviyesi
Take Profit değeri (pozisyondayken)
Fiyat-EMA mesafesi label'ı (yüzde olarak)
AYARLANABİLİR PARAMETRELER
EMA periyodu (varsayılan 200)
EMA kaynağı (close, open, vs.)
Take Profit tipi ve değeri
Stop yöntemleri (EMA altı veya % stop)
Stop yüzdesi (varsayılan %3)
ALERT (UYARI) SİSTEMİ
Al sinyali
Stop sinyali
Take Profit sinyali
STRATEJİNİN MANTIĞI
Trendi yakalamak: Fiyat EMA üstündeyken trend yukarı yönlü kabul ediliyor
Risk yönetimi: Çoklu stop yöntemleri ile zararı sınırlama
Kar realizasyonu: Hedefli çıkışlarla karları sabitleme
KULLANIM ALANI
Uzun vadeli trend takibi
Swing trading