Untitled

 avatar
MuratUCAR
plain_text
12 days ago
5.6 kB
15
Indexable
//@version=6
strategy("DARVAXIM with Pivot and Fibonacci Strategy - Sadece Al", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

// MTF Zaman Dilimi Seçimi
timeframe = input.timeframe("D", title="Pivot Zaman Dilimi", options=["60", "240", "D", "W"], group="Period") // Varsayılan: Günlük (D)

// Pivot Noktalarını Hesapla
pivot_high = request.security(syminfo.tickerid, timeframe, ta.highest(high, 1))  // Önceki çubuktaki en yüksek fiyat
pivot_low = request.security(syminfo.tickerid, timeframe, ta.lowest(low, 1))     // Önceki çubuktaki en düşük fiyat
pivot_close = request.security(syminfo.tickerid, timeframe, close[1])           // Önceki çubuktaki kapanış fiyatı

// Pivot Noktaları (R1, S1, R2, S2)
pivot = (pivot_high + pivot_low + pivot_close) / 3
R1 = (2 * pivot) - pivot_low
S1 = (2 * pivot) - pivot_high
R2 = pivot + (pivot_high - pivot_low)
S2 = pivot - (pivot_high - pivot_low)

// Kullanıcıdan Pivot Seviyesi Seçimi
pivotLevel = input.string("R1-S1", title="Pivot Seviyesi", options=["R1-S1", "R2-S2"], group="Pivot Levels")

// Seçilen Pivot Seviyesine Göre Yüksek ve Düşük Noktaları Belirle
mtf_high = pivotLevel == "R1-S1" ? R1 : R2
mtf_low = pivotLevel == "R1-S1" ? S1 : S2

// Kullanıcıdan girişler
maPeriod1 = input.int(21, title="1. Hareketli Ortalama Periyodu", minval=1)
maType = input.string("SMA", title="Hareketli Ortalama Türü", options=["SMA", "EMA", "WMA", "VWMA"])
trendLookback = input.int(5, title="Trend Analiz Periyodu", minval=1)

// Stop Loss ve Take Profit seviyeleri
stopLossPerc = input.float(2.0, title="Stop Loss (%)") / 100
trailStopPerc = input.float(1.5, title="Trailing Stop Loss (%)") / 100

// 4 Kar Al Noktası, Oranları ve Miktarları
profitTarget1 = input.float(10.0, title="Kar Al 1 (%)", group="Take Profit Levels") / 100
profitQty1 = input.float(25.0, title="Kar Al 1 Miktarı (%)", group="Take Profit Levels") / 100

profitTarget2 = input.float(20.0, title="Kar Al 2 (%)", group="Take Profit Levels") / 100
profitQty2 = input.float(25.0, title="Kar Al 2 Miktarı (%)", group="Take Profit Levels") / 100

profitTarget3 = input.float(30.0, title="Kar Al 3 (%)", group="Take Profit Levels") / 100
profitQty3 = input.float(25.0, title="Kar Al 3 Miktarı (%)", group="Take Profit Levels") / 100

profitTarget4 = input.float(40.0, title="Kar Al 4 (%)", group="Take Profit Levels") / 100
profitQty4 = input.float(25.0, title="Kar Al 4 Miktarı (%)", group="Take Profit Levels") / 100

// Hareketli Ortalama Türü
ma1 = switch maType
    "SMA" => ta.sma(close, maPeriod1)
    "EMA" => ta.ema(close, maPeriod1)
    "WMA" => ta.wma(close, maPeriod1)
    "VWMA" => ta.vwma(close, maPeriod1)  // volume argümanı kaldırıldı

// Ortalamanın yükselip yükselmediğini kontrol et
isRising = ta.rising(ma1, trendLookback)
isFalling = ta.falling(ma1, trendLookback)
trendColor = isRising ? color.green : isFalling ? color.red : color.blue

// Fibonacci seviyelerini hesapla
fib_236 = mtf_high - (mtf_high - mtf_low) * 0.236
fib_382 = mtf_high - (mtf_high - mtf_low) * 0.382
fib_50 = mtf_high - (mtf_high - mtf_low) * 0.5
fib_618 = mtf_high - (mtf_high - mtf_low) * 0.618
fib_786 = mtf_high - (mtf_high - mtf_low) * 0.786

// Fibonacci seviyelerini ve Pivot seviyelerini çiz
plot(mtf_high, color=color.new(color.blue, 50), title="Pivot Yüksek (R1/R2)")
plot(fib_236, color=color.blue, title="Fibonacci 23.6%")
plot(fib_382, color=color.green, title="Fibonacci 38.2%")
plot(fib_50, color=color.rgb(48, 199, 245), title="Fibonacci 50%")
plot(fib_618, color=color.red, title="Fibonacci 61.8%")
plot(fib_786, color=color.orange, title="Fibonacci 78.6%")
plot(mtf_low, color=color.new(color.red, 50), title="Pivot Düşük (S1/S2)")

// Grafik üzerinde trend çizgisini çiz
plot(ma1, color=trendColor, linewidth=2, title="Trend")

// Alış İşlem Mantığı (Sadece Long Pozisyonlar)
if isRising and (ta.crossover(close, fib_618) or ta.crossover(close, fib_786))
    buyPrice = close
    strategy.entry("Buy", strategy.long)

    // Stop Loss ve Take Profit işlemleri
    takeProfitPrice1 = buyPrice * (1 + profitTarget1)
    takeProfitPrice2 = buyPrice * (1 + profitTarget2)
    takeProfitPrice3 = buyPrice * (1 + profitTarget3)
    takeProfitPrice4 = buyPrice * (1 + profitTarget4)
    stopLossPrice = buyPrice * (1 - stopLossPerc)

    // Kar Al Seviyeleri (Miktarları ile)
    if (strategy.position_size > 0)
        // Take Profit 1
        if (close >= takeProfitPrice1)
            strategy.exit("TakeProfit1", from_entry="Buy", qty_percent=profitQty1, limit=takeProfitPrice1, stop=stopLossPrice)

        // Take Profit 2
        if (close >= takeProfitPrice2)
            strategy.exit("TakeProfit2", from_entry="Buy", qty_percent=profitQty2, limit=takeProfitPrice2, stop=stopLossPrice)

        // Take Profit 3
        if (close >= takeProfitPrice3)
            strategy.exit("TakeProfit3", from_entry="Buy", qty_percent=profitQty3, limit=takeProfitPrice3, stop=stopLossPrice)

        // Take Profit 4
        if (close >= takeProfitPrice4)
            strategy.exit("TakeProfit4", from_entry="Buy", qty_percent=profitQty4, limit=takeProfitPrice4, stop=stopLossPrice)

        // Trailing Stop
        trailOffset = buyPrice * trailStopPerc
        trailPrice = close - trailOffset
        if (close > trailPrice)
            strategy.exit("TrailingStop", from_entry="Buy", trail_offset=trailOffset, trail_points=trailOffset / syminfo.mintick)
Leave a Comment