PROTECTED SOURCE SCRIPT

Illuminati M5 — Innovate PRO v6 (Stable, No-Error)

35
//version=6
indicator("Illuminati M5 — Innovate PRO v6 (Stable, No-Error)", overlay=true, max_labels_count=500)

//==================== INPUTS: Ana ====================
longBaseThr = input.int(4, "Long Score Base Threshold", minval=1, maxval=10)
shortBaseThr = input.int(4, "Short Score Base Threshold", minval=1, maxval=10)
showPanel = input.bool(true, "Show Panel")
showDebug = input.bool(true, "Show Debug Row")
paintBG = input.bool(true, "Paint BG by decision")
plotSignals = input.bool(true, "Plot Entry Arrows")
aggrMode = input.bool(false, "Aggressive Mode (auto relax)")
useRegime = input.bool(true, "Use Regime Filter (ADX+ER)")
useH1Penalty = input.bool(true, "Use H1 Conflict Penalty")

//==================== INPUTS: Edges & Parametreler ====================
edgeA_VolSpike = input.bool(true, "Edge A: Require Volume Spike")
edgeB_VolSpike = input.bool(false, "Edge B: Require Volume Spike")
edgeA_LongWick = input.bool(false, "Edge A: Require Long Wick")
edgeB_ATRComp = input.bool(true, "Edge B: Require ATR Compression")

volMultA = input.float(1.05, "Vol ≥ X*SMA20 (Edge A)", step=0.01)
volMultB = input.float(1.10, "Vol ≥ X*SMA20 (Edge B)", step=0.01)
minWickRB = input.float(1.10, "Min Wick/Body (Edge A)", step=0.05)
vwapZMin = input.float(0.80, "VWAP |z| min (Edge A)", step=0.05)
vwapZBand = input.float(2.20, "VWAP |z| max (band)", step=0.10)

zLen = input.int(100, "Z-Score length", minval=20)
zAbsMin = input.float(1.10, "Z-Score |z| min (Edge C)", step=0.05)
boLookback = input.int(3, "Edge B: Breakout lookback (bars)", minval=2)
atrK = input.float(1.00, "ATR ≤ K*ATR(100) (Edge B)", step=0.01)

//==================== INPUTS: Trend/Regime ====================
adxLen = input.int(14, "ADX length", minval=5)
adxThr = input.float(20,"ADX trending threshold", step=0.5)
erLen = input.int(20, "Efficiency Ratio length", minval=10)
erThr = input.float(0.30,"ER trending threshold", step=0.01)

//==================== INPUTS: EMA & HTF ====================
emaFastLen = input.int(9, "EMA fast", minval=2)
emaSlowLen = input.int(55, "EMA slow", minval=5)
h1Fast = input.int(21, "H1 EMA fast", minval=5)
h1Slow = input.int(89, "H1 EMA slow", minval=10)

//==================== CORE SERIES ====================
emaF = ta.ema(close, emaFastLen)
emaS = ta.ema(close, emaSlowLen)
momLong = emaF > emaS
momShort = emaF < emaS

vwap = ta.vwap(close)
dev = close - vwap
devStd = ta.stdev(dev, zLen)
zVWAP = devStd == 0.0 ? 0.0 : dev / devStd

m = ta.sma(close, zLen)
sd = ta.stdev(close, zLen)
zPx = sd == 0.0 ? 0.0 : (close - m) / sd

volSma = ta.sma(volume, 20)
volSpikeA = volume >= volMultA * volSma
volSpikeB = volume >= volMultB * volSma

atr14 = ta.atr(14)
atr100 = ta.sma(atr14, 100)
atrComp = atr14 <= atrK * atr100

boUp = close > ta.highest(high[1], boLookback)
boDown = close < ta.lowest(low[1], boLookback)

//==================== Custom ADX (Wilder) — ta.adx kullanmadan ====================
f_adx(len) =>
upMove = high - high[1]
downMove = low[1] - low
plusDM = (upMove > downMove and upMove > 0) ? upMove : 0.0
minusDM = (downMove > upMove and downMove > 0) ? downMove : 0.0
tr1 = high - low
tr2 = math.abs(high - close[1])
tr3 = math.abs(low - close[1])
tr = math.max(tr1, math.max(tr2, tr3))
smPlusDM = ta.rma(plusDM, len)
smMinusDM = ta.rma(minusDM, len)
smTR = ta.rma(tr, len)
plusDI = 100.0 * smPlusDM / math.max(smTR, 1e-10)
minusDI = 100.0 * smMinusDM / math.max(smTR, 1e-10)
dx = 100.0 * math.abs(plusDI - minusDI) / math.max(plusDI + minusDI, 1e-10)
ta.rma(dx, len)

