PHP Code:
//@version=6
indicator("Yφrόk [Titan Form - Tam Gφrόώ]", overlay=true, max_labels_count=500)
// ─────────────────────────────────────────────────────────────────
// 1. TEMEL MATEMATέKSEL VE MATS FONKSέYONLARI
// ─────────────────────────────────────────────────────────────────
bool_to_float(bool source) => source ? 1.0 : 0.0
ema(source)=>
var float ema_val = 0.0
var int count = 0
count := nz(count[1]) + 1
ema_val := (1.0 - 2.0 / (count + 1.0)) * nz(ema_val[1]) + 2.0 / (count + 1.0) * source
ema_val
atan2(y, x) =>
var float angle = 0.0
if x > 0
angle := math.atan(y / x)
else if x < 0 and y >= 0
angle := math.atan(y / x) + math.pi
else if x < 0 and y < 0
angle := math.atan(y / x) - math.pi
else if x == 0 and y > 0
angle := math.pi / 2
else if x == 0 and y < 0
angle := -math.pi / 2
angle
degrees(float source) => source * 180 / math.pi
f_mats(int _len) =>
atr_val = ema(ta.tr)
slope = (close - close[10]) / (atr_val * 10)
angle_rad = atan2(slope, 1)
deg = degrees(angle_rad)
src_m = ta.sma((deg > 0 ? high : low), 2)
smooth = 0.0
hh = math.max(math.sign(ta.change(ta.highest(_len))), 0)
ll = math.max(math.sign(ta.change(ta.lowest(_len)) * -1), 0)
tc = math.pow(ta.sma(bool_to_float(hh > 0 or ll > 0), _len), 2)
smooth := nz(smooth[1] + tc * (src_m - smooth[1]), src_m)
wp = _len * 4 - 1
a = math.abs(nz(smooth[1]) - smooth)
ma_a = ta.ema(a, wp)
dfa = ta.ema(ma_a, wp) * _len * 0.4
res = 0.0
if smooth > nz(res[1])
res := (smooth - dfa < res[1]) ? res[1] : (smooth - dfa)
else
res := (smooth + dfa > res[1]) ? res[1] : (smooth + dfa)
res
// ─────────────────────────────────────────────────────────────────
// 2. GέRDέLER (KRAL, VOLATέLέTE VE AYNALAR)
// ─────────────────────────────────────────────────────────────────
k_start = input.float(0.0, "Kral Baώlangύη", step=0.01, group="Otonom Beyin")
k_inc = input.float(0.02, "Kral έvme", step=0.01, group="Otonom Beyin")
k_max = input.float(0.20, "Kral Max", step=0.01, group="Otonom Beyin")
volLength = input.int(20, "Oynaklύk Uzunluπu", minval = 5, group="έstatistiksel Hedef")
projBars = input.int(5, "έleriye Projeksiyon", minval = 1, group="έstatistiksel Hedef")
barsPerYear = input.int(50, "Yύllύk Mum Ηarpanύ", minval = 50, group="έstatistiksel Hedef")
h_start = input.float(0.06, "Hύzlύ SAR Baώlangύη", step=0.01, group="Yin-Yang SAR")
h_inc = input.float(0.06, "Hύzlύ SAR έvme", step=0.01, group="Yin-Yang SAR")
h_max = input.float(0.30, "Hύzlύ SAR Max", step=0.1, group="Yin-Yang SAR")
y_start = input.float(0.01, "Yavaώ SAR Baώlangύη", step=0.005, group="Yin-Yang SAR")
y_inc = input.float(0.01, "Yavaώ SAR έvme", step=0.005, group="Yin-Yang SAR")
y_max = input.float(0.10, "Yavaώ SAR Max", step=0.1, group="Yin-Yang SAR")
// ─────────────────────────────────────────────────────────────────
// 3. ADAPTέF VέTES SEΗέMέ (MATS ZIRHI)
// ─────────────────────────────────────────────────────────────────
string tf = timeframe.period
float aktif_zirh = na
if tf == "1"
aktif_zirh := f_mats(34)
else if tf == "3"
aktif_zirh := f_mats(21)
else if tf == "5"
aktif_zirh := f_mats(13)
else if tf == "15"
aktif_zirh := f_mats(8)
else if tf == "60"
aktif_zirh := f_mats(5)
else if tf == "240"
aktif_zirh := f_mats(3)
else
aktif_zirh := f_mats(2)
// MATS Zύrh Ηizimi (Arkada sessiz ve asil durmasύ iηin beyaz ve yarύ saydam)
plot(aktif_zirh, title="MATS Zύrhύ", color=color.new(color.white, 50), linewidth=3)
// ─────────────────────────────────────────────────────────────────
// 4. OTONOM BEYέN (FIBONACCI YAήLANMA VE ΗARPIήMA MOTORU)
// ─────────────────────────────────────────────────────────────────
type SARState
float sar_value
float extreme_point
float accel_factor
bool isLong
int trend_age
int bounce_count
bool was_touching
method f_updateState(SARState state, float high_val, float low_val, float close_val, float accel_start, float accel_inc, float accel_max, float decay_limit, float atr_val) =>
bool isInitialTrend = false
bool trend_changed = false
if na(state.sar_value)
if close_val > close_val[1]
state.isLong := true
state.extreme_point := high_val
state.sar_value := low_val[1]
else
state.isLong := false
state.extreme_point := low_val
state.sar_value := high_val[1]
isInitialTrend := true
state.accel_factor := accel_start
state.trend_age := 0
else
state.trend_age += 1
state.sar_value += state.accel_factor * (state.extreme_point - state.sar_value)
if state.isLong
if state.sar_value > low_val
isInitialTrend := true
trend_changed := true
state.isLong := false
state.sar_value := math.max(high_val, state.extreme_point)
state.extreme_point := low_val
state.accel_factor := accel_start
state.trend_age := 0
else
if state.sar_value < high_val
isInitialTrend := true
trend_changed := true
state.isLong := true
state.sar_value := math.min(low_val, state.extreme_point)
state.extreme_point := high_val
state.accel_factor := accel_start
state.trend_age := 0
if trend_changed
state.bounce_count := 0
state.was_touching := false
else
float tol = atr_val * 0.2
bool is_touch = state.isLong ? (low_val <= state.sar_value + tol) : (high_val >= state.sar_value - tol)
if is_touch and not state.was_touching
state.bounce_count += 1
state.was_touching := is_touch
float decay_factor = math.max(0.01, 1.0 - (state.trend_age / decay_limit))
float yasli_inc = accel_inc * decay_factor
if not isInitialTrend
if state.isLong
if high_val > state.extreme_point
state.extreme_point := high_val
state.accel_factor := math.min(state.accel_factor + yasli_inc, accel_max)
else
if low_val < state.extreme_point
state.extreme_point := low_val
state.accel_factor := math.min(state.accel_factor + yasli_inc, accel_max)
if bar_index > 1
if state.isLong
state.sar_value := math.min(state.sar_value, low_val[1])
if bar_index > 2
state.sar_value := math.min(state.sar_value, low_val[2])
else
state.sar_value := math.max(state.sar_value, high_val[1])
if bar_index > 2
state.sar_value := math.max(state.sar_value, high_val[2])
state
var float[] fibs = array.from(1.0, 2.0, 3.0, 5.0, 8.0, 13.0, 21.0, 34.0, 55.0)
var states = array.new<SARState>()
if barstate.isfirst
for i = 0 to 8
states.push(SARState.new(na, na, k_start, false, 0, 0, false))
float gercek_oynaklik = ta.atr(14)
for i = 0 to 8
SARState s = states.get(i)
s.f_updateState(high, low, close, k_start, k_inc, k_max, fibs.get(i), gercek_oynaklik)
var int king_idx = 5
int new_king = -1
for i = 0 to 8
if states.get(i).bounce_count >= 2
new_king := i
break
if new_king != -1
king_idx := new_king
float kral_sar = states.get(king_idx).sar_value
bool kral_yon = states.get(king_idx).isLong
float kral_ayna = close + (close - kral_sar)
float cc = ta.sar(0.0, 0.01, 0.3)
// ─────────────────────────────────────────────────────────────────
// 5. YέN-YANG SAR MOTORU VE MUM AHENGέ
// ─────────────────────────────────────────────────────────────────
f_ozel_sar(src_h, src_l, _start, _inc, _max, _reset_hiz) =>
var int trend = 0
var float sar_val = 0.0
var float ep = 0.0
var float af = 0.0
if trend == 0 and not na(src_h[1])
trend := src_h >= src_h[1] or src_l >= src_l[1] ? 1 : -1
sar_val := trend > 0 ? src_l[1] : src_h[1]
ep := trend > 0 ? src_h[1] : src_l[1]
af := _start
else
if _reset_hiz
af := _start
float nextsar = sar_val
if trend > 0
if src_h[1] > ep
ep := src_h[1]
af := math.min(_max, af + _inc)
nextsar := sar_val + af * (ep - sar_val)
nextsar := math.min(math.min(src_l[1], src_l[2]), nextsar)
if nextsar > src_l
trend := -1
nextsar := ep
ep := src_l
af := _start
else
if src_l[1] < ep
ep := src_l[1]
af := math.min(_max, af + _inc)
nextsar := sar_val + af * (ep - sar_val)
nextsar := math.max(math.max(src_h[1], src_h[2]), nextsar)
if nextsar < src_h
trend := 1
nextsar := ep
ep := src_h
af := _start
sar_val := nextsar
[sar_val, trend]
yeni_gun = ta.change(time("D")) != 0
[sar_hizli, trend_hizli] = f_ozel_sar(high, low, h_start, h_inc, h_max, yeni_gun)
ayna_hizli = trend_hizli > 0 ? close + math.abs(close - sar_hizli) : close - math.abs(close - sar_hizli)
[sar_yavas, trend_yavas] = f_ozel_sar(high, low, y_start, y_inc, y_max, yeni_gun)
ayna_yavas = trend_yavas > 0 ? close + math.abs(close - sar_yavas) : close - math.abs(close - sar_yavas)
// Mum Renkleri: Yin ve Yang (Hύzlύ ve Yavaώ SAR) aynύ yφndeyse Ahenk (Renkli), aksi halde Kaos (Gri)
bool ahenk_boga = (trend_hizli > 0) and (trend_yavas > 0)
bool ahenk_ayi = (trend_hizli < 0) and (trend_yavas < 0)
barcolor(ahenk_boga ? color.lime : ahenk_ayi ? color.red : color.new(color.gray, 60))
// ─────────────────────────────────────────────────────────────────
// 6. έSTATέSTέKSEL VOLATέLέTE (%68) VE HEDEFLER
// ─────────────────────────────────────────────────────────────────
logReturn = math.log(close / close[1])
rawVol = ta.stdev(logReturn, volLength)
annualVol = rawVol * math.sqrt(barsPerYear)
conePrice(float basePrice, float vol, int t, float sigmaMultiplier, int direction) =>
drift = direction * sigmaMultiplier * vol * math.sqrt(float(t) / float(barsPerYear))
basePrice * math.exp(drift)
var label[] sigmaLabels = array.new<label>()
if barstate.islast
if sigmaLabels.size() > 0
for i = 0 to sigmaLabels.size() - 1
label.delete(sigmaLabels.get(i))
sigmaLabels.clear()
float tip1up = conePrice(close, annualVol, projBars, 1.0, 1)
float tip1dn = conePrice(close, annualVol, projBars, 1.0, -1)
int tipX = bar_index + projBars
if kral_yon
sigmaLabels.push(label.new(tipX, tip1up, "(%68)\n" + str.tostring(tip1up, format.mintick), color=color.new(color.lime, 80), textcolor=color.lime, style=label.style_label_left, size=size.small))
else
sigmaLabels.push(label.new(tipX, tip1dn, "(%68)\n" + str.tostring(tip1dn, format.mintick), color=color.new(color.red, 80), textcolor=color.red, style=label.style_label_left, size=size.small))
// ─────────────────────────────────────────────────────────────────
// 7. EKRAN ΗέZέMLERέ (YέN-YANG EKLENDέ)
// ─────────────────────────────────────────────────────────────────
color col_kral = kral_yon ? color.new(color.lime, 0) : color.new(color.red, 0)
color col_ayna = kral_yon ? color.new(color.lime, 50) : color.new(color.red, 50)
// 1. Kral SAR ve Ayna
plot(kral_sar, title="Kral SAR", color=col_kral, style=plot.style_circles, linewidth=3)
plot(kral_ayna, title="Kral Ayna", color=col_ayna, style=plot.style_line, linewidth=2)
// 2. @yφrόk@ SAR (Sade haη iώareti)
plot(cc, title="@yφrόk@", color=color.new(color.white, 0), style=plot.style_cross, linewidth=2)
// 3. Trend Ηizgisi (Hύzlύ Ayna)
color col_hizli = (ayna_hizli > close) ? color.lime : color.red
plot(ayna_hizli, title="Trend (Hύzlύ Ayna)", color=col_hizli, style=plot.style_line, linewidth=1)
// 4. Yin-Yang SAR Noktalarύ (Geri Eklendi!)
color col_yin = trend_yavas > 0 ? color.aqua : color.blue
plot(sar_yavas, title="Yin (Su)", color=col_yin, style=plot.style_circles, linewidth=2)
color col_yang = trend_hizli > 0 ? color.orange : color.maroon
plot(sar_hizli, title="Yang (Ateώ)", color=col_yang, style=plot.style_circles, linewidth=1)
Yer έmleri