NEON KELTNER - Adaptive Keltner Signals

Seckin_Tuncay · study · 851 行 · 点赞 50 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
// ════════════════════════════════════════════════════════════════════
//  NEON KELTNER · Sinyal  (v12 lite)
//  lite: MAMA seçeneği çıkarıldı (derleme yükünü azaltmak için)
//  Temel: "Keltner Channel signals" (Pine v3, Keltner Channel APEX tabanlı)
//  v6'ya taşındı ve yeniden yazıldı:
//   · Keltner iç / dış bandına göre sinyal gücü (✦ / ✦✦)
//   · Trend filtresi (kanal eğimi veya üst zaman dilimi EMA)
//   · WaveTrend onayı (artık gerçekten sinyali filtreliyor)
//   · Otomatik Giriş / Stop / H1 / H2 çizgileri ve R/Ö oranı
//   · Aynı yönde bekleme (cooldown)
//   · Repaint önleme: mum kapanışı onayı + üst ZD'de sadece kapanmış mum
//   · Bilgi tablosu, dinamik alarmlar, neon minimal tema
//  v12:
//   · İngilizce dil desteği: grafik, panel, etiket, ipucu ve alarm metinleri
//     (Dil / Language ayarı). Ayarlar menüsü Pine kısıtı nedeniyle Türkçe kalır.
//  v11:
//   · Sinyal profili: Otomatik (varsayılan) / Standart / Sadece ⚡ / Özel
//   · Otomatik: her sinyal türü bu grafikteki kendi geçmiş sonuçlarına göre
//     gösterilir veya gizlenir; hedef (H1/H2) da otomatik seçilir. Karar her
//     an sadece o ana kadar SONUÇLANMIŞ sinyallere bakar (geleceği görmez).
//   · İstatistik satırları artık ayrık: Dönüş / Dönüş ✦✦ / ⚡ / ↺ / ↺ ⚠
//   · Uyumsuzluk geçerlilik penceresi varsayılanı 20
//  v10:
//   · Sinyal gücü filtresine 'Dış bant hariç' eklendi ve varsayılan oldu.
//     Testlerde (NEAR 1s/4s, altın 1s/4s) dış banda değen dönüşler (✦✦)
//     hiçbir yerde kazandırmadı, altında belirgin kaybettirdi.
//  v9:
//   · İstatistikte H1 ve H2 aynı anda (her sinyal iki hedef için ayrı izlenir)
//   · Bilgi ve istatistik tek panelde birleşti; bölümler ayrı ayrı veya
//     tamamen gizlenebilir
//  v8:
//   · Ters uyumsuzluk için 'Uyar' modu: ↺ sinyali çıkar ama ⚠ ile işaretlenir
//   · İstatistik tablosu: her sinyal türünün başarı oranı ve ortalama R'si
//     (stoptan önce hedefe ulaşan sinyaller = başarı)
//  v7:
//   · ↺ için trend gücü şartı: uzun EMA belirgin yol almış olmalı (yatay
//     dönemde EMA200 eğimi titreşip sahte ↺ üretiyordu)
//   · ↺ için ters uyumsuzluk vetosu: yakın zamanda ayı ⚡ varsa ↺ AL yok
//   · Tabloda trend gücü (ATR cinsinden)
//  v6:
//   · Yeni sinyal türü: trend içi geri çekilme (↺). Trend yönünde fiyat orta
//     çizgiye (veya iç banda) kadar geri çekilip reddedilince devam sinyali.
//   · Ayar grupları yeniden numaralandı
//  v5:
//   · Trend eğimi 50 mumda ölçülüyor (10 mum, sert geri çekilmede EMA200'ü de
//     ters çeviriyordu ve trend içi dip alımlarını engelliyordu)
//   · WaveTrend 'Esnek' modu (Aşırı Bölge VEYA Kesişim) varsayılan oldu
//   · Elenen sinyallerin üzerine gelince hangi filtreye takıldığı yazıyor
//  v4:
//   · WaveTrend uyumsuzluk (divergence) tespiti: fiyat daha düşük dip yapıp
//     WT daha yüksek dip yaptığında boğa, tersi ayı uyumsuzluğu.
//     Güç etiketi (⚡) veya zorunlu onay olarak kullanılabilir.
//   · Ayar grupları yeniden numaralandı
//  v3:
//   · DÜZELTME: trend filtresi artık uzun EMA eğimine bakıyor. Kanal ortası
//     (EMA34) dönüş anında hep ters yöne eğimli olduğu için sinyalleri
//     neredeyse tamamen siliyordu.
//   · Elenen ham sinyalleri gösterme seçeneği (teşhis için)
//   · Durum satırı ve fiyat ölçeği sadeleştirildi
//  v2:
//   · WaveTrend dinamik eşikler (yüzdelik dilim, sembole kendini uydurur)
//   · Otomatik mod: trendde Kesişim, yatayda Aşırı Bölge onayı
//   · Rejim ölçümü: Verimlilik Oranı (ER) veya ADX
// ════════════════════════════════════════════════════════════════════
indicator("NEON KELTNER · Sinyal", shorttitle = "NEON KC", overlay = true, max_lines_count = 500, max_labels_count = 500)
 
// ───────────────────────── Ayar grupları ─────────────────────────
string GA = "1 · Profil"
string G1 = "2 · Kanal"
string G2 = "3 · Sinyal"
string GP = "4 · Geri Çekilme Sinyali"
string G3 = "5 · Trend Filtresi"
string G4 = "6 · WaveTrend Onayı"
string GD = "7 · WT Uyumsuzluk"
string G5 = "8 · Stop · Hedef"
string G6 = "9 · Görünüm"
string GS = "10 · İstatistik"
string G7 = "11 · Alarmlar"
 
// 1 · Profil
lang    = input.string("Türkçe", "Dil / Language", options = ["Türkçe", "English"], group = GA, tooltip = "Grafik, panel, etiket ve alarm metinlerinin dili. Ayarlar menüsü Pine kısıtı nedeniyle Türkçe kalır.\nLanguage of chart, panel, label and alert texts. The settings menu stays in Turkish (Pine limitation).", display = display.none)
profile = input.string("Otomatik", "Sinyal profili", options = ["Otomatik", "Standart", "Sadece ⚡", "Özel"], group = GA, tooltip = "Otomatik: tüm sinyal türleri üretilir; her tür bu grafikteki kendi geçmiş sonuçlarına göre gösterilir ya da gizlenir, hedef (H1/H2) de otomatik seçilir. Ayar gerekmez.\nStandart: dış bant hariç dönüşler + ↺ sinyalleri.\nSadece ⚡: yalnızca uyumsuzluklu dönüşler.\nÖzel: aşağıdaki sinyal ayarları tek tek geçerli olur.", display = display.none)
autoMin = input.int(15, "Oto · en az sonuç sayısı", minval = 5, group = GA, tooltip = "Bir sinyal türü bu kadar sonuçlanmış sinyale ulaşana kadar gösterilir (panelde: ölçülüyor).", display = display.none)
autoTh  = input.float(0.05, "Oto · en düşük ortalama R", step = 0.05, group = GA, tooltip = "Ortalama R'si bunun altında kalan tür gizlenir. 0.05, komisyon için küçük bir pay bırakır.", display = display.none)
 
// 2 · Kanal
src     = input.source(close, "Kaynak", group = G1, display = display.none)
maType  = input.string("EMA", "Orta çizgi MA tipi", options = ["SMA", "EMA", "WMA", "DEMA", "TEMA", "TRIMA", "KAMA", "T3"], group = G1, display = display.none)
maLen   = input.int(34, "Orta çizgi uzunluğu", minval = 1, group = G1, display = display.none)
atrType = input.string("EMA", "ATR yumuşatma tipi", options = ["SMA", "EMA", "WMA", "DEMA", "TEMA", "TRIMA", "KAMA", "T3"], group = G1, display = display.none)
atrLen  = input.int(88, "ATR yumuşatma uzunluğu", minval = 1, group = G1, display = display.none)
multIn  = input.float(1.5, "İç bant çarpanı", minval = 0.1, step = 0.1, group = G1, display = display.none)
multOut = input.float(3.5, "Dış bant çarpanı", minval = 0.1, step = 0.1, group = G1, display = display.none)
 