adxVal = f_adx(adxLen)

//==================== Efficiency Ratio — ta.sum olmadan ====================
f_sumAbs(len) =>
float s = 0.0
for i = 0 to len - 1
s += math.abs(close - close[i+1])
s

ch = math.abs(close - close[erLen])
chDen = f_sumAbs(erLen)
er = chDen == 0.0 ? 0.0 : ch / chDen
isTrending = (adxVal > adxThr) and (er > erThr)

//==================== HTF (H1) Trend ====================
h1_fast = request.security(syminfo.tickerid, "60", ta.ema(close, h1Fast))
h1_slow = request.security(syminfo.tickerid, "60", ta.ema(close, h1Slow))
h1Up = h1_fast > h1_slow
h1Down = h1_fast < h1_slow

//==================== Adaptif Eşik ====================
volRegime = atr100 == 0.0 ? 1.0 : atr14 / atr100
adj(base, vReg) =>
base + (vReg < 0.8 ? 1 : vReg > 1.2 ? -1 : 0)
f_clamp(x, lo, hi) => math.min(math.max(x, lo), hi)
baseL = adj(longBaseThr, volRegime)
baseS = adj(shortBaseThr, volRegime)
longThr = f_clamp(aggrMode ? baseL - 1 : baseL, 1, 6)
shortThr = f_clamp(aggrMode ? baseS - 1 : baseS, 1, 6)

//==================== Likidite Avı (Wick + HH/LL + VWAP/Vol) ====================
body = math.max(math.abs(close - open), syminfo.mintick)
uWick = high - math.max(close, open)
lWick = math.min(close, open) - low
uwRB = uWick / body
lwRB = lWick / body

look = 20
prevHigh = ta.highest(high[1], look)
prevLow = ta.lowest(low[1], look)
sweepUp = high > prevHigh and close < prevHigh
sweepDown = low < prevLow and close > prevLow

trapUp = sweepUp and (uwRB >= minWickRB) and (volSpikeA or volSpikeB) and (math.abs(zVWAP) >= vwapZMin)
trapDown = sweepDown and (lwRB >= minWickRB) and (volSpikeA or volSpikeB) and (math.abs(zVWAP) >= vwapZMin)

//==================== Skor Sistemi ====================
int longScore = 0
int shortScore = 0

longScore += momLong ? 1 : 0
longScore += close > vwap ? 1 : 0
longScore += (math.abs(zPx) >= zAbsMin and zPx > 0) ? 1 : 0
longScore += boUp ? 1 : 0

shortScore += momShort ? 1 : 0
shortScore += close < vwap ? 1 : 0
shortScore += (math.abs(zPx) >= zAbsMin and zPx < 0) ? 1 : 0
shortScore += boDown ? 1 : 0

// Edge gereksinimleri
if edgeA_VolSpike and not volSpikeA
longScore := 0
if edgeB_VolSpike and not volSpikeB
shortScore := 0
if edgeA_LongWick and (uwRB < minWickRB and lwRB < minWickRB)
// uzun fitil gerekliyse ve yoksa, ek katkı yok (skoru sıfırlamıyoruz)
na

// ATR sıkışma şartı yoksa breakout gücünü azalt
if edgeB_ATRComp and not atrComp
longScore -= boUp ? 1 : 0
shortScore -= boDown ? 1 : 0

// Hibrit: Vol Spike + ATR Compression
hybridEdge = ((edgeA_VolSpike and volSpikeA) or (edgeB_VolSpike and volSpikeB)) and (edgeB_ATRComp and atrComp)
if hybridEdge
longScore += 2
shortScore += 2

// Rejim filtresi
if useRegime
if isTrending
longScore += momLong ? 1 : 0
shortScore += momShort ? 1 : 0
else
longScore -= (boUp and not (momLong or close > vwap)) ? 1 : 0
shortScore -= (boDown and not (momShort or close < vwap)) ? 1 : 0

// H1 cezası
if useH1Penalty
longScore -= h1Down ? 1 : 0
shortScore -= h1Up ? 1 : 0

