PHP Code:
// © Kinetik Komuta Merkezi - OMEGA-HUB MULTI-ENGINE MATRIX
//@version=6
strategy("OMEGA-HUB Multi-Engine Matrix", overlay=true, initial_capital=1000, commission_type=strategy.commission.percent, commission_value=0.04, max_bars_back=5000)
// ── 1. ANA SEÇÝCÝ VE GLOBAL AYARLAR ─────────────────────────────────────────
var string GRP_HUB = "🛸 OMEGA-HUB ANA KUMANDA"
strat_mode = input.string("V14.2 DayTrader", "Aktif Savaþ Doktrini", options=["V14.2 DayTrader", "AlphaTrend Matrix", "KNN Mean Reversion"], group=GRP_HUB)
tp_mult = input.float(3.0, "Hedef Dalga Çarpaný (V14.2 Ýçin R)", group=GRP_HUB)
// BIST Zaman Ayarlarý (10:00 - 17:50 arasý operasyon, 17:55 imha)
bist_tz = "Europe/Istanbul"
h = hour(time, bist_tz)
m = minute(time, bist_tz)
bool is_trade_window = (h >= 10) and (h < 17 or (h == 17 and m <= 50))
bool is_eod = (h == 17 and m >= 55) or (h >= 18)
// Global Sinyal Hafýzasý
bool global_long = false
bool global_short = false
bool global_exit_long = false
bool global_exit_short = false
// ── 2. MOTOR 1: V14.2 CYBORG-SNIPER MOTORU ──────────────────────────────────
var string GRP_V14 = "🎯 Mod 1: Cyborg-Sniper Ayarlarý"
q_ratio = input.float(0.002, "Kalman Q Sabiti", group=GRP_V14)
atrLen = input.int(14, "Kalkan ATR Periyodu", group=GRP_V14)
atrMult = input.float(1.2, "Kalkan Geniþliði", group=GRP_V14)
calc_kalman(float src, float p_state, float p_cv) =>
float q_process = 0.1 * q_ratio
float k_gain = (p_cv + q_process) / (p_cv + q_process + 1.0 + 1e-10)
float next_state = nz(p_state, src) + k_gain * (src - nz(p_state, src))
float next_cov = (1 - k_gain) * (p_cv + q_process)
[next_state, next_cov]
var float kf_state = close, var float p_cov = 1.0
[new_state, new_cov] = calc_kalman(close, kf_state, p_cov)
kf_state := new_state, p_cov := new_cov
mirror_signal = ta.ema(kf_state, 10) - ta.ema(kf_state, 20)
f_dbhf_sniper(src, l, m) =>
var float dbhf = src
float tau = ta.atr(l) * m
float diff = src - dbhf
if diff > tau
dbhf += (diff - tau) * 0.1
else if diff < -tau
dbhf += (diff + tau) * 0.1
dbhf
float kalkan = f_dbhf_sniper(hl2, atrLen, atrMult)
bool v14_long = ta.crossover(mirror_signal, 0)
bool v14_short = ta.crossunder(mirror_signal, 0)
// ── 3. MOTOR 2: ALPHATREND MOMENTUM MOTORU ──────────────────────────────────
var string GRP_AT = "⚡ Mod 2: AlphaTrend Ayarlarý"
coeff = input.float(1.0, "AlphaTrend ATR Çarpaný", step=0.1, group=GRP_AT)
AP = input.int(14, "AlphaTrend Periyodu", minval=1, group=GRP_AT)
overrideSensitivity = input.float(2.0, "Kýrýlým Hassasiyeti", step=0.1, group=GRP_AT)
float AT_ATR = ta.sma(ta.tr, AP)
float upT = low - AT_ATR * coeff
float downT = high + AT_ATR * coeff
float mfiVal = ta.mfi(hlc3, AP)
float AlphaTrend = 0.0
AlphaTrend := mfiVal >= 50 ? (upT < nz(AlphaTrend[1]) ? nz(AlphaTrend[1]) : upT) : (downT > nz(AlphaTrend[1]) ? nz(AlphaTrend[1]) : downT)
var int at_direction = 1
if AlphaTrend > AlphaTrend[2]
at_direction := 1
else if AlphaTrend < AlphaTrend[2]
at_direction := -1
bool isCrossUp = close[1] > AlphaTrend[1] and close[2] <= nz(AlphaTrend[2])
bool isCrossDn = close[1] < AlphaTrend[1] and close[2] >= nz(AlphaTrend[2])
bool _boMomentum = (math.abs(close[1] - close[2]) > AT_ATR[1] * overrideSensitivity)
if _boMomentum and isCrossUp
at_direction := 1
else if _boMomentum and isCrossDn
at_direction := -1
bool isTrendCrossUp = AlphaTrend > AlphaTrend[2] and nz(AlphaTrend[1]) <= nz(AlphaTrend[3])
bool isTrendCrossDn = AlphaTrend < AlphaTrend[2] and nz(AlphaTrend[1]) >= nz(AlphaTrend[3])
bool buySignalk = isTrendCrossUp or (_boMomentum and isCrossUp)
bool sellSignalk = isTrendCrossDn or (_boMomentum and isCrossDn)
var int K1 = 0, var int K2 = 0
var int O1 = 0, var int O2 = 0
O1 := buySignalk[1] ? 0 : O1 + 1
O2 := sellSignalk[1] ? 0 : O2 + 1
K1 := buySignalk ? 0 : K1 + 1
K2 := sellSignalk ? 0 : K2 + 1
bool at_long = buySignalk and O1 > K2
bool at_short = sellSignalk and O2 > K1
// ── 4. MOTOR 3: KNN YAPAY ZEKA (ORTALAMAYA DÖNÜÞ) MOTORU ────────────────────
var string GRP_KNN = "🧠 Mod 3: KNN Yapay Zeka Ayarlarý"
k_val = input.int(60, "K Komþu Sayýsý", minval=5, group=GRP_KNN)
win_size = input.int(800, "Geriye Dönük Tarama Penceresi", minval=50, group=GRP_KNN)
rev_window = input.int(6, "Geri Dönüþ Vadesi", minval=1, group=GRP_KNN)
p_dist = input.float(2.0, "Minkowski p Üssü", minval=1.0, group=GRP_KNN)
gauss_bw = input.float(1.5, "Gaussian Bant Geniþliði", minval=0.1, group=GRP_KNN)
prob_thresh = input.float(0.65, "Geri Dönüþ Ýhtimal Eþiði", minval=0.3, group=GRP_KNN)
f_zscore(src, len) =>
_mu = ta.sma(src[1], len)
_sig = ta.stdev(src[1], len)
(src - _mu) / math.max(_sig, 1e-6)
basis = ta.ema(close, 20)
bb_std = ta.stdev(close, 20)
bb_upper = basis + 2.0 * bb_std
vol_ratio = volume / math.max(ta.sma(volume[1], 20), 1)
f_dist = (close - basis) / math.max(basis, 1e-6) * 100
f_bb_pos = (close - basis) / math.max(bb_upper - basis, 1e-6)
f_rsi_dev = ta.rsi(close, 14) - 50.0
f_body_cmp = math.abs(close - open) / math.max(high - low, 1e-6)
f_vol_fade = -vol_ratio
z1 = f_zscore(f_dist, win_size), z2 = f_zscore(f_bb_pos, win_size), z3 = f_zscore(f_rsi_dev, win_size)
z4 = f_zscore(f_body_cmp, win_size), z5 = f_zscore(f_vol_fade, win_size)
f_label() =>
int lbl = 0
if close[rev_window] > basis[rev_window]
bool touched = false
for j = 0 to rev_window - 1
if low[rev_window - 1 - j] <= basis[rev_window - 1 - j]
touched := true
lbl := touched ? 1 : 0
else if close[rev_window] < basis[rev_window]
bool touched = false
for j = 0 to rev_window - 1
if high[rev_window - 1 - j] >= basis[rev_window - 1 - j]
touched := true
lbl := touched ? -1 : 0
lbl
var float p_rev_above = 0.0, var float p_rev_below = 0.0
var float[] dist_arr = array.new_float(0)
var float[] label_arr = array.new_float(0)
// CPU yükünü azaltmak için sadece KNN modu seçiliyken çalýþtýrýlýr
if strat_mode == "KNN Mean Reversion" and bar_index > win_size + rev_window
array.clear(dist_arr), array.clear(label_arr)
for i = rev_window to win_size + rev_window by rev_window
float d = math.pow(math.pow(math.abs(z1 - z1[i]), p_dist) + math.pow(math.abs(z2 - z2[i]), p_dist) + math.pow(math.abs(z3 - z3[i]), p_dist) + math.pow(math.abs(z4 - z4[i]), p_dist) + math.pow(math.abs(z5 - z5[i]), p_dist), 1.0 / p_dist)
array.push(dist_arr, d), array.push(label_arr, f_label()[i])
int n_samples = array.size(dist_arr)
if n_samples >= k_val
int[] sorted_idx = array.sort_indices(dist_arr, order.ascending)
float sigma = math.max(array.get(dist_arr, array.get(sorted_idx, math.min(math.max(1, int(k_val / 2)), n_samples - 1))), 1e-6)
float w_rev_above = 0.0, float w_rev_below = 0.0
float w_total_above = 0.0, float w_total_below = 0.0
for j = 0 to k_val - 1
int idx = array.get(sorted_idx, j)
float d = array.get(dist_arr, idx)
float lbl = array.get(label_arr, idx)
float w = math.exp(-math.pow(d, gauss_bw) / (2.0 * sigma * sigma))
if lbl == 1
w_rev_above += w, w_total_above += w
else if lbl == -1
w_rev_below += w, w_total_below += w
else
if z1[array.get(sorted_idx, j)] > 0
w_total_above += w
else
w_total_below += w
p_rev_above := w_total_above > 0 ? w_rev_above / w_total_above : 0.0
p_rev_below := w_total_below > 0 ? w_rev_below / w_total_below : 0.0
bool knn_long = ta.crossover(p_rev_below, prob_thresh) and close < basis
bool knn_short = ta.crossover(p_rev_above, prob_thresh) and close > basis
// ── 5. STRATEJÝK HUBA BAÐLAMA VE YÖNLENDÝRME (ROUTING) ───────────────────────
if strat_mode == "V14.2 DayTrader"
global_long := v14_long
global_short := v14_short
global_exit_long := (close < kalkan)
global_exit_short := (close > kalkan)
else if strat_mode == "AlphaTrend Matrix"
global_long := at_long
global_short := at_short
global_exit_long := (K1 < K2 and close < AlphaTrend)
global_exit_short := (K2 < K1 and close > AlphaTrend)
else if strat_mode == "KNN Mean Reversion"
global_long := knn_long
global_short := knn_short
global_exit_long := ta.crossover(close, basis) // Ortalamaya ulaþtýðýnda çýkýþ
global_exit_short := ta.crossunder(close, basis)
// ── 6. EMÝR ÝCRAATLARI (MÜHÜRLÜ REPAINTSÝZ) ─────────────────────────────────
if global_long and is_trade_window and barstate.isconfirmed
strategy.entry("LONG", strategy.long, comment=strat_mode + " Giriþ")
if global_short and is_trade_window and barstate.isconfirmed
strategy.entry("SHORT", strategy.short, comment=strat_mode + " Giriþ")
// Teknik Çýkýþ Þartlarý
if strategy.position_size > 0 and global_exit_long and barstate.isconfirmed
strategy.close("LONG", comment="Teknik Çýkýþ")
if strategy.position_size < 0 and global_exit_short and barstate.isconfirmed
strategy.close("SHORT", comment="Teknik Çýkýþ")
// BIST Gün Sonu Acýmasýz Ýmha (17:55)
if is_eod
if strategy.position_size > 0
strategy.close("LONG", comment="G.S. Kapanýþ")
if strategy.position_size < 0
strategy.close("SHORT", comment="G.S. Kapanýþ")
// ── 7. DARK-MODE ANALYTICS HUD RADAR PANELÝ ─────────────────────────────────
float kar_faktoru = strategy.grossloss == 0 ? (strategy.grossprofit > 0 ? 99.99 : 0.0) : (strategy.grossprofit / strategy.grossloss)
if barstate.islast
var table hud = table.new(position.top_right, 2, 4, bgcolor=color.rgb(15, 15, 20, 15), border_width=1, border_color=color.rgb(45, 45, 55))
color hdrBg = color.rgb(30, 30, 45, 10)
color altBg = color.rgb(20, 20, 25, 10)
table.cell(hud, 0, 0, "🛸 OMEGA-HUB", text_color=color.white, text_size=size.small, bgcolor=hdrBg, text_halign=text.align_left)
table.cell(hud, 1, 0, "KOMUTA MERKEZÝ", text_color=color.white, text_size=size.small, bgcolor=hdrBg, text_halign=text.align_right)
table.merge_cells(hud, 0, 0, 1, 0)
table.cell(hud, 0, 1, "Aktif Doktrin", text_color=color.gray, text_size=size.small, bgcolor=altBg, text_halign=text.align_left)
table.cell(hud, 1, 1, strat_mode, text_color=color.orange, text_size=size.small, bgcolor=altBg, text_halign=text.align_right)
table.cell(hud, 0, 2, "Radar Durumu", text_color=color.gray, text_size=size.small, text_halign=text.align_left)
table.cell(hud, 1, 2, strategy.position_size > 0 ? "LONG AKTÝF" : strategy.position_size < 0 ? "SHORT AKTÝF" : "PUSUDA", text_color=strategy.position_size != 0 ? color.lime : color.gray, text_size=size.small, text_halign=text.align_right)
table.cell(hud, 0, 3, "Kâr Faktörü (PF)", text_color=color.gray, text_size=size.small, bgcolor=altBg, text_halign=text.align_left)
table.cell(hud, 1, 3, str.tostring(kar_faktoru, "#.##"), text_color=kar_faktoru >= 2.0 ? color.lime : kar_faktoru >= 1.0 ? color.yellow : color.red, text_size=size.small, bgcolor=altBg, text_halign=text.align_right)
// VÝZYON HATTI (Sadece Seçili Olan Ana Gösterge Çizilir)
plot(strat_mode == "V14.2 DayTrader" ? kf_state : na, "Kalman Hattý", color=color.white, linewidth=1)
plot(strat_mode == "V14.2 DayTrader" ? kalkan : na, "Sniper Kalkaný", color=color.lime, linewidth=2)
plot(strat_mode == "AlphaTrend Matrix" ? AlphaTrend : na, "AlphaTrend Hattý", color=at_direction == 1 ? color.green : color.red, linewidth=2)
plot(strat_mode == "KNN Mean Reversion" ? basis : na, "KNN Basis MA", color=color.blue, linewidth=2)
Yer Ýmleri