// 2 · Sinyal
bbLen    = input.int(34, "Sapma uzunluğu", minval = 2, group = G2, tooltip = "Orta çizgi etrafındaki standart sapma bandı. Fiyat bu bandın dışına çıkıp geri girince sinyal oluşur.", display = display.none)
bbMult   = input.float(2.0, "Sapma çarpanı", minval = 0.5, step = 0.1, group = G2, display = display.none)
obLvl    = input.float(1.0, "%B üst seviye", step = 0.05, group = G2, inline = "pb", display = display.none)
osLvl    = input.float(0.0, "%B alt seviye", step = 0.05, group = G2, inline = "pb", display = display.none)
minTierS = input.string("Dış bant hariç", "Sinyal gücü filtresi", options = ["Hepsi", "Dış bant hariç", "KC İç Bant", "KC Dış Bant"], group = G2, tooltip = "Hepsi: tüm dönüşler.\nDış bant hariç: dış Keltner bandına değen dönüşler (✦✦) verilmez. Testlerde bunlar kazandırmadı.\nKC İç Bant: fiyat en az iç banda değmiş olmalı (✦ ve ✦✦).\nKC Dış Bant: sadece dış banda değenler (✦✦).\n\nNot: NEAR gibi sert trend yapan coinlerde Hepsi daha iyi olabilir; istatistik panelinden kontrol et.", display = display.none)
cooldown = input.int(5, "Aynı yönde bekleme (mum)", minval = 0, group = G2, display = display.none)
confOnly = input.bool(true, "Sadece mum kapanışında onayla", group = G2, tooltip = "Açık kalırsa sinyal mum kapanmadan görünüp kaybolmaz.", display = display.none)
 
// 3 · Trend Filtresi
trendMode = input.string("Uzun EMA", "Trend filtresi", options = ["Kapalı", "Uzun EMA", "Üst Zaman Dilimi"], group = G3, tooltip = "Yukarı trendde sadece AL, aşağı trendde sadece SAT gösterilir.\nUzun EMA: uzun EMA'nın eğimine bakar, kısa geri çekilmelerden etkilenmez.", display = display.none)
trendLen  = input.int(200, "Uzun EMA uzunluğu", minval = 10, group = G3, inline = "tl", display = display.none)
trendSlp  = input.int(50, "Eğim mesafesi (mum)", minval = 1, group = G3, inline = "tl", display = display.none)
htfTF     = input.timeframe("240", "Üst zaman dilimi", group = G3, tooltip = "Grafik zaman diliminden büyük seçilmeli.", display = display.none)
htfLen    = input.int(50, "Üst ZD EMA uzunluğu", minval = 1, group = G3, display = display.none)
 
// 4 · WaveTrend Onayı
wtMode = input.string("Esnek", "WaveTrend onayı", options = ["Kapalı", "Aşırı Bölge", "Kesişim", "Esnek", "Otomatik"], group = G4, tooltip = "Aşırı Bölge: AL için WT son N mumda aşırı satımda olmalı.\nKesişim: AL için WT son N mumda yukarı kesişmiş olmalı.\nEsnek: ikisinden biri yeterli.\nOtomatik: trendde Kesişim, yatayda Aşırı Bölge kullanılır.", display = display.none)
wtN1   = input.int(10, "Kanal uzunluğu", minval = 1, group = G4, display = display.none)
wtN2   = input.int(21, "Ortalama uzunluğu", minval = 1, group = G4, display = display.none)
wtSig  = input.int(4, "Sinyal uzunluğu", minval = 1, group = G4, display = display.none)
wtLook = input.int(5, "Geriye bakış (mum)", minval = 1, group = G4, display = display.none)
thrMode  = input.string("Dinamik", "Eşik tipi", options = ["Sabit", "Dinamik"], group = G4, tooltip = "Sabit: aşağıdaki ±değerler.\nDinamik: eşikler WT'nin kendi geçmişinden hesaplanır (yüzdelik dilim), her sembole kendini uydurur.", display = display.none)
wtOB     = input.float(53, "Sabit aşırı alım", group = G4, inline = "wt", display = display.none)
wtOS     = input.float(-53, "Sabit aşırı satım", group = G4, inline = "wt", display = display.none)
wtPctLen = input.int(200, "Dinamik · geçmiş (mum)", minval = 20, group = G4, display = display.none)
wtPct    = input.float(10, "Dinamik · uç dilim (%)", minval = 1, maxval = 40, step = 1, group = G4, tooltip = "10 = WT'nin en düşük %10'u aşırı satım, en yüksek %10'u aşırı alım.", display = display.none)
wtFloor  = input.float(20, "Dinamik · minimum eşik", minval = 0, group = G4, tooltip = "Dinamik eşik sıfıra çok yaklaşmasın diye alt sınır (±).", display = display.none)
regMode  = input.string("Verimlilik Oranı", "Rejim ölçümü", options = ["Verimlilik Oranı", "ADX"], group = G4, tooltip = "Otomatik modda trend / yatay ayrımı için kullanılır.", display = display.none)
erLen    = input.int(20, "ER uzunluğu", minval = 2, group = G4, inline = "er", display = display.none)
erTh     = input.float(0.30, "ER trend eşiği", minval = 0.05, maxval = 0.9, step = 0.05, group = G4, inline = "er", display = display.none)
adxLen   = input.int(14, "ADX uzunluğu", minval = 2, group = G4, inline = "adx", display = display.none)
adxTh    = input.float(25, "ADX trend eşiği", minval = 5, step = 1, group = G4, inline = "adx", display = display.none)
 
// 5 · Stop · Hedef
// 5 · WT Uyumsuzluk
divUse     = input.string("Güç etiketi", "Uyumsuzluk kullanımı", options = ["Kapalı", "Güç etiketi", "Zorunlu onay"], group = GD, tooltip = "Güç etiketi: sinyal çıkar, uyumsuzluk varsa ⚡ eklenir.\nZorunlu onay: sadece uyumsuzluklu sinyaller gösterilir.", display = display.none)
divLook    = input.int(10, "Salınım penceresi (mum)", minval = 3, group = GD, tooltip = "WT kesişiminde dip/tepe bu kadar mum geriye bakılarak bulunur.", display = display.none)
divMaxDist = input.int(80, "İki dip/tepe arası en fazla (mum)", minval = 10, group = GD, display = display.none)
divValid   = input.int(20, "Geçerlilik (mum)", minval = 1, group = GD, tooltip = "Uyumsuzluk, bu kadar mum içinde oluşan sinyale sayılır.", display = display.none)
divLvl     = input.float(0, "WT seviye şartı (±)", minval = 0, group = GD, tooltip = "Boğa uyumsuzluğunda WT dibi bu değerin altında (−), ayıda tepesi üstünde (+) olmalı. 0 = sıfır çizgisi.", display = display.none)
showDivLn  = input.bool(true, "Grafikte uyumsuzluk çizgisi", group = GD, display = display.none)
 
// 3 · Geri Çekilme Sinyali
pbUse  = input.bool(true, "Geri çekilme sinyalleri (↺)", group = GP, tooltip = "Trend yönünde devam sinyali: düşüş trendinde fiyat orta çizgiye kadar yükselip reddedilince SAT ↺, yükseliş trendinde tersi AL ↺.\nTrend yönü 5 · Trend Filtresi ayarından alınır (Kapalı ise Uzun EMA kullanılır).", display = display.none)
pbZone = input.string("Orta çizgi", "Dokunma bölgesi", options = ["Orta çizgi", "İç bant"], group = GP, tooltip = "Orta çizgi: fiyat en az orta çizgiye değmeli.\nİç bant: karşı iç banda kadar gitmeli (daha derin, daha seyrek).", display = display.none)
pbLook = input.int(5, "Dokunma penceresi (mum)", minval = 1, group = GP, display = display.none)
pbWT   = input.bool(true, "WaveTrend yön onayı", group = GP, tooltip = "SAT ↺ için WT hızlı çizgi yavaş çizginin altında, AL ↺ için üstünde olmalı.", display = display.none)
pbCd   = input.int(10, "Aynı yönde bekleme (mum)", minval = 0, group = GP, display = display.none)
pbStr  = input.float(1.0, "Trend gücü şartı (ATR, 0 = kapalı)", minval = 0, step = 0.1, group = GP, tooltip = "Uzun EMA, eğim mesafesi boyunca en az bu kadar ATR yol almış olmalı. Yatay dönemde sahte ↺ sinyallerini eler.", display = display.none)
pbVMode = input.string("Uyar", "Ters uyumsuzluk", options = ["Kapalı", "Uyar", "Engelle"], group = GP, tooltip = "Son N mumda ters yönde uyumsuzluk varsa (↺ AL için ayı, ↺ SAT için boğa):\nUyar: sinyal çıkar, ⚠ ile işaretlenir.\nEngelle: sinyal verilmez.", display = display.none)
pbVeto  = input.int(40, "Ters uyumsuzluk penceresi (mum)", minval = 1, group = GP, display = display.none)
 
