PHP Code:
// Kinetik Komuta Merkezi [V9 - TWAP x Fourier x Acceptance]
//@version=6
indicator("Kinetik Komuta Merkezi [V9]", shorttitle="KKM V9", overlay=true, max_boxes_count=100, max_labels_count=200)
// ─────────────────────────────────────────────────────────────────
// 0. GRDLER VE AYARLAR
// ─────────────────────────────────────────────────────────────────
g_twap = "1. Maliyet Trambolini (TWAP & statistiksel Bantlar)"
float i_dev1 = input.float(1.0, "1. Sapma (Grlt Snr)", step=0.1, group=g_twap)
float i_dev2 = input.float(2.0, "2. Sapma (Kinetik Hedef)", step=0.1, group=g_twap)
float i_dev3 = input.float(3.0, "3. Sapma (Anomali Snr)", step=0.1, group=g_twap)
g_fourier = "2. Fourier Spektral ekirdek"
int i_N = input.int(64, "Pencere Uzunluu (N)", group=g_fourier)
int i_harmonics = input.int(3, "Harmonik Filtresi", group=g_fourier)
g_ember = "3. Kinetik Ateleme (tki)"
int i_atrLen = input.int(14, "ATR Uzunluu", group=g_ember)
float i_ignRange = input.float(1.5, "Ateleme Eii (ATR arpan)", step=0.1, group=g_ember)
g_accept = "4. Fiyat Kabul (Acceptance) Motoru"
float i_bandAtr = input.float(0.30, "Kabul Band Ykseklii (ATR)", step=0.05, group=g_accept)
float i_shelfAtr = input.float(0.50, "ptal Raf Mesafesi (ATR)", step=0.05, group=g_accept)
int i_minCloses = input.int(3, "Minimum Onay Mumu", group=g_accept)
// Renkler
color c_twap = color.rgb(255, 204, 0)
color c_buy = color.rgb(0, 230, 118)
color c_sell = color.rgb(255, 23, 68)
color c_watch = color.rgb(41, 98, 255)
color c_shelf = color.rgb(136, 14, 79)
color c_neutral= color.rgb(120, 123, 134)
// ─────────────────────────────────────────────────────────────────
// 1. SAF TWAP VE STATSTKSEL SAPMA (Maliyet Trambolini)
// ─────────────────────────────────────────────────────────────────
// Yeni gn algla (Seans balangcnda otomatik reset)
bool isNewDay = ta.change(time("D")) != 0
var float sumPrice = 0.0
var float sumPrice2 = 0.0
var int barCount = 0
if isNewDay
sumPrice := close
sumPrice2 := close * close
barCount := 1
else
sumPrice += close
sumPrice2 += close * close
barCount += 1
float twapValue = sumPrice / barCount
float variance = (sumPrice2 / barCount) - (twapValue * twapValue)
float stdev = math.sqrt(math.max(variance, 0))
float up1 = twapValue + (stdev * i_dev1)
float dn1 = twapValue - (stdev * i_dev1)
float up2 = twapValue + (stdev * i_dev2)
float dn2 = twapValue - (stdev * i_dev2)
float up3 = twapValue + (stdev * i_dev3)
float dn3 = twapValue - (stdev * i_dev3)
plot(twapValue, "TWAP (Maliyet Trambolini)", color=color.new(c_twap, 20), linewidth=2, style=plot.style_linebr)
p_up1 = plot(up1, "+1σ", color=color.new(c_buy, 60), linewidth=1, style=plot.style_linebr)
p_dn1 = plot(dn1, "-1σ", color=color.new(c_sell, 60), linewidth=1, style=plot.style_linebr)
p_up2 = plot(up2, "+2σ", color=color.new(c_buy, 40), linewidth=2, style=plot.style_linebr)
p_dn2 = plot(dn2, "-2σ", color=color.new(c_sell, 40), linewidth=2, style=plot.style_linebr)
plot(up3, "+3σ", color=color.new(c_sell, 20), linewidth=1, style=plot.style_cross) // Anomali
plot(dn3, "-3σ", color=color.new(c_buy, 20), linewidth=1, style=plot.style_cross) // Anomali
fill(p_up1, p_dn1, color=color.new(c_twap, 95), title="1σ Grlt Alan")
// ─────────────────────────────────────────────────────────────────
// 2. FOURIER SPEKTRAL DNM (SIFIR GECKMEL FREKANS)
// ─────────────────────────────────────────────────────────────────
float dc = math.sum(close, i_N) / i_N
float a_k_sum = 0.0
for k = 1 to i_harmonics
float a_k = 0.0
for i = 0 to i_N - 1
float angle = (2.0 * math.pi * k * i) / i_N
a_k += nz(close[i]) * math.cos(angle)
a_k_sum += (2.0 / i_N) * a_k
float fourier_wave = dc + a_k_sum
float fourier_slope = fourier_wave - nz(fourier_wave[1])
bool bullBias = fourier_slope > 0
bool bearBias = fourier_slope < 0
// ─────────────────────────────────────────────────────────────────
// 3. KNETK ATELEME (HACMSZ IGNITION BAR)
// ─────────────────────────────────────────────────────────────────
float atrVal = ta.atr(i_atrLen)
float safeAtr = math.max(atrVal, syminfo.mintick)
float barRange = high - low
bool isIgnition = barRange >= (safeAtr * i_ignRange)
bool fireBull = bullBias and isIgnition and close > open and close > nz(close[1])
bool fireBear = bearBias and isIgnition and close < open and close < nz(close[1])
// ─────────────────────────────────────────────────────────────────
// 4. FYAT KABUL (ACCEPTANCE) VE PTAL RAFI DEVRES
// ─────────────────────────────────────────────────────────────────
var int activeSide = 0
var float activeLevel = na
var int startBar = na
var int beyondCloses = 0
var string plannerState = "NONE"
var box accBox = na
var box shelfBox = na
// Ateleme Geldiinde Yeni Seri
if (fireBull and activeSide != 1)
activeSide := 1
activeLevel := close
startBar := bar_index
beyondCloses := 0
plannerState := "BUILDING"
label.new(bar_index, low - safeAtr, "ATELEME", color=c_buy, textcolor=color.white, style=label.style_label_up, size=size.small)
else if (fireBear and activeSide != -1)
activeSide := -1
activeLevel := close
startBar := bar_index
beyondCloses := 0
plannerState := "BUILDING"
label.new(bar_index, high + safeAtr, "ATELEME", color=c_sell, textcolor=color.white, style=label.style_label_down, size=size.small)
// Seri Kontrolleri
bool stateChanged = false
if activeSide != 0
int barsActive = bar_index - startBar
float shelf = activeSide == 1 ? activeLevel - (i_shelfAtr * safeAtr) : activeLevel + (i_shelfAtr * safeAtr)
float bandTop = activeLevel + (i_bandAtr * safeAtr)
float bandBot = activeLevel - (i_bandAtr * safeAtr)
bool isBeyond = activeSide == 1 ? close > activeLevel : close < activeLevel
if isBeyond
beyondCloses += 1
bool isFailed = activeSide == 1 ? close < shelf : close > shelf
float persistenceScore = math.min(50, (beyondCloses / math.max(1.0, i_minCloses)) * 50)
float distanceScore = math.min(30, (math.abs(close - activeLevel) / safeAtr) * 15)
float momentumScore = isBeyond ? 20 : 0
float accScore = persistenceScore + distanceScore + momentumScore
string prevState = plannerState
if isFailed
plannerState := "REJECTED"
activeSide := 0
else if accScore >= 80 and barsActive >= i_minCloses
plannerState := "ACCEPTED"
else if accScore >= 50
plannerState := "WATCH"
stateChanged := plannerState != prevState
// Kutular iz
color boxCol = activeSide == 1 ? color.new(c_buy, 85) : color.new(c_sell, 85)
if barsActive == 0
accBox := box.new(startBar, bandTop, bar_index + 10, bandBot, bgcolor=boxCol, border_color=color.new(boxCol, 0))
float shelfT = activeSide == 1 ? shelf : shelf + (safeAtr * 0.1)
float shelfB = activeSide == 1 ? shelf - (safeAtr * 0.1) : shelf
shelfBox := box.new(startBar, shelfT, bar_index + 10, shelfB, bgcolor=color.new(c_shelf, 85), border_color=color.new(c_shelf, 20))
else if activeSide != 0
box.set_right(accBox, bar_index + 6)
box.set_right(shelfBox, bar_index + 6)
box.set_text(accBox, plannerState + "\n" + str.tostring(math.round(accScore)) + "/100")
box.set_text_color(accBox, color.new(color.white, 30))
box.set_text_size(accBox, size.small)
if stateChanged
if plannerState == "ACCEPTED"
label.new(bar_index, activeSide == 1 ? low - safeAtr : high + safeAtr, "ACCEPT", color=c_buy, textcolor=color.white, style=activeSide==1?label.style_label_up:label.style_label_down, size=size.small)
else if plannerState == "WATCH"
label.new(bar_index, activeSide == 1 ? low - safeAtr : high + safeAtr, "WATCH", color=c_watch, textcolor=color.white, style=activeSide==1?label.style_label_up:label.style_label_down, size=size.small)
if plannerState == "REJECTED" and prevState != "REJECTED"
label.new(bar_index, activeSide[1] == 1 ? low - safeAtr : high + safeAtr, "REJECTED", color=color.maroon, textcolor=color.white, style=activeSide[1]==1?label.style_label_up:label.style_label_down, size=size.small)
// ─────────────────────────────────────────────────────────────────
// 5. FOURIER DALGASI (KNETK NEON)
// ─────────────────────────────────────────────────────────────────
color waveCol = bullBias ? c_buy : bearBias ? c_sell : c_neutral
plot(fourier_wave, "Glow D", color=color.new(waveCol, 85), linewidth=6)
plot(fourier_wave, "Glow ", color=color.new(waveCol, 60), linewidth=3)
plot(fourier_wave, "ekirdek", color=color.new(waveCol, 0), linewidth=1)
barcolor(activeSide != 0 ? (activeSide == 1 ? color.new(c_buy, 30) : color.new(c_sell, 30)) : na)
deiik bir alma oldu... sadeleme... ve tablo gerekir gibi... imdilik yedekte kalsn....
Yer mleri