OPEN-SOURCE SCRIPT

Orta Vadeli Trend Sürme Stratejisi

106
//version=5
strategy("Orta Vadeli Trend Sürme Stratejisi", overlay=true, initial_capital=100000, default_qty_type=strategy.percent_of_equity, default_qty_value=1, commission_type=strategy.commission.percent, commission_value=0.1, calc_on_order_fills=true, calc_on_every_tick=true)

// *****************************************************************************
// 1. İşlem Dönemi: Son 6 Ay
// timenow milisaniye cinsinden güncel zamanı verir. 6 ay ≈ 15778800000 ms (ortalama 6x30.44 gün)
sixMonthsAgo = timenow - 15778800000
allowedTrade = time >= sixMonthsAgo // Sadece son 6 ay içindeki barlarda işlem yap

// *****************************************************************************
// 2. Teknik Göstergeler ve Parametre Ayarları

// RSI Ayarları
rsiLength = input.int(14, "RSI Periyodu")
rsiOverbought = input.int(70, "RSI Aşırı Alım Eşiği")
rsiOversold = input.int(30, "RSI Aşırı Satım Eşiği")
rsiValue = ta.rsi(close, rsiLength)

// MACD Ayarları
macdFast = input.int(12, "MACD Hızlı EMA")
macdSlow = input.int(26, "MACD Yavaş EMA")
macdSignal = input.int(9, "MACD Sinyal Periyodu")
[macdLine, signalLine, histLine] = ta.macd(close, macdFast, macdSlow, macdSignal)

// Bollinger Bantları
bbLength = input.int(20, "Bollinger Periyodu")
bbStdDev = input.float(2.0, "Bollinger Standart Sapma")
bbBasis = ta.sma(close, bbLength)
bbDev = bbStdDev * ta.stdev(close, bbLength)
upperBB = bbBasis + bbDev
lowerBB = bbBasis - bbDev

// Hareketli Ortalamalar (EMA) – Trendin takibi için
emaShort = ta.ema(close, 20)
emaLong = ta.ema(close, 50)

// Çok Zamanlı Trend Analizi: Haftalık ve Aylık EMA (20 periyot)
emaWeekly = request.security(syminfo.tickerid, "W", ta.ema(close, 20))
emaMonthly = request.security(syminfo.tickerid, "M", ta.ema(close, 20))

// ADX (Trend Gücü) - adxSmoothing parametresi eklenmiştir.
adxPeriod = input.int(14, "ADX Periyodu")
adxSmoothing = input.int(14, "ADX Smoothing Periyodu")
adxThreshold = input.int(25, "ADX Eşik Değeri")
[plusDI, minusDI, adxValue] = ta.dmi(adxPeriod, adxSmoothing)

// Parabolic SAR (Trend değişim noktası tespiti)
psarStart = input.float(0.02, "PSAR Başlangıç")
psarIncrement = input.float(0.02, "PSAR Artış")
psarMax = input.float(0.2, "PSAR Maksimum")
psarValue = ta.sar(psarStart, psarIncrement, psarMax)

// Stochastic Osilatör
stochKLength = input.int(14, "Stochastic %K Periyodu")
stochDLength = input.int(3, "Stochastic %D Periyodu")
stochK = ta.stoch(close, high, low, stochKLength)
stochD = ta.sma(stochK, stochDLength)

// *****************************************************************************
// 3. Piyasa Trend Analizi
// Genel trend, günlük, haftalık ve aylık EMA değerleri üzerinden yorumlanır.
trendUp = (close > emaShort) and (close > emaLong) and (close > emaWeekly) and (close > emaMonthly)
trendDown = (close < emaShort) and (close < emaLong) and (close < emaWeekly) and (close < emaMonthly)

// *****************************************************************************
// 4. Giriş ve Çıkış Sinyalleri
// Alım: Yukarı yönlü trend, MACD’nin yukarı kesişimi, ADX’in güçlü trend sinyali ve fiyatın PSAR’ın üzerinde oluşması
// Satım: Aşağı yönlü trend, MACD’nin aşağı kesişimi, ADX’in güçlü trend sinyali ve fiyatın PSAR’ın altında oluşması

longCondition = allowedTrade and trendUp and ta.crossover(macdLine, signalLine) and (adxValue > adxThreshold) and (rsiValue < rsiOverbought) and (close > psarValue)
shortCondition = allowedTrade and trendDown and ta.crossunder(macdLine, signalLine) and (adxValue > adxThreshold) and (rsiValue > rsiOversold) and (close < psarValue)

// *****************************************************************************
// 5. Risk Yönetimi ve Pozisyon Büyüklüğü
// ATR tabanlı stop loss ve take profit
atrPeriod = input.int(14, "ATR Periyodu")
atrMultiplierSL = input.float(2.0, "ATR Stop Loss Çarpanı")
atrMultiplierTP = input.float(3.0, "ATR Take Profit Çarpanı")
atrValue = ta.atr(atrPeriod)

// İşlem girişlerinde, pozisyon açıldıktan sonra otomatik olarak stop loss ve take profit seviyeleri belirlenir.
if (longCondition)
strategy.entry("Long", strategy.long)
strategy.exit("Long Exit", "Long", stop = close - atrMultiplierSL * atrValue, limit = close + atrMultiplierTP * atrValue)

if (shortCondition)
strategy.entry("Short", strategy.short)
strategy.exit("Short Exit", "Short", stop = close + atrMultiplierSL * atrValue, limit = close - atrMultiplierTP * atrValue)

// *****************************************************************************
// 6. Grafiksel Gösterimler ve Raporlama

plot(emaShort, color=color.blue, title="EMA 20")
plot(emaLong, color=color.orange, title="EMA 50")
plot(psarValue, style=plot.style_circles, color=color.red, title="Parabolic SAR")
plot(bbBasis, color=color.gray, title="BB Temel (SMA)")
plot(upperBB, color=color.green, title="BB Üst Bant")
plot(lowerBB, color=color.green, title="BB Alt Bant")

// *****************************************************************************
// 7. Notlar ve Açıklamalar
// - Bu strateji, son 6 ayı kapsayacak şekilde filtreleme yapmaktadır.
// - Giriş/çıkış sinyalleri, trendin güçlü olduğu durumları hedefleyip, çoklu teknik gösterge kombinasyonu ile teyit edilmektedir.
// - Risk yönetimi, ATR tabanlı dinamik stop loss ve take profit seviyeleri ile sağlanmaktadır.
// - Stratejiyi çalıştırmadan önce, farklı zaman dilimlerinde ve semboller üzerinde optimizasyon yapmanız önerilir.

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。