7 al-sat stratejisi ve 2 referans 3 yıllık BTC verisinde yarıştı. TradingView'da kendin test et: Pine Script kodları, adımlar ve geçmiş veri sonuçları.
9 stratejinin kodları
Her kutunun sağ üstündeki düğmeyle kodu kopyala, Pine Editor'e yapıştır.
Telefonda kod kutusunu yana kaydırarak satırın tamamını görebilirsin.
9 kodun hepsi TradingView'ın kendi Pine Script v6
derleyicisinde hatasız ve uyarısız derlenip denendi.
1) Claude Trend
Yapay zekânın kendi tasarladığı trend stratejisi.
Kural: Fiyat 200 günlük ortalamanın üstünde ve RSI 50'nin üstündeyse gir. Fiyat 50 günlük EMA'nın altında kapanırsa çık.
Claude'a verilen prompt: "Bitcoin için sade bir trend stratejisi tasarla: büyük trend yukarıysa ve güç varsa gir, trend bozulunca çık."
Videoda kuralı kısaca "200 günlük ortalamanın üstünde ve hacim varsa al, altına düşünce sat" diye anlattım. Sonuçlar bu sayfadaki kodla alındı; kuralın tamamı şu: giriş, fiyat 200 günlük SMA'nın üstünde ve RSI(14) 50'nin üstündeyken; çıkış, fiyat 50 günlük EMA'nın altında kapanınca.
//@version=6
strategy("Claude Trend", overlay=true, initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1)
startT = input.time(timestamp("2023-10-07T00:00:00+00:00"), "Başlangıç")
endT = input.time(timestamp("2026-10-06T00:00:00+00:00"), "Bitiş")
inDate = time >= startT and time <= endT
sma200 = ta.sma(close, 200)
ema50 = ta.ema(close, 50)
r = ta.rsi(close, 14)
if inDate and strategy.position_size == 0 and close > sma200 and r > 50
strategy.entry("L", strategy.long)
if strategy.position_size > 0 and close < ema50
strategy.close("L")
plot(sma200, "SMA 200", color.red)
plot(ema50, "EMA 50", color.yellow)
2) Supertrend L/S
Hem long hem short: hep piyasada kalır, yalnızca yön değiştirir.
Kural: Supertrend yukarı dönünce long, aşağı dönünce short. Pozisyon hiç kapanmaz, sadece yön değiştirir.
Claude'a verilen prompt: "Supertrend (10, 3) ile hep piyasada kalan bir strateji yaz: trend yukarıysa long, aşağıysa short."
//@version=6
strategy("Supertrend L/S", overlay=true, initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1)
startT = input.time(timestamp("2023-10-07T00:00:00+00:00"), "Başlangıç")
endT = input.time(timestamp("2026-10-06T00:00:00+00:00"), "Bitiş")
inDate = time >= startT and time <= endT
[st, dir] = ta.supertrend(3, 10)
// Pine'da dir < 0 = yükselen trend
if inDate and dir < 0 and strategy.position_size <= 0
strategy.entry("L", strategy.long)
if inDate and dir > 0 and strategy.position_size >= 0
strategy.entry("S", strategy.short)
plot(st, "Supertrend", dir < 0 ? color.green : color.red)
3) İndikatör Konseyi
Beş indikatör oy veriyor; en az dördü evet derse giriyor.
Kural: Her biri 1 oy: RSI > 50 · MACD sinyalin üstünde · EMA 9 > EMA 21 · fiyat Bollinger orta bandının üstünde · hacim 20 günlük ortalamanın üstünde ve gün yeşil kapandı. 4 veya 5 oy = gir, 0 veya 1 oy = çık.
Claude'a verilen prompt: "5 indikatörün oy verdiği bir strateji yaz: RSI, MACD, EMA 9/21, Bollinger orta bandı ve hacim. 4 evet gelirse gir, 1 veya daha az evet kalırsa çık."
//@version=6
strategy("İndikatör Konseyi", overlay=true, initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1)
startT = input.time(timestamp("2023-10-07T00:00:00+00:00"), "Başlangıç")
endT = input.time(timestamp("2026-10-06T00:00:00+00:00"), "Bitiş")
inDate = time >= startT and time <= endT
r = ta.rsi(close, 14)
[macdL, sigL, _] = ta.macd(close, 12, 26, 9)
e9 = ta.ema(close, 9)
e21 = ta.ema(close, 21)
bbm = ta.sma(close, 20)
vAvg = ta.sma(volume, 20)
votes = (r > 50 ? 1 : 0) + (macdL > sigL ? 1 : 0) + (e9 > e21 ? 1 : 0) + (close > bbm ? 1 : 0) + (volume > vAvg and close > open ? 1 : 0)
if inDate and strategy.position_size == 0 and votes >= 4
strategy.entry("L", strategy.long)
if strategy.position_size > 0 and votes <= 1
strategy.close("L")
plotchar(votes, "Oy", "", location.top)
4) Dip Avcısı RSI(2)
Trend yukarıyken sert düşüşte giriyor, birkaç gün içinde çıkıyor.
Kural: Fiyat 200 günlük ortalamanın üstündeyken 2 günlük RSI 10'un altına inerse gir. Fiyat 5 günlük ortalamanın üstünde kapanınca ya da giriş günündeki fiyatın 2 ATR altına düşünce çık.
Claude'a verilen prompt: "Trend yukarıyken kısa süreli sert düşüşleri alan bir strateji yaz: 2 günlük RSI 10'un altına inince al, fiyat 5 günlük ortalamanın üstüne çıkınca sat, 2 ATR stop koy."
//@version=6
strategy("Dip Avcısı RSI(2)", overlay=true, initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1)
startT = input.time(timestamp("2023-10-07T00:00:00+00:00"), "Başlangıç")
endT = input.time(timestamp("2026-10-06T00:00:00+00:00"), "Bitiş")
inDate = time >= startT and time <= endT
r2 = ta.rsi(close, 2)
sma200 = ta.sma(close, 200)
sma5 = ta.sma(close, 5)
atr = ta.atr(14)
var float stopLvl = na
if inDate and strategy.position_size == 0 and r2 < 10 and close > sma200
stopLvl := close - 2 * atr
strategy.entry("L", strategy.long)
if strategy.position_size > 0 and (close > sma5 or close < stopLvl)
strategy.close("L")
plot(sma5, "SMA 5", color.aqua)
plot(strategy.position_size > 0 ? stopLvl : na, "Stop", color.red, style=plot.style_linebr)
5) Kırılım + ATR Stop
20 günlük zirve kırılınca giriyor, iz süren stopla çıkıyor.
Kural: Kapanış son 20 günün en yükseğini geçerse gir. Stop, fiyatın 3 ATR altında başlar ve sadece yukarı taşınır. Kapanış stopun altına inerse çık.
Claude'a verilen prompt: "20 günlük zirve kırılınca giren, 3 ATR'lik iz süren stop ile çıkan bir strateji yaz."
//@version=6
strategy("Kırılım + ATR Stop", overlay=true, initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1)
startT = input.time(timestamp("2023-10-07T00:00:00+00:00"), "Başlangıç")
endT = input.time(timestamp("2026-10-06T00:00:00+00:00"), "Bitiş")
inDate = time >= startT and time <= endT
hh20 = ta.highest(high, 20)[1]
atr = ta.atr(14)
var float trail = na
if strategy.position_size > 0
trail := math.max(trail, close - 3 * atr)
if close < trail
strategy.close("L")
else if inDate and close > hh20
trail := close - 3 * atr
strategy.entry("L", strategy.long)
plot(hh20, "20G zirve", color.green)
plot(strategy.position_size > 0 ? trail : na, "İz süren stop", color.red, style=plot.style_linebr)
6) MACD Trend
MACD ve 50 günlük EMA birlikte onay verince giriyor.
Kural: MACD sinyalin üstünde ve fiyat 50 EMA'nın üstündeyse gir. MACD sinyalin altına inince çık.
Claude'a verilen prompt: "MACD sinyal çizgisini yukarı kestiğinde ve fiyat 50 günlük EMA'nın üstündeyken giren, MACD aşağı kesince çıkan bir strateji yaz."
//@version=6
strategy("MACD Trend", overlay=true, initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1)
startT = input.time(timestamp("2023-10-07T00:00:00+00:00"), "Başlangıç")
endT = input.time(timestamp("2026-10-06T00:00:00+00:00"), "Bitiş")
inDate = time >= startT and time <= endT
[macdL, sigL, _] = ta.macd(close, 12, 26, 9)
ema50 = ta.ema(close, 50)
if inDate and strategy.position_size == 0 and macdL > sigL and close > ema50
strategy.entry("L", strategy.long)
if strategy.position_size > 0 and macdL < sigL
strategy.close("L")
plot(ema50, "EMA 50", color.yellow)
7) Ichimoku Bulut
Fiyat Ichimoku bulutunun üstündeyken trende katılıyor.
Kural: Fiyat bulutun üstünde ve dönüş çizgisi (9) baz çizgisinin (26) üstündeyse gir. Fiyat baz çizgisinin altında kapanırsa çık.
Claude'a verilen prompt: "Ichimoku ile bir strateji yaz: fiyat bulutun üstünde ve dönüş çizgisi baz çizgisinin üstündeyse gir, fiyat baz çizgisinin altına inince çık."
//@version=6
strategy("Ichimoku Bulut", overlay=true, initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1)
startT = input.time(timestamp("2023-10-07T00:00:00+00:00"), "Başlangıç")
endT = input.time(timestamp("2026-10-06T00:00:00+00:00"), "Bitiş")
inDate = time >= startT and time <= endT
donchian(len) => math.avg(ta.lowest(len), ta.highest(len))
conv = donchian(9)
base = donchian(26)
spanA = math.avg(conv, base)[26]
spanB = donchian(52)[26]
cloudTop = math.max(spanA, spanB)
if inDate and strategy.position_size == 0 and close > cloudTop and conv > base
strategy.entry("L", strategy.long)
if strategy.position_size > 0 and close < base
strategy.close("L")
plot(conv, "Dönüş", color.aqua)
plot(base, "Baz", color.orange)
plot(cloudTop, "Bulut üstü", color.gray)
8) Al ve Unut
Karşılaştırma için klasik: ilk gün alıp hiç dokunmuyor.
Kural: İlk gün tüm parayla al, hiç dokunma.
//@version=6
strategy("Al ve Unut", overlay=true, initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1)
startT = input.time(timestamp("2023-10-07T00:00:00+00:00"), "Başlangıç")
inDate = time >= startT
if inDate and strategy.position_size == 0 and strategy.closedtrades == 0
strategy.entry("L", strategy.long)
9) Her Gün DCA
Karşılaştırma için klasik: parayı günlere bölüp her gün aynı miktarda alıyor.
Kural: 1000$'ı dönemdeki gün sayısına böl, her gün aynı miktarda al. Henüz harcanmamış para nakitte bekler.
3 yıl için gün sayısı 1096, son 1 yıl için 366. Ayarlardan değiştir.
//@version=6
strategy("Her Gün DCA", overlay=true, initial_capital=1000, pyramiding=2000, commission_type=strategy.commission.percent, commission_value=0.1)
startT = input.time(timestamp("2023-10-07T00:00:00+00:00"), "Başlangıç")
endT = input.time(timestamp("2026-10-06T00:00:00+00:00"), "Bitiş")
days = input.int(1096, "Gün sayısı (3 yıl = 1096, 1 yıl = 366)")
inDate = time >= startT and time <= endT
perDay = 1000.0 / days
if inDate
strategy.entry("DCA", strategy.long, qty = perDay * 0.999 / close)