PHP Code:
//@version=6
indicator("Yφrόk [Titan: ALMA Tetiπi & ICS Bulut]", shorttitle="Yφrόk Titan", overlay=true, max_lines_count=20, max_bars_back=5000)
// ─────────────────────────────────────────────────────────────────
// 1. SABέTLER VE GέRDέLER
// ─────────────────────────────────────────────────────────────────
int DIR_UP = 1
int DIR_DOWN = -1
int DIR_FLAT = 0
const float MIN_SIGMA = 1e-10
const float PI = math.pi
string GP_CALC = "════════ Bulut & Ηapa ════════"
string i_calcBar = input.string("Live Bar", "Hesaplama Ηapasύ", options = ["Live Bar", "Close Bar"], group = GP_CALC)
int i_period = input.int(26, "Trend Blok Periyodu", minval = 5, group = GP_CALC)
int i_groups = input.int(5, "Trend Blok Gruplarύ", minval = 2, group = GP_CALC)
float i_thresh = input.float(0.5, "Yatay Piyasa Eώiπi (°)", minval = 0.0, step = 0.1, group = GP_CALC)
int i_sigmaLen = input.int(20, "Yang-Zhang Volatilite Uzunluπu", minval = 5, group = GP_CALC)
int i_pjOff = input.int(26, "έleri Projeksiyon (Mum)", minval = 1, group = GP_CALC)
string GP_FILL = "════════ Bulut Renkleri ════════"
color i_fillUp = input.color(#26a69a, "Yόkseliώ Bulutu", group = GP_FILL)
color i_fillDn = input.color(#ef5350, "Dόώόώ Bulutu", group = GP_FILL)
color i_fillRng = input.color(#888888, "Yatay Bulut", group = GP_FILL)
int i_fillTr = input.int(85, "Bulut ήeffaflύπύ", minval = 0, maxval = 100, group = GP_FILL)
string GRP_EXIT = "════════ Tuzak Filtresi (ALMA) ════════"
useDecisiveExit = input.bool(true, "Kararlύ Ηύkύώ Kullan (Sahte έπneleri Filtrele)", group = GRP_EXIT)
pendingExitPriceType = input.string("Close", "Filtre Referansύ", options = ["Close", "High/Low"], group = GRP_EXIT)
string GRP_MA = "════════ Kuantum Ortalamalar ════════"
showMa1 = input.bool(true, "Hat #1 Gφster", inline = "MA1", group = GRP_MA)
ma1Type = input.string("ALMA", "", inline = "MA1", options = ["ALMA", "EMA", "SMA"], group = GRP_MA)
ma1Length = input.int(10, "", inline = "MA1", minval = 1, group = GRP_MA)
ma1Color = input.color(color.orange, "", inline = "MA1", group = GRP_MA)
showMa2 = input.bool(true, "Hat #2 Gφster", inline = "MA2", group = GRP_MA)
ma2Type = input.string("ALMA", "", inline = "MA2", options = ["ALMA", "EMA", "SMA"], group = GRP_MA)
ma2Length = input.int(21, "", inline = "MA2", minval = 1, group = GRP_MA)
ma2Color = input.color(color.green, "", inline = "MA2", group = GRP_MA)
showMa3 = input.bool(true, "Hat #3 Gφster", inline = "MA3", group = GRP_MA)
ma3Type = input.string("ALMA", "", inline = "MA3", options = ["ALMA", "EMA", "SMA"], group = GRP_MA)
ma3Length = input.int(50, "", inline = "MA3", minval = 1, group = GRP_MA)
ma3Color = input.color(color.red, "", inline = "MA3", group = GRP_MA)
showMa4 = input.bool(true, "Hat #4 Gφster", inline = "MA4", group = GRP_MA)
ma4Type = input.string("ALMA", "", inline = "MA4", options = ["ALMA", "EMA", "SMA"], group = GRP_MA)
ma4Length = input.int(200, "", inline = "MA4", minval = 1, group = GRP_MA)
ma4Color = input.color(color.fuchsia, "", inline = "MA4", group = GRP_MA)
var int _anchor = i_calcBar == "Live Bar" ? 0 : 1
f_fClr(int d) => d == DIR_UP ? i_fillUp : d == DIR_DOWN ? i_fillDn : i_fillRng
// ─────────────────────────────────────────────────────────────────
// 2. έZOTROPέK KOORDέNAT SέSTEMέ (ICS) MATEMATέΠέ
// ─────────────────────────────────────────────────────────────────
f_icsLine(float p1, int x1, float p2, int x2, int targetX, float sig) =>
float out = p1
if x1 != x2 and p1 > 0 and p2 > 0 and sig > MIN_SIGMA
float y1 = math.log(p1) / sig
float y2 = math.log(p2) / sig
float yT = y1 + (y2 - y1) * (targetX - x1) / (x2 - x1)
out := math.exp(yT * sig)
out
f_icsAngle(float p1, int x1, float p2, int x2, float sig) =>
float out = 0.0
if x1 != x2 and p1 > 0 and p2 > 0 and sig > MIN_SIGMA
float y1 = math.log(p1) / sig
float y2 = math.log(p2) / sig
out := math.atan((y2 - y1) / (x2 - x1)) * 180.0 / PI
out
// ─────────────────────────────────────────────────────────────────
// 3. YANG-ZHANG VOLATέLέTE (σ) & BLOK έNήASI
// ─────────────────────────────────────────────────────────────────
float _yzOR = math.log(open[_anchor] / nz(close[_anchor + 1], open[_anchor]))
float _yzCO = math.log(close[_anchor] / open[_anchor])
float _yzHO = math.log(high[_anchor] / open[_anchor])
float _yzHC = math.log(high[_anchor] / close[_anchor])
float _yzLO = math.log(low[_anchor] / open[_anchor])
float _yzLC = math.log(low[_anchor] / close[_anchor])
float _sqOR = ta.variance(_yzOR, i_sigmaLen)
float _sqCO = ta.variance(_yzCO, i_sigmaLen)
float _sqRS = ta.sma(_yzHO * _yzHC + _yzLO * _yzLC, i_sigmaLen)
float _k = 0.34 / (1.34 + (i_sigmaLen + 1.0) / math.max(i_sigmaLen - 1.0, 1.0))
float _sq = nz(_sqOR) + _k * nz(_sqCO) + (1.0 - _k) * nz(_sqRS)
float sigma = math.max(math.sqrt(math.max(_sq, 0.0)), MIN_SIGMA)
float _hhS = ta.highest(high, i_period)
float _llS = ta.lowest(low, i_period)
max_bars_back(_hhS, 2500)
max_bars_back(_llS, 2500)
var array<float> _bGm = array.new<float>()
var array<float> _bHi = array.new<float>()
var array<float> _bLo = array.new<float>()
var array<int> _bCx = array.new<int>()
_bGm.clear(), _bHi.clear(), _bLo.clear(), _bCx.clear()
bool _ok = bar_index >= i_groups * i_period + _anchor
if _ok
for i = 0 to i_groups - 1
int off = _anchor + i * i_period
float hi = _hhS[off]
float lo = _llS[off]
_bGm.push((hi > 0 and lo > 0) ? math.exp((math.log(hi) + math.log(lo)) / 2.0) : na)
_bHi.push(hi)
_bLo.push(lo)
_bCx.push(bar_index - off - int(i_period / 2))
int _dir = DIR_FLAT
float _ang = 0.0
int _seg = 0
if _ok and _bGm.size() >= 2
float g0 = _bGm.get(0)
float g1 = _bGm.get(1)
if not na(g0) and not na(g1) and g0 != g1
int pd = g0 > g1 ? DIR_UP : DIR_DOWN
_seg := 1
if i_groups > 2
for i = 1 to i_groups - 2
float a = _bGm.get(i)
float b = _bGm.get(i + 1)
if not na(a) and not na(b)
if (a > b ? DIR_UP : (a < b ? DIR_DOWN : DIR_FLAT)) == pd
_seg := i + 1
else
break
else
break
float sig = math.max(nz(sigma, MIN_SIGMA), MIN_SIGMA)
if _bGm.size() > _seg
_ang := f_icsAngle(_bGm.get(_seg), _bCx.get(_seg), _bGm.get(0), _bCx.get(0), sig)
_dir := math.abs(_ang) <= i_thresh ? DIR_FLAT : pd
// ─────────────────────────────────────────────────────────────────
// 4. HAREKETLέ ORTALAMALAR & ALMA PERSISTENCY TETέΠέ
// ─────────────────────────────────────────────────────────────────
calcMa(simple string maType, simple int length) =>
switch maType
"ALMA" => ta.alma(close, length, 0.85, 6)
"SMA" => ta.sma(close, length)
"EMA" => ta.ema(close, length)
=> na
ma1 = showMa1 ? calcMa(ma1Type, ma1Length) : na
ma2 = showMa2 ? calcMa(ma2Type, ma2Length) : na
ma3 = showMa3 ? calcMa(ma3Type, ma3Length) : na
ma4 = showMa4 ? calcMa(ma4Type, ma4Length) : na
plot(showMa1 ? ma1 : na, color = ma1Color, title = "Hat 1", linewidth=2)
plot(showMa2 ? ma2 : na, color = ma2Color, title = "Hat 2", linewidth=2)
plot(showMa3 ? ma3 : na, color = ma3Color, title = "Hat 3", linewidth=2)
plot(showMa4 ? ma4 : na, color = ma4Color, title = "Hat 4", linewidth=2)
var int ma1Count = 0, var float ma1ExitLevel = na, var bool ma1PendingExit = false, var bool ma1EntrySignal = false, var bool ma1ExitSignal = false, var bool ma1Populated = false
var int ma2Count = 0, var float ma2ExitLevel = na, var bool ma2PendingExit = false, var bool ma2EntrySignal = false, var bool ma2ExitSignal = false, var bool ma2Populated = false
var int ma3Count = 0, var float ma3ExitLevel = na, var bool ma3PendingExit = false, var bool ma3EntrySignal = false, var bool ma3ExitSignal = false, var bool ma3Populated = false
var int ma4Count = 0, var float ma4ExitLevel = na, var bool ma4PendingExit = false, var bool ma4EntrySignal = false, var bool ma4ExitSignal = false, var bool ma4Populated = false
updatePersistency(float price, float maValue, int prevCount, float prevExitLevel, bool prevPendingExit) =>
newCount = prevCount
newExitLevel = prevExitLevel
newPendingExit = prevPendingExit
entrySignal = false
exitSignal = false
if not na(maValue)
if useDecisiveExit
posExitTrigger = pendingExitPriceType == "Close" ? close < maValue : low < maValue
negExitTrigger = pendingExitPriceType == "Close" ? close > maValue : high > maValue
if newCount > 0
if newPendingExit
if low < newExitLevel
newCount := -1
newPendingExit := false
newExitLevel := na
exitSignal := true
if negExitTrigger
newPendingExit := true
newExitLevel := high
else if negExitTrigger
newPendingExit := false
newExitLevel := na
newCount += 1
else
newCount += 1
else
if posExitTrigger
newPendingExit := true
newExitLevel := low
newCount += 1
else
newCount += 1
else if newCount < 0
if newPendingExit
if high > newExitLevel
newCount := 1
newPendingExit := false
newExitLevel := na
entrySignal := true
if posExitTrigger
newPendingExit := true
newExitLevel := low
else if posExitTrigger
newPendingExit := false
newExitLevel := na
newCount -= 1
else
newCount -= 1
else
if negExitTrigger
newPendingExit := true
newExitLevel := high
newCount -= 1
else
newCount -= 1
else
if ta.crossover(price, maValue)
newCount := 1
newExitLevel := na
newPendingExit := false
entrySignal := true
else if ta.crossunder(price, maValue)
newCount := -1
newExitLevel := na
newPendingExit := false
exitSignal := true
else
if ta.crossover(price, maValue)
newCount := 1
newExitLevel := na
newPendingExit := false
entrySignal := true
else if ta.crossunder(price, maValue)
newCount := -1
newExitLevel := na
newPendingExit := false
exitSignal := true
else
if price > maValue
if newCount >= 1
newCount += 1
else
newCount := 1
entrySignal := true
else if price < maValue
if newCount <= -1
newCount -= 1
else
newCount := -1
exitSignal := true
else
newCount := newCount > 0 ? newCount + 1 : newCount < 0 ? newCount - 1 : 0
[newCount, newExitLevel, newPendingExit, entrySignal, exitSignal]
if showMa1
if not ma1Populated and not na(ma1)
ma1Populated := true
if close > ma1
ma1Count := 1
ma1EntrySignal := true
if ma1Populated
[c, e, p, en, ex] = updatePersistency(close, ma1, ma1Count, ma1ExitLevel, ma1PendingExit)
ma1Count := c, ma1ExitLevel := e, ma1PendingExit := p, ma1EntrySignal := en, ma1ExitSignal := ex
if showMa2
if not ma2Populated and not na(ma2)
ma2Populated := true
if close > ma2
ma2Count := 1
ma2EntrySignal := true
if ma2Populated
[c, e, p, en, ex] = updatePersistency(close, ma2, ma2Count, ma2ExitLevel, ma2PendingExit)
ma2Count := c, ma2ExitLevel := e, ma2PendingExit := p, ma2EntrySignal := en, ma2ExitSignal := ex
if showMa3
if not ma3Populated and not na(ma3)
ma3Populated := true
if close > ma3
ma3Count := 1
ma3EntrySignal := true
if ma3Populated
[c, e, p, en, ex] = updatePersistency(close, ma3, ma3Count, ma3ExitLevel, ma3PendingExit)
ma3Count := c, ma3ExitLevel := e, ma3PendingExit := p, ma3EntrySignal := en, ma3ExitSignal := ex
if showMa4
if not ma4Populated and not na(ma4)
ma4Populated := true
if close > ma4
ma4Count := 1
ma4EntrySignal := true
if ma4Populated
[c, e, p, en, ex] = updatePersistency(close, ma4, ma4Count, ma4ExitLevel, ma4PendingExit)
ma4Count := c, ma4ExitLevel := e, ma4PendingExit := p, ma4EntrySignal := en, ma4ExitSignal := ex
// ─────────────────────────────────────────────────────────────────
// 5. ALMA SέNYAL ΗέZέMLERέ (RAKAMLAR)
// ─────────────────────────────────────────────────────────────────
plotchar(showMa1 and ma1EntrySignal, title="Hat 1 AL", char='1', location=location.belowbar, color=ma1Color, size=size.tiny)
plotchar(showMa2 and ma2EntrySignal, title="Hat 2 AL", char='2', location=location.belowbar, color=ma2Color, size=size.tiny)
plotchar(showMa3 and ma3EntrySignal, title="Hat 3 AL", char='3', location=location.belowbar, color=ma3Color, size=size.tiny)
plotchar(showMa4 and ma4EntrySignal, title="Hat 4 AL", char='4', location=location.belowbar, color=ma4Color, size=size.tiny)
plotchar(showMa1 and ma1ExitSignal, title="Hat 1 SAT", char='1', location=location.abovebar, color=ma1Color, size=size.tiny)
plotchar(showMa2 and ma2ExitSignal, title="Hat 2 SAT", char='2', location=location.abovebar, color=ma2Color, size=size.tiny)
plotchar(showMa3 and ma3ExitSignal, title="Hat 3 SAT", char='3', location=location.abovebar, color=ma3Color, size=size.tiny)
plotchar(showMa4 and ma4ExitSignal, title="Hat 4 SAT", char='4', location=location.abovebar, color=ma4Color, size=size.tiny)
// ─────────────────────────────────────────────────────────────────
// 6. GΦRSELLEήTέRME (SAF έZOTROPέK BULUT DOLGUSU)
// ─────────────────────────────────────────────────────────────────
var line _upLn = na
var line _loLn = na
var line _upPj = na
var line _loPj = na
var linefill _chFill = na
var linefill _pjFill = na
if barstate.islastconfirmedhistory or barstate.islast
line.delete(_upLn), line.delete(_loLn), line.delete(_upPj), line.delete(_loPj)
linefill.delete(_chFill), linefill.delete(_pjFill)
if _ok and _seg >= 1 and _bHi.size() > _seg
float fHH = na, float fLH = na, float fHL = na, float fLL = na
int xHH = na, int xLH = na, int xHL = na, int xLL = na
for i = 0 to _seg
float h = _bHi.get(i)
float l = _bLo.get(i)
int x = _bCx.get(i)
if na(fHH) or h > fHH
fHH := h, xHH := x
if na(fLH) or h < fLH
fLH := h, xLH := x
if na(fHL) or l > fHL
fHL := l, xHL := x
if na(fLL) or l < fLL
fLL := l, xLL := x
int sLx = _bCx.get(_seg)
int sRx = _bCx.get(0)
float uY1 = na, float uY2 = na, float lY1 = na, float lY2 = na
float trSig = math.max(nz(sigma, MIN_SIGMA), MIN_SIGMA)
if _dir == DIR_UP
uY1 := f_icsLine(fLH, xLH, fHH, xHH, sLx, trSig)
uY2 := f_icsLine(fLH, xLH, fHH, xHH, sRx, trSig)
lY1 := f_icsLine(fLL, xLL, fHL, xHL, sLx, trSig)
lY2 := f_icsLine(fLL, xLL, fHL, xHL, sRx, trSig)
else if _dir == DIR_DOWN
uY1 := f_icsLine(fHH, xHH, fLH, xLH, sLx, trSig)
uY2 := f_icsLine(fHH, xHH, fLH, xLH, sRx, trSig)
lY1 := f_icsLine(fHL, xHL, fLL, xLL, sLx, trSig)
lY2 := f_icsLine(fHL, xHL, fLL, xLL, sRx, trSig)
else
uY1 := nz(fHH), uY2 := nz(fHH)
lY1 := nz(fLL), lY2 := nz(fLL)
int ax = bar_index - _anchor
float uYa = f_icsLine(uY1, sLx, uY2, sRx, ax, trSig)
float lYa = f_icsLine(lY1, sLx, lY2, sRx, ax, trSig)
_upLn := line.new(sLx, uY1, ax, uYa, color = na)
_loLn := line.new(sLx, lY1, ax, lYa, color = na)
int eX = ax + i_pjOff
float uYe = f_icsLine(uY1, sLx, uY2, sRx, eX, trSig)
float lYe = f_icsLine(lY1, sLx, lY2, sRx, eX, trSig)
_upPj := line.new(ax, uYa, eX, uYe, color = na)
_loPj := line.new(ax, lYa, eX, lYe, color = na)
color fc = color.new(f_fClr(_dir), i_fillTr)
_chFill := linefill.new(_upLn, _loLn, fc)
_pjFill := linefill.new(_upPj, _loPj, fc)
Yer έmleri