// Likidite avı yönlendirmesi
if trapDown
longScore += 2
shortScore -= 1
if trapUp
shortScore += 2
longScore -= 1

longScore := math.max(0, longScore)
shortScore := math.max(0, shortScore)

//==================== Karar & Plot ====================
goLong = longScore >= longThr and longScore > shortScore
goShort = shortScore >= shortThr and shortScore > longScore
noTrade = not goLong and not goShort

bgcolor(paintBG ? (goLong ? color.new(color.green,85) : goShort ? color.new(color.red,85) : color.new(color.gray,90)) : na)
plotshape(plotSignals and goLong, "LONG", shape.triangleup, location.belowbar, size=size.tiny, text="L", color=color.green)
plotshape(plotSignals and goShort, "SHORT", shape.triangledown, location.abovebar, size=size.tiny, text="S", color=color.red)

//==================== PANEL (4 sütun güvenli, clear kullanmadan) ====================
var table t = table.new(position.top_right, 4, 10, border_width=1)

// Panel başlangıcı
if barstate.islast and showPanel
// Row 0
table.cell(t, 0, 0, "Regime")

// Ternary ve renkleri değişkene al
statusText = isTrending ? "Trending" : "Ranging"
statusBg = isTrending ? color.new(color.green, 70) : color.new(color.orange, 70)

// Tek satırda, eksiksiz çağrı
table.cell(t, 1, 0, statusText, text_color=color.white, bgcolor=statusBg)

table.cell(t, 2, 0, "ADX")
table.cell(t, 3, 0, str.tostring(adxVal, format.mintick))


// Row 1
table.cell(t, 0, 1, "Efficiency")
table.cell(t, 1, 1, str.tostring(er, format.mintick))
table.cell(t, 2, 1, "ATR Reg.")
table.cell(t, 3, 1, str.tostring(volRegime, format.mintick))

// Row 2
table.cell(t, 0, 2, "LongScore")
table.cell(t, 1, 2, str.tostring(longScore))
table.cell(t, 2, 2, "Thr")
table.cell(t, 3, 2, str.tostring(longThr))

// Row 3
table.cell(t, 0, 3, "ShortScore")
table.cell(t, 1, 3, str.tostring(shortScore))
table.cell(t, 2, 3, "Thr")
table.cell(t, 3, 3, str.tostring(shortThr))

// Row 4
table.cell(t, 0, 4, "Hybrid Edge")
table.cell(t, 1, 4, hybridEdge ? "ON" : "OFF", bgcolor=hybridEdge ? color.new(color.teal,70) : na)
table.cell(t, 2, 4, "Trap U/D")
table.cell(t, 3, 4, (trapUp ? "▲" : "-") + " / " + (trapDown ? "▼" : "-"))

// Row 5 — Decision line
string dLong = goLong ? "LONG ✅" : "Long"
string dShort = goShort ? "SHORT ✅" : "Short"
string dNT = noTrade ? "NO TRADE ✅" : "No Trade"
string dLiq = (trapUp or trapDown) ? "Likidite Avı ✅" : "Likidite Avı"
table.cell(t, 0, 5, dLong, bgcolor=goLong ? color.new(color.green,70) : na)
table.cell(t, 1, 5, dShort, bgcolor=goShort ? color.new(color.red,70) : na)
table.cell(t, 2, 5, dNT, bgcolor=noTrade ? color.new(color.gray,70) : na)
table.cell(t, 3, 5, dLiq, bgcolor=(trapUp or trapDown) ? color.new(color.yellow,60) : na)

// Row 6–9 (Debug)
if showDebug
table.cell(t, 0, 6, "zVWAP / zPx")
table.cell(t, 1, 6, str.tostring(zVWAP, format.mintick))
table.cell(t, 2, 6, str.tostring(zPx, format.mintick))

table.cell(t, 0, 7, "Vol A/B")
table.cell(t, 1, 7, (volSpikeA ? "A✓" : "A×"))
table.cell(t, 2, 7, (volSpikeB ? "B✓" : "B×"))

table.cell(t, 0, 8, "ATR Comp")
table.cell(t, 1, 8, atrComp ? "ON" : "OFF")
table.cell(t, 2, 8, "")
table.cell(t, 3, 8, "")

table.cell(t, 0, 9, "H1 Up/Down")
table.cell(t, 1, 9, h1Up ? "Up" : h1Down ? "Down" : "-")
table.cell(t, 2, 9, "")
table.cell(t, 3, 9, "")

Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.