stopBuf  = input.float(0.5, "Stop tamponu (ATR)", minval = 0, step = 0.1, group = G5, tooltip = "Stop, dönüş öncesi dip/tepenin bu kadar ATR ötesine konur.", display = display.none)
showLvls = input.bool(true, "Giriş / Stop / Hedef çizgileri", group = G5, display = display.none)
onlyLast = input.bool(true, "Sadece son işlemi göster", group = G5, display = display.none)
lvlLen   = input.int(20, "Çizgi uzunluğu (mum)", minval = 5, maxval = 400, group = G5, display = display.none)
 
// 6 · Görünüm
colBuy    = input.color(#00FFA3, "AL", group = G6, inline = "c1", display = display.none)
colSell   = input.color(#FF2E88, "SAT", group = G6, inline = "c1", display = display.none)
colNeu    = input.color(#8B95A7, "Nötr", group = G6, inline = "c1", display = display.none)
showGlow  = input.bool(true, "Neon parlama", group = G6, display = display.none)
showFill  = input.bool(true, "Bant dolgusu", group = G6, display = display.none)
showDots  = input.bool(true, "Destek / direnç noktaları", group = G6, display = display.none)
showPanel = input.bool(true, "Paneli göster", group = G6, display = display.none)
showTable = input.bool(true, "Panel · bilgi bölümü", group = G6, display = display.none)
slopeLen  = input.int(5, "Orta çizgi renk eğimi (mum)", minval = 1, group = G6, display = display.none)
showRaw   = input.bool(false, "Elenen sinyalleri göster (teşhis)", group = G6, tooltip = "Filtrelere takılan ham dönüşleri soluk küçük noktalarla gösterir.", display = display.none)
showRegBg = input.bool(false, "Trend rejiminde hafif arka plan", group = G6, display = display.none)
tablePos  = input.string("Sağ Üst", "Panel konumu", options = ["Sağ Üst", "Sağ Alt", "Sol Üst", "Sol Alt"], group = G6, display = display.none)
 
// 7 · Alarmlar
// 9 · İstatistik
statShow = input.bool(true, "Panel · istatistik bölümü", group = GS, tooltip = "Grafikte yüklü geçmişteki her sinyal izlenir: stoptan önce hedefe ulaşırsa başarı, önce stopa değerse kayıp. Aynı mumda ikisi birden olursa kayıp sayılır.", display = display.none)
statMax  = input.int(100, "Zaman aşımı (mum)", minval = 5, group = GS, tooltip = "Bu kadar mumda ne hedefe ne stopa ulaşan sinyal 'sonuçsuz' sayılır, orana katılmaz.", display = display.none)
 
dynAlert = input.bool(true, "Detaylı alarm mesajı (alert)", group = G7, tooltip = "Alarm kurarken 'Herhangi bir alert() çağrısı' seçeneğini seç. Mesajda giriş, stop, hedef ve R/Ö yazar.", display = display.none)
 
// Sabit tema renkleri
// Profile göre etkin ayarlar
bool   isAuto  = profile == "Otomatik"
string effTier = profile == "Özel" ? minTierS : profile == "Standart" ? "Dış bant hariç" : "Hepsi"
string effDiv  = profile == "Özel" ? divUse : profile == "Sadece ⚡" ? "Zorunlu onay" : "Güç etiketi"
bool   effPb   = profile == "Özel" ? pbUse : profile != "Sadece ⚡"
 
// Dil yardımcıları
bool isEN = lang == "English"
 
f_t(string tr, string en) =>
    isEN ? en : tr
 
f_tg(string h) =>
    isEN ? (h == "H1" ? "T1" : h == "H2" ? "T2" : h) : h
 
f_mode(string m) =>
    not isEN ? m : m == "Kesişim" ? "Cross" : m == "Aşırı Bölge" ? "Extreme zone" : m == "Esnek" ? "Flexible" : m == "Kapalı" ? "Off" : m
 
f_prof(string p) =>
    not isEN ? p : p == "Otomatik" ? "Auto" : p == "Standart" ? "Standard" : p == "Sadece ⚡" ? "⚡ only" : "Custom"
 
color cStop = #FF6B3D
color cTgt  = #FFD60A
color cText = #C9D1D9
color cBg   = #0B0F14
 
// ───────────────────────── MA fonksiyonları ─────────────────────────
f_kama(float s, int l) =>
    float noise  = math.abs(s - nz(s[1], s))
    float signal = math.abs(s - nz(s[l], s))
    float nn     = math.sum(noise, l)
    float er     = nn != 0 ? signal / nn : 0.0
    float sc     = math.pow(er * (0.666 - 0.0645) + 0.0645, 2)
    float k      = na
    k := nz(k[1], s) + sc * (s - nz(k[1], s))
    k
 
f_t3(float s, int l) =>
    float e1 = ta.ema(s, l)
    float e2 = ta.ema(e1, l)
    float e3 = ta.ema(e2, l)
    float e4 = ta.ema(e3, l)
    float e5 = ta.ema(e4, l)
    float e6 = ta.ema(e5, l)
    float b  = 0.7
    float c1 = -b * b * b
    float c2 = 3 * b * b + 3 * b * b * b
    float c3 = -6 * b * b - 3 * b - 3 * b * b * b
    float c4 = 1 + 3 * b + b * b * b + 3 * b * b
    c1 * e6 + c2 * e5 + c3 * e4 + c4 * e3
 
f_ma(string t, float s, int l) =>
    float e     = ta.ema(s, l)
    float ee    = ta.ema(e, l)
    float eee   = ta.ema(ee, l)
    float vSMA  = ta.sma(s, l)
    float vWMA  = ta.wma(s, l)
    float vDEMA = 2 * e - ee
    float vTEMA = 3 * (e - ee) + eee
    float vTRI  = ta.sma(ta.sma(s, math.ceil(l / 2.0)), math.floor(l / 2.0) + 1)
    float vKAMA = f_kama(s, l)
    float vT3   = f_t3(s, l)
    t == "EMA" ? e : t == "DEMA" ? vDEMA : t == "TEMA" ? vTEMA : t == "WMA" ? vWMA : t == "TRIMA" ? vTRI : t == "KAMA" ? vKAMA : t == "T3" ? vT3 : vSMA
 
// ───────────────────────── Yardımcı fonksiyonlar ─────────────────────────
f_fmt(float v) =>
    na(v) ? "—" : str.tostring(v, format.mintick)
 
f_rr(float r) =>
    na(r) ? "—" : "1:" + str.tostring(r, "#.##")
 
f_tierTxt(int t) =>
    t == 2 ? " ✦✦" : t == 1 ? " ✦" : ""
 
f_clear(array<line> ls, array<label> lbs) =>
    while array.size(ls) > 0
        line.delete(array.pop(ls))
    while array.size(lbs) > 0
        label.delete(array.pop(lbs))
    true
 
f_lvl(float y, color c, string tag, int x1, int x2, string st) =>
    line  ln = line.new(x1, y, x2, y, color = c, width = 1, style = st)
    label lb = label.new(x2, y, tag + "  " + str.tostring(y, format.mintick), style = label.style_label_left, color = color.new(c, 100), textcolor = c, size = size.tiny)
    [ln, lb]
 
f_draw(float en, float sl, float t1, float t2, array<line> ls, array<label> lbs) =>
    if onlyLast
        f_clear(ls, lbs)
    int x2 = bar_index + lvlLen
    [a0, b0] = f_lvl(en, colNeu, f_t("Giriş", "Entry"), bar_index, x2, line.style_dotted)
    ls.push(a0)
    lbs.push(b0)
    [a1, b1] = f_lvl(sl, cStop, "Stop", bar_index, x2, line.style_solid)
    ls.push(a1)
    lbs.push(b1)
    if not na(t1)
        [a2, b2] = f_lvl(t1, cTgt, f_tg("H1"), bar_index, x2, line.style_dashed)
        ls.push(a2)
        lbs.push(b2)
    [a3, b3] = f_lvl(t2, cTgt, f_tg("H2"), bar_index, x2, line.style_solid)
    ls.push(a3)
    lbs.push(b3)
    true
 
f_cell(table t, int c, int r, string txt, color tc) =>
    table.cell(t, c, r, txt, text_color = tc, text_size = size.small, text_halign = c == 0 ? text.align_left : text.align_right, bgcolor = color.new(cBg, 100))
 
// ───────────────────────── Keltner kanalı ─────────────────────────
float mid    = f_ma(maType, src, maLen)
float rng    = f_ma(atrType, ta.tr(true), atrLen)
float topIn  = mid + rng * multIn
float topOut = mid + rng * multOut
float botIn  = mid - rng * multIn
float botOut = mid - rng * multOut
 
// Sinyal bandı (%B)
float dev  = bbMult * ta.stdev(src, bbLen)
float bUp  = mid + dev
float bLo  = mid - dev
float pctB = (bUp - bLo) != 0 ? (close - bLo) / (bUp - bLo) : 0.5
float atrS = ta.atr(14)
 
// ───────────────────────── Trend ─────────────────────────
bool  slopeUp = mid > mid[slopeLen]
bool  slopeDn = mid < mid[slopeLen]
float htfE    = request.security(syminfo.tickerid, htfTF, ta.ema(close, htfLen)[1], lookahead = barmerge.lookahead_on)
float htfC    = request.security(syminfo.tickerid, htfTF, close[1], lookahead = barmerge.lookahead_on)
bool  htfUp   = htfC > htfE
bool  htfDn   = htfC < htfE
float emaL    = ta.ema(close, trendLen)
bool  longUp  = emaL > emaL[trendSlp]
bool  longDn  = emaL < emaL[trendSlp]
bool  trendUp = trendMode == "Uzun EMA" ? longUp : trendMode == "Üst Zaman Dilimi" ? htfUp : true
bool  trendDn = trendMode == "Uzun EMA" ? longDn : trendMode == "Üst Zaman Dilimi" ? htfDn : true
 
// ───────────────────────── WaveTrend ─────────────────────────
float ap   = hlc3
float esa  = ta.ema(ap, wtN1)
float dd   = ta.ema(math.abs(ap - esa), wtN1)
float ci   = dd != 0 ? (ap - esa) / (0.015 * dd) : 0.0
float wt1  = ta.ema(ci, wtN2)
float wt2  = ta.sma(wt1, wtSig)
bool  wtXu = ta.crossover(wt1, wt2)
bool  wtXd = ta.crossunder(wt1, wt2)
int   bsUp = ta.barssince(wtXu)
int   bsDn = ta.barssince(wtXd)
float wtLo = ta.lowest(wt2, wtLook)
float wtHi = ta.highest(wt2, wtLook)
// Dinamik eşikler
float wtOSd = ta.percentile_linear_interpolation(wt2, wtPctLen, wtPct)
float wtOBd = ta.percentile_linear_interpolation(wt2, wtPctLen, 100 - wtPct)
float osLim = thrMode == "Dinamik" ? math.min(nz(wtOSd, wtOS), -wtFloor) : wtOS
float obLim = thrMode == "Dinamik" ? math.max(nz(wtOBd, wtOB), wtFloor) : wtOB
 
// Rejim (trend / yatay)
float erNum = math.abs(close - close[erLen])
float erDen = math.sum(math.abs(close - close[1]), erLen)
float erRaw = erDen != 0 ? erNum / erDen : 0.0
float erVal = ta.sma(erRaw, 3)
[diP, diM, adxV] = ta.dmi(adxLen, adxLen)
bool   isTrend = regMode == "Verimlilik Oranı" ? erVal >= erTh : adxV >= adxTh
string effMode = wtMode == "Otomatik" ? (isTrend ? "Kesişim" : "Aşırı Bölge") : wtMode
 
bool  wtOsB = wtLo <= osLim
bool  wtObS = wtHi >= obLim
bool  wtXB  = not na(bsUp) and bsUp <= wtLook
bool  wtXS  = not na(bsDn) and bsDn <= wtLook
bool  okWTB = effMode == "Kapalı" ? true : effMode == "Aşırı Bölge" ? wtOsB : effMode == "Kesişim" ? wtXB : (wtOsB or wtXB)
bool  okWTS = effMode == "Kapalı" ? true : effMode == "Aşırı Bölge" ? wtObS : effMode == "Kesişim" ? wtXS : (wtObS or wtXS)
 
// ───────────────────────── WT uyumsuzluk ─────────────────────────
float wtSwL  = ta.lowest(wt2, divLook)
float wtSwH  = ta.highest(wt2, divLook)
float prSwL  = ta.lowest(low, divLook)
float prSwH  = ta.highest(high, divLook)
int   prSwLb = bar_index + ta.lowestbars(low, divLook)
int   prSwHb = bar_index + ta.highestbars(high, divLook)
 
var float pBullWt  = na
var float pBullPr  = na
var int   pBullBar = na
var float pBearWt  = na
var float pBearPr  = na
var int   pBearBar = na
var int   lastBullDiv = na
var int   lastBearDiv = na
 
if wtXu and wtSwL <= -divLvl
    if not na(pBullBar) and prSwLb > pBullBar and prSwLb - pBullBar <= divMaxDist and prSwL < pBullPr and wtSwL > pBullWt
        lastBullDiv := bar_index
        if showDivLn and effDiv != "Kapalı"
            line.new(pBullBar, pBullPr, prSwLb, prSwL, color = color.new(colBuy, 25), width = 1, style = line.style_dashed)
    pBullWt  := wtSwL
    pBullPr  := prSwL
    pBullBar := prSwLb
 
if wtXd and wtSwH >= divLvl
    if not na(pBearBar) and prSwHb > pBearBar and prSwHb - pBearBar <= divMaxDist and prSwH > pBearPr and wtSwH < pBearWt
        lastBearDiv := bar_index
        if showDivLn and effDiv != "Kapalı"
            line.new(pBearBar, pBearPr, prSwHb, prSwH, color = color.new(colSell, 25), width = 1, style = line.style_dashed)
    pBearWt  := wtSwH
    pBearPr  := prSwH
    pBearBar := prSwHb
 
bool divB   = effDiv != "Kapalı" and not na(lastBullDiv) and bar_index - lastBullDiv <= divValid
bool divS   = effDiv != "Kapalı" and not na(lastBearDiv) and bar_index - lastBearDiv <= divValid
bool okDivB = effDiv == "Zorunlu onay" ? divB : true
bool okDivS = effDiv == "Zorunlu onay" ? divS : true
 
// ───────────────────────── Dönüş takibi ─────────────────────────
var float exLow   = na
var float exHigh  = na
var int   exTierB = 0
var int   exTierS = 0
var float supLvl  = na
var float resLvl  = na
 
bool  buyRaw    = ta.crossover(pctB, osLvl)
bool  sellRaw   = ta.crossunder(pctB, obLvl)
float swingLow  = math.min(nz(exLow, low[1]), low)
float swingHigh = math.max(nz(exHigh, high[1]), high)
int   tierB     = exTierB
int   tierS     = exTierS
 
if buyRaw
    supLvl  := swingLow
    exLow   := na
    exTierB := 0
if sellRaw
    resLvl  := swingHigh
    exHigh  := na
    exTierS := 0
 
if pctB < osLvl
    exLow   := na(exLow) ? low : math.min(exLow, low)
    exTierB := math.max(exTierB, low <= botOut ? 2 : low <= botIn ? 1 : 0)
if pctB > obLvl
    exHigh  := na(exHigh) ? high : math.max(exHigh, high)
    exTierS := math.max(exTierS, high >= topOut ? 2 : high >= topIn ? 1 : 0)
 
// ───────────────────────── Filtreli sinyal ─────────────────────────
int minTierN = effTier == "KC Dış Bant" ? 2 : effTier == "KC İç Bant" ? 1 : 0
int maxTierN = effTier == "Dış bant hariç" ? 1 : 2
 
var int lastBuyBar  = na
var int lastSellBar = na
bool cdB    = na(lastBuyBar) or bar_index - lastBuyBar > cooldown
bool cdS    = na(lastSellBar) or bar_index - lastSellBar > cooldown
bool confOK = not confOnly or barstate.isconfirmed
 
bool buySig  = buyRaw and tierB >= minTierN and tierB <= maxTierN and trendUp and okWTB and okDivB and cdB and confOK
bool sellSig = sellRaw and tierS >= minTierN and tierS <= maxTierN and trendDn and okWTS and okDivS and cdS and confOK
 
// Son sinyal bilgisi
var int   sigDir   = 0
var int   sigTier  = 0
var int   sigBar   = na
var float sigEntry = na
var float sigSL    = na
var float sigT1    = na
var float sigT2    = na
var float sigRR    = na
var bool  sigDiv   = false
var string sigKind = ""
 
var array<line>  lvLines  = array.new<line>()
var array<label> lvLabels = array.new<label>()
 
// ───────────────────────── İstatistik altyapısı ─────────────────────────
// Ayrık kategoriler: 0 Dönüş · 1 Dönüş ✦✦ · 2 ⚡ Uyumsuzluk · 3 ↺ Geri çekilme · 4 ↺ ⚠ Uyarılı
// Her sinyal H1 ve H2 için ayrı ayrı izlenir. Gizlenen sinyaller de izlenir.
var array<int>   tDir  = array.new<int>()
var array<float> tEn   = array.new<float>()
var array<float> tSl   = array.new<float>()
var array<float> tTg1  = array.new<float>()
var array<float> tTg2  = array.new<float>()
var array<bool>  tOk1  = array.new<bool>()
var array<bool>  tOk2  = array.new<bool>()
var array<int>   tCat  = array.new<int>()
var array<int>   tBar  = array.new<int>()
var array<int>   stN   = array.new<int>(5, 0)
var array<int>   stW1  = array.new<int>(5, 0)
var array<int>   stL1  = array.new<int>(5, 0)
var array<int>   stT1  = array.new<int>(5, 0)
var array<float> stR1  = array.new<float>(5, 0.0)
var array<int>   stW2  = array.new<int>(5, 0)
var array<int>   stL2  = array.new<int>(5, 0)
var array<int>   stT2  = array.new<int>(5, 0)
var array<float> stR2  = array.new<float>(5, 0.0)
 
f_inc(array<int> a, int c) =>
    a.set(c, a.get(c) + 1)
    true
 
f_push(int d, float en, float sl, float t1, float t2, int c) =>
    if barstate.isconfirmed and not na(sl) and not na(t2) and math.abs(en - sl) > 0
        tDir.push(d)
        tEn.push(en)
        tSl.push(sl)
        tTg1.push(nz(t1, t2))
        tTg2.push(t2)
        tOk1.push(false)
        tOk2.push(false)
        tCat.push(c)
        tBar.push(bar_index)
        f_inc(stN, c)
    true
 
f_add(array<int> w, array<int> l, array<int> t, array<float> rs, int cat, int res, float r) =>
    if res == 1
        f_inc(w, cat)
        rs.set(cat, rs.get(cat) + r)
    else if res == -1
        f_inc(l, cat)
        rs.set(cat, rs.get(cat) - 1.0)
    else
        f_inc(t, cat)
    true
 
f_n(array<int> w, array<int> l, int c) =>
    w.get(c) + l.get(c)
 
f_ev(array<int> w, array<int> l, array<float> rs, int c) =>
    int n = w.get(c) + l.get(c)
    n > 0 ? rs.get(c) / n : na
 
// Otomatik profil: tür gösterilsin mi? (yeterli sonuç yoksa gösterilir)
f_gate(int c) =>
    float e1 = f_ev(stW1, stL1, stR1, c)
    float e2 = f_ev(stW2, stL2, stR2, c)
    not isAuto or f_n(stW1, stL1, c) < autoMin or math.max(nz(e1, -9.0), nz(e2, -9.0)) > autoTh
 
// Otomatik profil: bu tür için H2 daha mı iyi?
f_bestH2(int c) =>
    float e1 = f_ev(stW1, stL1, stR1, c)
    float e2 = f_ev(stW2, stL2, stR2, c)
    f_n(stW2, stL2, c) >= autoMin and nz(e2, -9.0) > nz(e1, -9.0)
 
f_catRev(int tier, bool dv) =>
    dv ? 2 : tier == 2 ? 1 : 0
 
bool   buyShow    = false
bool   sellShow   = false
bool   pbBuyShow  = false
bool   pbSellShow = false
string autoTgt    = ""
 
if buySig
    lastBuyBar := bar_index
    float  en = close
    float  sl = swingLow - atrS * stopBuf
    float  t1 = mid > en ? mid : na
    float  t2 = topIn
    float  rk = en - sl
    int    c  = f_catRev(tierB, divB)
    string bt = isAuto ? (f_bestH2(c) ? "H2" : "H1") : ""
    float  tg = bt == "H1" ? nz(t1, t2) : t2
    bool   ok = f_gate(c)
    f_push(1, en, sl, t1, t2, c)
    if ok
        buyShow  := true
        autoTgt  := bt
        sigDir   := 1
        sigTier  := tierB
        sigDiv   := divB
        sigKind  := ""
        sigBar   := bar_index
        sigEntry := en
        sigSL    := sl
        sigT1    := t1
        sigT2    := t2
        sigRR    := rk > 0 ? (tg - en) / rk : na
        string tip = f_t("AL", "BUY") + f_tierTxt(tierB) + (divB ? " ⚡" : "") + f_t("\nUyumsuzluk: ", "\nDivergence: ") + (divB ? f_t("boğa ⚡", "bull ⚡") : f_t("yok", "none")) + f_t("\nGiriş: ", "\nEntry: ") + f_fmt(en) + "\nStop: " + f_fmt(sl) + f_t("\nH1: ", "\nT1: ") + f_fmt(t1) + f_t("\nH2: ", "\nT2: ") + f_fmt(t2) + f_t("\nR/Ö: ", "\nR/R: ") + f_rr(sigRR) + (bt != "" ? f_t("\nOto hedef: ", "\nAuto target: ") + f_tg(bt) : "")
        label.new(bar_index, low, f_t("AL", "BUY") + f_tierTxt(tierB) + (divB ? " ⚡" : ""), yloc = yloc.belowbar, style = label.style_label_up, color = color.new(colBuy, 80), textcolor = colBuy, size = size.small, tooltip = tip)
        if showLvls
            f_draw(en, sl, t1, t2, lvLines, lvLabels)
    else if showRaw
        label.new(bar_index, low, "•", yloc = yloc.belowbar, style = label.style_none, textcolor = color.new(colBuy, 40), size = size.normal, tooltip = f_t("Otomatik profil gizledi: bu sinyal türü bu grafikte kazandırmıyor", "Hidden by Auto profile: this signal type is not profitable on this chart"))
 
if sellSig
    lastSellBar := bar_index
    float  en = close
    float  sl = swingHigh + atrS * stopBuf
    float  t1 = mid < en ? mid : na
    float  t2 = botIn
    float  rk = sl - en
    int    c  = f_catRev(tierS, divS)
    string bt = isAuto ? (f_bestH2(c) ? "H2" : "H1") : ""
    float  tg = bt == "H1" ? nz(t1, t2) : t2
    bool   ok = f_gate(c)
    f_push(-1, en, sl, t1, t2, c)
    if ok
        sellShow := true
        autoTgt  := bt
        sigDir   := -1
        sigTier  := tierS
        sigDiv   := divS
        sigKind  := ""
        sigBar   := bar_index
        sigEntry := en
        sigSL    := sl
        sigT1    := t1
        sigT2    := t2
        sigRR    := rk > 0 ? (en - tg) / rk : na
        string tip = f_t("SAT", "SELL") + f_tierTxt(tierS) + (divS ? " ⚡" : "") + f_t("\nUyumsuzluk: ", "\nDivergence: ") + (divS ? f_t("ayı ⚡", "bear ⚡") : f_t("yok", "none")) + f_t("\nGiriş: ", "\nEntry: ") + f_fmt(en) + "\nStop: " + f_fmt(sl) + f_t("\nH1: ", "\nT1: ") + f_fmt(t1) + f_t("\nH2: ", "\nT2: ") + f_fmt(t2) + f_t("\nR/Ö: ", "\nR/R: ") + f_rr(sigRR) + (bt != "" ? f_t("\nOto hedef: ", "\nAuto target: ") + f_tg(bt) : "")
        label.new(bar_index, high, f_t("SAT", "SELL") + f_tierTxt(tierS) + (divS ? " ⚡" : ""), yloc = yloc.abovebar, style = label.style_label_down, color = color.new(colSell, 80), textcolor = colSell, size = size.small, tooltip = tip)
        if showLvls
            f_draw(en, sl, t1, t2, lvLines, lvLabels)
    else if showRaw
        label.new(bar_index, high, "•", yloc = yloc.abovebar, style = label.style_none, textcolor = color.new(colSell, 40), size = size.normal, tooltip = f_t("Otomatik profil gizledi: bu sinyal türü bu grafikte kazandırmıyor", "Hidden by Auto profile: this signal type is not profitable on this chart"))
 
// ───────────────────────── Geri çekilme sinyali (↺) ─────────────────────────
float trStr    = atrS > 0 ? math.abs(emaL - emaL[trendSlp]) / atrS : na
bool  pbStrong = pbStr == 0 or (not na(trStr) and trStr >= pbStr)
bool  vetoB    = pbVMode != "Kapalı" and not na(lastBearDiv) and bar_index - lastBearDiv <= pbVeto
bool  vetoS    = pbVMode != "Kapalı" and not na(lastBullDiv) and bar_index - lastBullDiv <= pbVeto
bool  warnB    = pbVMode == "Uyar" and vetoB
bool  warnS    = pbVMode == "Uyar" and vetoS
bool  pbTrUp   = trendMode == "Üst Zaman Dilimi" ? htfUp : longUp
bool  pbTrDn   = trendMode == "Üst Zaman Dilimi" ? htfDn : longDn
float zoneS    = pbZone == "İç bant" ? topIn : mid
float zoneB    = pbZone == "İç bant" ? botIn : mid
float pbHi     = ta.highest(high, pbLook)
float pbLo     = ta.lowest(low, pbLook)
bool  pbFreshS = high >= mid or close[1] >= mid[1]
bool  pbFreshB = low <= mid or close[1] <= mid[1]
 
var int lastPbBuy  = na
var int lastPbSell = na
bool cdPbB = na(lastPbBuy) or bar_index - lastPbBuy > pbCd
bool cdPbS = na(lastPbSell) or bar_index - lastPbSell > pbCd
 
bool pbBuy  = effPb and pbTrUp and pbLo <= zoneB and pbFreshB and close > mid and close > open and (not pbWT or wt1 > wt2) and pbStrong and not (pbVMode == "Engelle" and vetoB) and cdPbB and confOK and not buySig
bool pbSell = effPb and pbTrDn and pbHi >= zoneS and pbFreshS and close < mid and close < open and (not pbWT or wt1 < wt2) and pbStrong and not (pbVMode == "Engelle" and vetoS) and cdPbS and confOK and not sellSig
 
if pbBuy
    lastPbBuy := bar_index
    float  en = close
    float  sl = math.min(pbLo, low) - atrS * stopBuf
    float  t1 = topIn > en ? topIn : na
    float  t2 = topOut
    float  rk = en - sl
    int    c  = warnB ? 4 : 3
    string bt = isAuto ? (f_bestH2(c) ? "H2" : "H1") : ""
    float  tg = bt == "H1" ? nz(t1, t2) : t2
    bool   ok = f_gate(c)
    f_push(1, en, sl, t1, t2, c)
    if ok
        pbBuyShow := true
        autoTgt  := bt
        sigDir   := 1
        sigKind  := warnB ? "↺ ⚠" : "↺"
        sigTier  := 0
        sigDiv   := false
        sigBar   := bar_index
        sigEntry := en
        sigSL    := sl
        sigT1    := t1
        sigT2    := t2
        sigRR    := rk > 0 ? (tg - en) / rk : na
        string tip = f_t("AL ↺ (trend içi geri çekilme)", "BUY ↺ (in-trend pullback)") + (warnB ? f_t("\n⚠ Yakın zamanda ayı uyumsuzluğu var", "\n⚠ Recent bearish divergence") : "") + f_t("\nGiriş: ", "\nEntry: ") + f_fmt(en) + "\nStop: " + f_fmt(sl) + f_t("\nH1: ", "\nT1: ") + f_fmt(t1) + f_t("\nH2: ", "\nT2: ") + f_fmt(t2) + f_t("\nR/Ö: ", "\nR/R: ") + f_rr(sigRR) + (bt != "" ? f_t("\nOto hedef: ", "\nAuto target: ") + f_tg(bt) : "")
        label.new(bar_index, low, f_t("↺ AL", "↺ BUY") + (warnB ? " ⚠" : ""), yloc = yloc.belowbar, style = label.style_label_up, color = color.new(colBuy, 92), textcolor = color.new(colBuy, 10), size = size.small, tooltip = tip)
        if showLvls
            f_draw(en, sl, t1, t2, lvLines, lvLabels)
    else if showRaw
        label.new(bar_index, low, "•", yloc = yloc.belowbar, style = label.style_none, textcolor = color.new(colBuy, 40), size = size.normal, tooltip = f_t("Otomatik profil gizledi: bu ↺ türü bu grafikte kazandırmıyor", "Hidden by Auto profile: this ↺ type is not profitable on this chart"))
 
if pbSell
    lastPbSell := bar_index
    float  en = close
    float  sl = math.max(pbHi, high) + atrS * stopBuf
    float  t1 = botIn < en ? botIn : na
    float  t2 = botOut
    float  rk = sl - en
    int    c  = warnS ? 4 : 3
    string bt = isAuto ? (f_bestH2(c) ? "H2" : "H1") : ""
    float  tg = bt == "H1" ? nz(t1, t2) : t2
    bool   ok = f_gate(c)
    f_push(-1, en, sl, t1, t2, c)
    if ok
        pbSellShow := true
        autoTgt  := bt
        sigDir   := -1
        sigKind  := warnS ? "↺ ⚠" : "↺"
        sigTier  := 0
        sigDiv   := false
        sigBar   := bar_index
        sigEntry := en
        sigSL    := sl
        sigT1    := t1
        sigT2    := t2
        sigRR    := rk > 0 ? (en - tg) / rk : na
        string tip = f_t("SAT ↺ (trend içi geri çekilme)", "SELL ↺ (in-trend pullback)") + (warnS ? f_t("\n⚠ Yakın zamanda boğa uyumsuzluğu var", "\n⚠ Recent bullish divergence") : "") + f_t("\nGiriş: ", "\nEntry: ") + f_fmt(en) + "\nStop: " + f_fmt(sl) + f_t("\nH1: ", "\nT1: ") + f_fmt(t1) + f_t("\nH2: ", "\nT2: ") + f_fmt(t2) + f_t("\nR/Ö: ", "\nR/R: ") + f_rr(sigRR) + (bt != "" ? f_t("\nOto hedef: ", "\nAuto target: ") + f_tg(bt) : "")
        label.new(bar_index, high, f_t("↺ SAT", "↺ SELL") + (warnS ? " ⚠" : ""), yloc = yloc.abovebar, style = label.style_label_down, color = color.new(colSell, 92), textcolor = color.new(colSell, 10), size = size.small, tooltip = tip)
        if showLvls
            f_draw(en, sl, t1, t2, lvLines, lvLabels)
    else if showRaw
        label.new(bar_index, high, "•", yloc = yloc.abovebar, style = label.style_none, textcolor = color.new(colSell, 40), size = size.normal, tooltip = f_t("Otomatik profil gizledi: bu ↺ türü bu grafikte kazandırmıyor", "Hidden by Auto profile: this ↺ type is not profitable on this chart"))
 
// ───────────────────────── Sinyal sonuçlarını izle ─────────────────────────
if barstate.isconfirmed and tEn.size() > 0
    for i = tEn.size() - 1 to 0
        int b = tBar.get(i)
        if bar_index > b
            int   d    = tDir.get(i)
            float en   = tEn.get(i)
            float sl   = tSl.get(i)
            int   c    = tCat.get(i)
            bool  lossHit = d == 1 ? low <= sl : high >= sl
            bool  tOut = bar_index - b >= statMax
            float rk   = math.abs(en - sl)
            if not tOk1.get(i)
                float tg  = tTg1.get(i)
                bool  win = d == 1 ? high >= tg : low <= tg
                int   res = lossHit ? -1 : win ? 1 : tOut ? 0 : 2
                if res != 2
                    f_add(stW1, stL1, stT1, stR1, c, res, math.abs(tg - en) / rk)
                    tOk1.set(i, true)
            if not tOk2.get(i)
                float tg  = tTg2.get(i)
                bool  win = d == 1 ? high >= tg : low <= tg
                int   res = lossHit ? -1 : win ? 1 : tOut ? 0 : 2
                if res != 2
                    f_add(stW2, stL2, stT2, stR2, c, res, math.abs(tg - en) / rk)
                    tOk2.set(i, true)
            if tOk1.get(i) and tOk2.get(i)
                tDir.remove(i)
                tEn.remove(i)
                tSl.remove(i)
                tTg1.remove(i)
                tTg2.remove(i)
                tOk1.remove(i)
                tOk2.remove(i)
                tCat.remove(i)
                tBar.remove(i)
 
// ───────────────────────── Çizimler (neon minimal) ─────────────────────────
color cMid = slopeUp ? colBuy : slopeDn ? colSell : colNeu
 
plot(mid, "Orta · parlama", color = showGlow ? color.new(cMid, 85) : na, linewidth = 4, display = display.pane)
plot(mid, "Orta çizgi", color = color.new(cMid, 15), linewidth = 1, display = display.pane)
 
plot(topOut, "Üst dış · parlama", color = showGlow ? color.new(colSell, 88) : na, linewidth = 4, display = display.pane)
pTopOut = plot(topOut, "Üst dış bant", color = color.new(colSell, 35), linewidth = 1, display = display.pane)
pTopIn  = plot(topIn, "Üst iç bant", color = color.new(colSell, 70), linewidth = 1, display = display.pane)
pBotIn  = plot(botIn, "Alt iç bant", color = color.new(colBuy, 70), linewidth = 1, display = display.pane)
pBotOut = plot(botOut, "Alt dış bant", color = color.new(colBuy, 35), linewidth = 1, display = display.pane)
plot(botOut, "Alt dış · parlama", color = showGlow ? color.new(colBuy, 88) : na, linewidth = 4, display = display.pane)
 
fill(pTopOut, pTopIn, topOut, topIn, showFill ? color.new(colSell, 82) : na, showFill ? color.new(colSell, 97) : na, title = "Üst bölge dolgu")
fill(pBotIn, pBotOut, botIn, botOut, showFill ? color.new(colBuy, 97) : na, showFill ? color.new(colBuy, 82) : na, title = "Alt bölge dolgu")
 
f_why(int tier, bool tr, bool wt, bool dv, bool cd, bool cf) =>
    string r = ""
    r := tier < minTierN or tier > maxTierN ? r + f_t("\n· Sinyal gücü", "\n· Signal strength") : r
    r := not tr ? r + f_t("\n· Trend filtresi", "\n· Trend filter") : r
    r := not wt ? r + f_t("\n· WaveTrend onayı", "\n· WaveTrend confirmation") : r
    r := not dv ? r + f_t("\n· Uyumsuzluk şartı", "\n· Divergence requirement") : r
    r := not cd ? r + f_t("\n· Bekleme süresi", "\n· Cooldown") : r
    r := not cf ? r + f_t("\n· Mum kapanmadı", "\n· Bar not closed") : r
    r
 
if showRaw and buyRaw and not buySig
    label.new(bar_index, low, "•", yloc = yloc.belowbar, style = label.style_none, textcolor = color.new(colBuy, 40), size = size.normal, tooltip = f_t("Elenen AL", "Filtered BUY") + f_tierTxt(tierB) + f_why(tierB, trendUp, okWTB, okDivB, cdB, confOK))
if showRaw and sellRaw and not sellSig
    label.new(bar_index, high, "•", yloc = yloc.abovebar, style = label.style_none, textcolor = color.new(colSell, 40), size = size.normal, tooltip = f_t("Elenen SAT", "Filtered SELL") + f_tierTxt(tierS) + f_why(tierS, trendDn, okWTS, okDivS, cdS, confOK))
 
bgcolor(showRegBg and isTrend ? color.new(cTgt, 96) : na, title = "Trend rejimi")
 
plot(showDots ? supLvl : na, "Destek (dönüş dibi)", color = color.new(colBuy, 45), style = plot.style_circles, linewidth = 1, display = display.pane)
plot(showDots ? resLvl : na, "Direnç (dönüş tepesi)", color = color.new(colSell, 45), style = plot.style_circles, linewidth = 1, display = display.pane)
 
// ───────────────────────── Birleşik panel (bilgi + istatistik) ─────────────────────────
string tPos = tablePos == "Sağ Üst" ? position.top_right : tablePos == "Sağ Alt" ? position.bottom_right : tablePos == "Sol Üst" ? position.top_left : position.bottom_left
var table tb = table.new(tPos, 7, 16, bgcolor = color.new(cBg, 15), border_color = color.new(colNeu, 85), border_width = 1, frame_color = color.new(colBuy, 60), frame_width = 1)
varip bool merged = false
 
bool infoOn = showPanel and showTable
bool statOn = showPanel and statShow
int  sr     = infoOn ? 9 : 0
 
f_pct(array<int> w, array<int> l, int c) =>
    int n = w.get(c) + l.get(c)
    n > 0 ? float(w.get(c)) / n * 100.0 : na
 
f_srow(int row, int c, string name) =>
    float  p1 = f_pct(stW1, stL1, c)
    float  e1 = f_ev(stW1, stL1, stR1, c)
    float  p2 = f_pct(stW2, stL2, c)
    float  e2 = f_ev(stW2, stL2, stR2, c)
    bool   meas = f_n(stW1, stL1, c) < autoMin
    string ot = not isAuto ? "—" : meas ? f_t("ölçülüyor", "measuring") : f_gate(c) ? "✓ " + f_tg(f_bestH2(c) ? "H2" : "H1") : f_t("✗ gizli", "✗ hidden")
    color  oc = not isAuto or meas ? colNeu : f_gate(c) ? colBuy : colSell
    f_cell(tb, 0, row, name, cText)
    f_cell(tb, 1, row, str.tostring(stN.get(c)), colNeu)
    f_cell(tb, 2, row, na(p1) ? "—" : str.tostring(p1, "#") + "%", na(p1) ? colNeu : p1 >= 50 ? colBuy : colSell)
    f_cell(tb, 3, row, na(e1) ? "—" : (e1 >= 0 ? "+" : "") + str.tostring(e1, "#.##") + "R", na(e1) ? colNeu : e1 >= 0 ? colBuy : colSell)
    f_cell(tb, 4, row, na(p2) ? "—" : str.tostring(p2, "#") + "%", na(p2) ? colNeu : p2 >= 50 ? colBuy : colSell)
    f_cell(tb, 5, row, na(e2) ? "—" : (e2 >= 0 ? "+" : "") + str.tostring(e2, "#.##") + "R", na(e2) ? colNeu : e2 >= 0 ? colBuy : colSell)
    f_cell(tb, 6, row, ot, oc)
    true
 
if barstate.islast and (infoOn or statOn)
    if not merged
        if infoOn
            for r = 0 to 8
                table.merge_cells(tb, 1, r, 6, r)
        if statOn
            table.merge_cells(tb, 0, sr + 6, 6, sr + 6)
        merged := true
 
    if infoOn
        bool   shUp   = trendMode == "Kapalı" ? longUp : trendUp
        bool   shDn   = trendMode == "Kapalı" ? longDn : trendDn
        string trTxt  = (shUp ? f_t("▲ Yukarı", "▲ Up") : shDn ? f_t("▼ Aşağı", "▼ Down") : f_t("— Yatay", "— Flat")) + (trendMode == "Kapalı" ? f_t(" · filtre kapalı", " · filter off") : trendMode == "Üst Zaman Dilimi" ? " · " + htfTF : " · EMA" + str.tostring(trendLen)) + (na(trStr) ? "" : " · " + str.tostring(trStr, "#.#") + " ATR")
        color  trCol  = shUp ? colBuy : shDn ? colSell : colNeu
        string wtTxt  = str.tostring(wt2, "#.#") + (wt2 <= osLim ? f_t(" · aşırı satım", " · oversold") : wt2 >= obLim ? f_t(" · aşırı alım", " · overbought") : wt1 > wt2 ? " · ▲" : " · ▼") + "  [" + str.tostring(osLim, "#") + " / " + str.tostring(obLim, "#") + "]"
        color  wtCol  = wt2 <= osLim ? colBuy : wt2 >= obLim ? colSell : cText
        string regTxt = (isTrend ? "Trend" : f_t("Yatay", "Range")) + " · " + (regMode == "Verimlilik Oranı" ? "ER " + str.tostring(erVal, "#.##") : "ADX " + str.tostring(adxV, "#.#")) + " → " + f_mode(effMode)
        color  regCol = isTrend ? cTgt : cText
        string sigTxt = sigDir == 0 ? "—" : (sigKind != "" ? sigKind + " " : "") + (sigDir == 1 ? f_t("AL", "BUY") : f_t("SAT", "SELL")) + f_tierTxt(sigTier) + (sigDiv ? " ⚡" : "") + " · " + str.tostring(bar_index - sigBar) + f_t(" mum önce", " bars ago")
        color  sigCol = sigDir == 1 ? colBuy : sigDir == -1 ? colSell : colNeu
        string stTxt  = sigDir == 0 ? "—" : f_fmt(sigSL) + "  (" + str.tostring(math.abs(sigEntry - sigSL) / sigEntry * 100, "#.##") + "%)"
        bool   bullNew = not na(lastBullDiv) and (na(lastBearDiv) or lastBullDiv >= lastBearDiv)
        string dvTxt   = effDiv == "Kapalı" ? f_t("kapalı", "off") : na(lastBullDiv) and na(lastBearDiv) ? "—" : bullNew ? f_t("Boğa ⚡ · ", "Bull ⚡ · ") + str.tostring(bar_index - lastBullDiv) + f_t(" mum önce", " bars ago") : f_t("Ayı ⚡ · ", "Bear ⚡ · ") + str.tostring(bar_index - lastBearDiv) + f_t(" mum önce", " bars ago")
        color  dvCol   = effDiv == "Kapalı" or (na(lastBullDiv) and na(lastBearDiv)) ? colNeu : bullNew ? colBuy : colSell
        f_cell(tb, 0, 0, "NEON KC", colBuy)
        f_cell(tb, 1, 0, syminfo.ticker + " · " + timeframe.period + " · " + f_prof(profile), cText)
        f_cell(tb, 0, 1, "Trend", colNeu)
        f_cell(tb, 1, 1, trTxt, trCol)
        f_cell(tb, 0, 2, f_t("Rejim", "Regime"), colNeu)
        f_cell(tb, 1, 2, regTxt, regCol)
        f_cell(tb, 0, 3, "WaveTrend", colNeu)
        f_cell(tb, 1, 3, wtTxt, wtCol)
        f_cell(tb, 0, 4, f_t("Uyumsuzluk", "Divergence"), colNeu)
        f_cell(tb, 1, 4, dvTxt, dvCol)
        f_cell(tb, 0, 5, "%B", colNeu)
        f_cell(tb, 1, 5, str.tostring(pctB, "#.##"), cText)
        f_cell(tb, 0, 6, f_t("Son sinyal", "Last signal"), colNeu)
        f_cell(tb, 1, 6, sigTxt, sigCol)
        f_cell(tb, 0, 7, "Stop", colNeu)
        f_cell(tb, 1, 7, stTxt, cStop)
        f_cell(tb, 0, 8, f_t("R/Ö", "R/R"), colNeu)
        f_cell(tb, 1, 8, f_rr(sigRR), cTgt)
 
    if statOn
        f_cell(tb, 0, sr, f_t("İSTATİSTİK", "STATISTICS"), cTgt)
        f_cell(tb, 1, sr, f_t("Sayı", "Count"), colNeu)
        f_cell(tb, 2, sr, f_t("H1 %", "T1 %"), cTgt)
        f_cell(tb, 3, sr, f_t("H1 R", "T1 R"), cTgt)
        f_cell(tb, 4, sr, f_t("H2 %", "T2 %"), cTgt)
        f_cell(tb, 5, sr, f_t("H2 R", "T2 R"), cTgt)
        f_cell(tb, 6, sr, f_t("Oto", "Auto"), cTgt)
        f_srow(sr + 1, 0, f_t("Dönüş", "Reversal"))
        f_srow(sr + 2, 1, f_t("Dönüş ✦✦", "Reversal ✦✦"))
        f_srow(sr + 3, 2, f_t("⚡ Uyumsuzluk", "⚡ Divergence"))
        f_srow(sr + 4, 3, f_t("↺ Geri çekilme", "↺ Pullback"))
        f_srow(sr + 5, 4, f_t("↺ ⚠ Uyarılı", "↺ ⚠ Warned"))
        f_cell(tb, 0, sr + 6, str.tostring(tEn.size()) + f_t(" açık sinyal · zaman aşımı ", " open signals · timeout ") + str.tostring(statMax) + f_t(" mum", " bars") + (isAuto ? f_t(" · oto: en az ", " · auto: min ") + str.tostring(autoMin) + f_t(" sonuç, eşik ", " results, threshold ") + str.tostring(autoTh, "#.##") + "R" : ""), colNeu)
 
// ───────────────────────── Alarmlar ─────────────────────────
alertcondition(buyShow, "NEON KC · AL / BUY", "NEON KC AL/BUY — {{ticker}} {{interval}} · {{close}}")
alertcondition(sellShow, "NEON KC · SAT / SELL", "NEON KC SAT/SELL — {{ticker}} {{interval}} · {{close}}")
alertcondition(pbBuyShow, "NEON KC · AL / BUY ↺", "NEON KC AL/BUY ↺ — {{ticker}} {{interval}} · {{close}}")
alertcondition(pbSellShow, "NEON KC · SAT / SELL ↺", "NEON KC SAT/SELL ↺ — {{ticker}} {{interval}} · {{close}}")
 
if dynAlert and buyShow
    alert("NEON KC · " + f_t("AL", "BUY") + f_tierTxt(sigTier) + (sigDiv ? " ⚡" : "") + " | " + syminfo.ticker + " " + timeframe.period + f_t(" | Giriş ", " | Entry ") + f_fmt(sigEntry) + " · Stop " + f_fmt(sigSL) + f_t(" · H1 ", " · T1 ") + f_fmt(sigT1) + f_t(" · H2 ", " · T2 ") + f_fmt(sigT2) + f_t(" · R/Ö ", " · R/R ") + f_rr(sigRR) + (autoTgt != "" ? f_t(" · Hedef ", " · Target ") + f_tg(autoTgt) : ""), alert.freq_once_per_bar_close)
if dynAlert and sellShow
    alert("NEON KC · " + f_t("SAT", "SELL") + f_tierTxt(sigTier) + (sigDiv ? " ⚡" : "") + " | " + syminfo.ticker + " " + timeframe.period + f_t(" | Giriş ", " | Entry ") + f_fmt(sigEntry) + " · Stop " + f_fmt(sigSL) + f_t(" · H1 ", " · T1 ") + f_fmt(sigT1) + f_t(" · H2 ", " · T2 ") + f_fmt(sigT2) + f_t(" · R/Ö ", " · R/R ") + f_rr(sigRR) + (autoTgt != "" ? f_t(" · Hedef ", " · Target ") + f_tg(autoTgt) : ""), alert.freq_once_per_bar_close)
if dynAlert and pbBuyShow
    alert("NEON KC · " + sigKind + f_t(" AL (geri çekilme) | ", " BUY (pullback) | ") + syminfo.ticker + " " + timeframe.period + f_t(" | Giriş ", " | Entry ") + f_fmt(sigEntry) + " · Stop " + f_fmt(sigSL) + f_t(" · H1 ", " · T1 ") + f_fmt(sigT1) + f_t(" · H2 ", " · T2 ") + f_fmt(sigT2) + f_t(" · R/Ö ", " · R/R ") + f_rr(sigRR) + (autoTgt != "" ? f_t(" · Hedef ", " · Target ") + f_tg(autoTgt) : ""), alert.freq_once_per_bar_close)
if dynAlert and pbSellShow
    alert("NEON KC · " + sigKind + f_t(" SAT (geri çekilme) | ", " SELL (pullback) | ") + syminfo.ticker + " " + timeframe.period + f_t(" | Giriş ", " | Entry ") + f_fmt(sigEntry) + " · Stop " + f_fmt(sigSL) + f_t(" · H1 ", " · T1 ") + f_fmt(sigT1) + f_t(" · H2 ", " · T2 ") + f_fmt(sigT2) + f_t(" · R/Ö ", " · R/R ") + f_rr(sigRR) + (autoTgt != "" ? f_t(" · Hedef ", " · Target ") + f_tg(autoTgt) : ""), alert.freq_once_per_bar_close)

← 返回列表