Untitled

Anonymous
plain_text
09/14/2026 11:23 AM
63.8 KB
7
Indexable
//@version=6
indicator("FiboAyna - MA - RSI  [FiboBorsa]", shorttitle = "FiboAyna", overlay=true)

var string mesaj = "⏰ -----| FIBONNACCI |----- ⏰\n\nHisse: {hisse}\nPeriod: {periyot}\nFiyat: {close}\nYön: {yon}\nA Noktası: {A:}\nB Noktası: {B:}\nSeviye: {seviye}\nMum: {mum}"
var string ho_mesaj = "⏰ ---| Hareketli Ortalama |--- ⏰\n\nHisse: {hisse}\nPeriod: {periyot}\nFiyat: {close}\nKesişim: --{ho}--"
var string boga_mesaj = "🐂 ---| Boğa Çizgisi Kesişimi |--- 🐂\n\nHisse: {hisse}\nPeriod: {periyot}\nFiyat: {close}\nBoğa Çizgisi: {ho}\nMum: {mum}"

var string sym = syminfo.ticker
var string periyot = timeframe.period

// pivots threshold
threshold_multiplier = 5 // input.float(title="Deviation", defval=5, minval=0, group = "Fibonnacci")
depth = 20 // input.int(title="Depth", defval=20, minval=2, group = "Fibonnacci")
reverse = false //input(false, "Reverse", display = display.data_window)
var extendLeft = input.bool(false, "Extend Left    |    Extend Right", inline = "Extend Lines", group = "Fibonnacci")
var extendRight = input.bool(false, "", inline = "Extend Lines", group = "Fibonnacci")
var bars_ahead = input.int(20, "Sağa Uzat", group = "Fibonnacci")
var extending = extend.none
if extendLeft and extendRight
    extending := extend.both
if extendLeft and not extendRight
    extending := extend.left
if not extendLeft and extendRight
    extending := extend.right
prices = input.bool(true, "Show Prices", display = display.data_window, group = "Fibonnacci")
levels = input.bool(true, "Show Levels", inline = "Levels", display = display.data_window, group = "Fibonnacci")
levelsFormat = input.string("Values", "", options = ["Values", "Percent"], inline = "Levels", display = display.data_window, active = levels, group = "Fibonnacci")
labelsPosition = input.string("Right", "Labels Position", options = ["Left", "Right"], display = display.data_window, group = "Fibonnacci")
var int backgroundTransparency = input.int(85, "Background Transparency", minval = 0, maxval = 100, display = display.data_window, group = "Fibonnacci")
var int ss = input.int(14, "Etiket Boyutu", minval = 0, maxval = 24, display = display.data_window, group = "Fibonnacci")

fiboyon = input.string("Dipten Tepe", "Alarm Yönü", ["Dipten Tepe", "Tepeden Dipe"], group = "Alarm Ayarları")

// Timeframe'i milisaniye cinsine çevir
tf_ms = timeframe.in_seconds() * 1000
future_time = time + (tf_ms * bars_ahead)


import TradingView/ZigZag/7 as zigzag

update()=>
    var settings = zigzag.Settings.new(threshold_multiplier, depth, color(na), false, false, false, false, "Absolute", true)
    var zigzag.ZigZag zigZag = zigzag.newInstance(settings)
    var zigzag.Pivot lastP = na
    var float startPrice = na
    var float height = na
    if barstate.islast and zigZag.pivots.size() < 2
        runtime.error("Not enough data to calculate Auto Fib Retracement on the current symbol. Change the chart's timeframe to a lower one or select a smaller calculation depth using the indicator's `Depth` settings.")
    settings.devThreshold := ta.atr(10) / close * 100 * threshold_multiplier
    if zigZag.update()
        lastP := zigZag.lastPivot()
        if not na(lastP)
            var line lineLast = na
            if na(lineLast)
                lineLast := line.new(lastP.start, lastP.end, xloc=xloc.bar_time, color=color.gray, width=1, style=line.style_dashed)
            else
                line.set_first_point(lineLast, lastP.start)
                line.set_second_point(lineLast, lastP.end)

            startPrice := reverse ? lastP.start.price : lastP.end.price
            endPrice = reverse ? lastP.end.price : lastP.start.price
            height := (startPrice > endPrice ? -1 : 1) * math.abs(startPrice - endPrice)
    [lastP, startPrice, height]

[lastP, startPrice, height] = update()

_draw_line(price, col) =>
    var id = line.new(lastP.start.time, lastP.start.price, time, price, xloc=xloc.bar_time, color=col, width=1, extend=extending)
    line.set_xy1(id, lastP.start.time, price)
    line.set_xy2(id, future_time, price)
	id


_draw_label(price, txt, txtColor) =>
    x = labelsPosition == "Left" ? lastP.start.time : not extendRight ? future_time : time
    labelStyle = labelsPosition == "Left" ? label.style_label_right : label.style_label_left
    align = labelsPosition == "Left" ? text.align_right : text.align_left
    labelsAlignStrLeft = txt
    labelsAlignStrRight = txt
    labelsAlignStr = labelsPosition == "Left" ? labelsAlignStrLeft : labelsAlignStrRight
    var id = label.new(x=x, y=price, xloc=xloc.bar_time, text=labelsAlignStr, textcolor=txtColor, style=labelStyle, size=ss, textalign=align, color=#00000000)
    label.set_xy(id, x, price)
    label.set_text(id, labelsAlignStr)
    label.set_textcolor(id, txtColor)

_wrap(txt) =>
    "(" + str.tostring(txt, format.mintick) + ")"

_label_txt(level, price) =>
    l = levelsFormat == "Values" ? str.tostring(level) : str.tostring(level * 100) + "%"
    (levels ? l : "") + (prices ? _wrap(price) : "")

_crossing_level(series float sr, series float r) =>
    (r > sr and r < sr[1]) or (r < sr and r > sr[1])


method placeholders(string str, float a = 0, float b = 0, float level = 0, string ho = "") =>
    mum = close < open ? "🔴" : "🚀"
    yon = not na(lastP) ? lastP.start.price > lastP.end.price ? "↘️ Tepe - Dip ↘️" : "↗️ Dip - Tepe ↗️" : ""
    msg = str

    msg := str.replace(msg, '{hisse}', syminfo.ticker)
    msg := str.replace(msg, '{close}',    str.tostring(close))
    msg := str.replace(msg, '{open}',     str.tostring(open))
    msg := str.replace(msg, '{high}',     str.tostring(high))
    msg := str.replace(msg, '{low}',      str.tostring(low))
    msg := str.replace(msg, '{periyot}',  timeframe.period)
    msg := str.replace(msg, '{A:}',  str.tostring(a))
    msg := str.replace(msg, '{B:}',  str.tostring(b))
    msg := str.replace(msg, '{seviye}',  str.tostring(level))
    msg := str.replace(msg, '{ho}',  str.tostring(ho))
    msg := str.replace(msg, '{yon}', yon)
    msg := str.replace(msg, '{mum}', mum)

    msg

eksiKosulu(seviye, sifir)=>
    seviye < 0 and close > sifir

alarmYonu(string val)=>
    val == "Dipten Tepe" ? lastP.end.price > lastP.start.price : lastP.start.price > lastP.end.price

processLevel(bool show, float value, color colorL, line lineIdOther) =>
    float m = value
	r = startPrice + height * m
    crossed = _crossing_level(close, r)
    if show and not na(lastP)
		lineId = _draw_line(r, colorL)
        _draw_label(r, _label_txt(m, r), colorL)
        if crossed and not eksiKosulu(m, lastP.end.price) and alarmYonu(fiboyon)
            alertMsg = mesaj.placeholders(a = lastP.start.price, b = lastP.end.price, level = value)
            alert(alertMsg)
        if not na(lineIdOther)
            linefill.new(lineId, lineIdOther, color = color.new(colorL, backgroundTransparency))
		lineId
    else
		lineIdOther

// === 30 Input Set ===
show_1  = input.bool(true,  "",  inline = "Level1",  display = display.data_window)
value_1 = input.float(-1.214,   "", inline = "Level1",  display = display.data_window, active = show_1)
color_1 = input.color(color.new(#2E0854, 0), "", inline = "Level1", display = display.data_window, active = show_1) // Derin Mor

show_2  = input.bool(true,  "",  inline = "Level1",  display = display.data_window)
value_2 = input.float(-1,   "", inline = "Level1",  display = display.data_window, active = show_2)
color_2 = input.color(color.new(#4B0082, 0), "", inline = "Level1", display = display.data_window, active = show_2) // İndigo

show_3  = input.bool(true,  "",  inline = "Level2",  display = display.data_window)
value_3 = input.float(-0.886,   "", inline = "Level2",  display = display.data_window, active = show_3)
color_3 = input.color(color.new(#6A0DAD, 0), "", inline = "Level2", display = display.data_window, active = show_3) // Parlak Mor

show_4  = input.bool(true,  "",  inline = "Level2",  display = display.data_window)
value_4 = input.float(-0.786,   "", inline = "Level2",  display = display.data_window, active = show_4)
color_4 = input.color(color.new(#8B00FF, 0), "", inline = "Level2", display = display.data_window, active = show_4) // Menekşe

show_5  = input.bool(true,  "",  inline = "Level3",  display = display.data_window)
value_5 = input.float(-0.685,   "", inline = "Level3",  display = display.data_window, active = show_5)
color_5 = input.color(color.new(#9370DB, 0), "", inline = "Level3", display = display.data_window, active = show_5) // Orta Mor

show_6  = input.bool(true,  "",  inline = "Level3",  display = display.data_window)
value_6 = input.float(-0.618,   "", inline = "Level3",  display = display.data_window, active = show_6)
color_6 = input.color(color.new(#8A2BE2, 0), "", inline = "Level3", display = display.data_window, active = show_6) // Mavi-Mor

show_7  = input.bool(true,  "",  inline = "Level4",  display = display.data_window)
value_7 = input.float(-0.5,   "", inline = "Level4",  display = display.data_window, active = show_7)
color_7 = input.color(color.new(#4169E1, 0), "", inline = "Level4", display = display.data_window, active = show_7) // Kraliyet Mavisi

show_8  = input.bool(true,  "",  inline = "Level4",  display = display.data_window)
value_8 = input.float(-0.382,   "", inline = "Level4",  display = display.data_window, active = show_8)
color_8 = input.color(color.new(#0000FF, 0), "", inline = "Level4", display = display.data_window, active = show_8) // Saf Mavi

show_9  = input.bool(true,  "",  inline = "Level5",  display = display.data_window)
value_9 = input.float(-0.315,   "", inline = "Level5",  display = display.data_window, active = show_9)
color_9 = input.color(color.new(#00BFFF, 0), "", inline = "Level5", display = display.data_window, active = show_9) // Gök Mavisi

show_10  = input.bool(true, "", inline = "Level5", display = display.data_window)
value_10 = input.float(-0.214,  "", inline = "Level5", display = display.data_window, active = show_10)
color_10 = input.color(color.new(#00FFFF, 0), "", inline = "Level5", display = display.data_window, active = show_10) // Turkuaz

show_11  = input.bool(true, "", inline = "Level6", display = display.data_window)
value_11 = input.float(-0.114,  "", inline = "Level6", display = display.data_window, active = show_11)
color_11 = input.color(color.new(#00FA9A, 0), "", inline = "Level6", display = display.data_window, active = show_11) // Bahar Yeşili

show_12  = input.bool(true, "", inline = "Level6", display = display.data_window)
value_12 = input.float(0,  "", inline = "Level6", display = display.data_window, active = show_12)
color_12 = input.color(color.new(#00FF00, 0), "", inline = "Level6", display = display.data_window, active = show_12) // Saf Yeşil

show_13  = input.bool(true, "", inline = "Level7", display = display.data_window)
value_13 = input.float(0.114,  "", inline = "Level7", display = display.data_window, active = show_13)
color_13 = input.color(color.new(#32CD32, 0), "", inline = "Level7", display = display.data_window, active = show_13) // Kireç Yeşili

show_14  = input.bool(true, "", inline = "Level7", display = display.data_window)
value_14 = input.float(0.214,  "", inline = "Level7", display = display.data_window, active = show_14)
color_14 = input.color(color.new(#ADFF2F, 0), "", inline = "Level7", display = display.data_window, active = show_14) // Sarı-Yeşil

show_15  = input.bool(true, "", inline = "Level8", display = display.data_window)
value_15 = input.float(0.315,  "", inline = "Level8", display = display.data_window, active = show_15)
color_15 = input.color(color.new(#FFFF00, 0), "", inline = "Level8", display = display.data_window, active = show_15) // Saf Sarı

show_16  = input.bool(true, "", inline = "Level8", display = display.data_window)
value_16 = input.float(0.382, "", inline = "Level8", display = display.data_window, active = show_16)
color_16 = input.color(color.new(#FFD700, 0), "", inline = "Level8", display = display.data_window, active = show_16) // Altın

show_17  = input.bool(true, "", inline = "Level9", display = display.data_window)
value_17 = input.float(0.5,  "", inline = "Level9", display = display.data_window, active = show_17)
color_17 = input.color(color.new(#FFA500, 0), "", inline = "Level9", display = display.data_window, active = show_17) // Turuncu

show_18  = input.bool(true, "", inline = "Level9", display = display.data_window)
value_18 = input.float(0.618,  "", inline = "Level9", display = display.data_window, active = show_18)
color_18 = input.color(color.new(#FF8C00, 0), "", inline = "Level9", display = display.data_window, active = show_18) // Koyu Turuncu

show_19  = input.bool(true, "", inline = "Level10", display = display.data_window)
value_19 = input.float(0.685,  "", inline = "Level10", display = display.data_window, active = show_19)
color_19 = input.color(color.new(#FF4500, 0), "", inline = "Level10", display = display.data_window, active = show_19) // Turuncu-Kızıl

show_20  = input.bool(true, "", inline = "Level10", display = display.data_window)
value_20 = input.float(0.786,  "", inline = "Level10", display = display.data_window, active = show_20)
color_20 = input.color(color.new(#FF0000, 0), "", inline = "Level10", display = display.data_window, active = show_20) // Saf Kızıl

show_21  = input.bool(true, "", inline = "Level11", display = display.data_window)
value_21 = input.float(0.886,  "", inline = "Level11", display = display.data_window, active = show_21)
color_21 = input.color(color.new(#E60000, 0), "", inline = "Level11", display = display.data_window, active = show_21) // Canlı Kırmızı

show_22  = input.bool(true, "", inline = "Level11", display = display.data_window)
value_22 = input.float(1,  "", inline = "Level11", display = display.data_window, active = show_22)
color_22 = input.color(color.new(#CC0000, 0), "", inline = "Level11", display = display.data_window, active = show_22) // Koyu Kırmızı

show_23  = input.bool(true, "", inline = "Level12", display = display.data_window)
value_23 = input.float(1.114,  "", inline = "Level12", display = display.data_window, active = show_23)
color_23 = input.color(color.new(#B22222, 0), "", inline = "Level12", display = display.data_window, active = show_23) // Ateş Tuğlası

show_24  = input.bool(true, "", inline = "Level12", display = display.data_window)
value_24 = input.float(1.214,  "", inline = "Level12", display = display.data_window, active = show_24)
color_24 = input.color(color.new(#A52A2A, 0), "", inline = "Level12", display = display.data_window, active = show_24) // Kahverengi-Kızıl

show_25  = input.bool(true, "", inline = "Level13", display = display.data_window)
value_25 = input.float(1.315,  "", inline = "Level13", display = display.data_window, active = show_25)
color_25 = input.color(color.new(#8B0000, 0), "", inline = "Level13", display = display.data_window, active = show_25) // Koyu Kan Rengi

show_26  = input.bool(true, "", inline = "Level13", display = display.data_window)
value_26 = input.float(1.382,  "", inline = "Level13", display = display.data_window, active = show_26)
color_26 = input.color(color.new(#800000, 0), "", inline = "Level13", display = display.data_window, active = show_26) // Bordo

show_27  = input.bool(true, "", inline = "Level14", display = display.data_window)
value_27 = input.float(1.5,  "", inline = "Level14", display = display.data_window, active = show_27)
color_27 = input.color(color.new(#660000, 0), "", inline = "Level14", display = display.data_window, active = show_27) // Derin Bordo

show_28  = input.bool(true, "", inline = "Level14", display = display.data_window)
value_28 = input.float(1.618,  "", inline = "Level14", display = display.data_window, active = show_28)
color_28 = input.color(color.new(#4D0000, 0), "", inline = "Level14", display = display.data_window, active = show_28) // Çok Koyu Kızıl

show_29  = input.bool(true, "", inline = "Level15", display = display.data_window)
value_29 = input.float(1.685,  "", inline = "Level15", display = display.data_window, active = show_29)
color_29 = input.color(color.new(#330000, 0), "", inline = "Level15", display = display.data_window, active = show_29) // Siyaha Yakın Kızıl

show_30  = input.bool(true, "", inline = "Level15", display = display.data_window)
value_30 = input.float(1.786,    "", inline = "Level15", display = display.data_window, active = show_30)
color_30 = input.color(color.new(#1A0000, 0), "", inline = "Level15", display = display.data_window, active = show_30) // En Koyu Kızıl


lineId1  = processLevel(show_1,  value_1,  color_1,  line(na))
lineId2  = processLevel(show_2,  value_2,  color_2,  lineId1)
lineId3  = processLevel(show_3,  value_3,  color_3,  lineId2)
lineId4  = processLevel(show_4,  value_4,  color_4,  lineId3)
lineId5  = processLevel(show_5,  value_5,  color_5,  lineId4)
lineId6  = processLevel(show_6,  value_6,  color_6,  lineId5)
lineId7  = processLevel(show_7,  value_7,  color_7,  lineId6)
lineId8  = processLevel(show_8,  value_8,  color_8,  lineId7)
lineId9  = processLevel(show_9,  value_9,  color_9,  lineId8)
lineId10 = processLevel(show_10, value_10, color_10, lineId9)
lineId11 = processLevel(show_11, value_11, color_11, lineId10)
lineId12 = processLevel(show_12, value_12, color_12, lineId11)
lineId13 = processLevel(show_13, value_13, color_13, lineId12)
lineId14 = processLevel(show_14, value_14, color_14, lineId13)
lineId15 = processLevel(show_15, value_15, color_15, lineId14)
lineId16 = processLevel(show_16, value_16, color_16, lineId15)
lineId17 = processLevel(show_17, value_17, color_17, lineId16)
lineId18 = processLevel(show_18, value_18, color_18, lineId17)
lineId19 = processLevel(show_19, value_19, color_19, lineId18)
lineId20 = processLevel(show_20, value_20, color_20, lineId19)
lineId21 = processLevel(show_21, value_21, color_21, lineId20)
lineId22 = processLevel(show_22, value_22, color_22, lineId21)
lineId23 = processLevel(show_23, value_23, color_23, lineId22)
lineId24 = processLevel(show_24, value_24, color_24, lineId23)
lineId25 = processLevel(show_25, value_25, color_25, lineId24)
lineId26 = processLevel(show_26, value_26, color_26, lineId25)
lineId27 = processLevel(show_27, value_27, color_27, lineId26)
lineId28 = processLevel(show_28, value_28, color_28, lineId27)
lineId29 = processLevel(show_29, value_29, color_29, lineId28)
lineId30 = processLevel(show_30, value_30, color_30, lineId29)

// Hareketli Ortalamalar
h_show_1  = input.bool(true,  "", inline = "h0", display = display.data_window, group = "Hareketli Ortalamalar")
h_value_1 = input.int(5,      "", inline = "h0", display = display.data_window, active = h_show_1, group = "Hareketli Ortalamalar")
h_color_1 = input.color(color.red, "", inline = "h0", display = display.data_window, active = h_show_1, group = "Hareketli Ortalamalar")
cross_1 =   input.string("Yukarı", "Kesişim", options = ["Yukarı", "Aşağı"], inline = "h0", display = display.data_window, group = "Hareketli Ortalamalar", active = h_show_1)

h_show_2  = input.bool(true,  "", inline = "h1", display = display.data_window, group = "Hareketli Ortalamalar")
h_value_2 = input.int(8,      "", inline = "h1", display = display.data_window, active = h_show_2, group = "Hareketli Ortalamalar")
h_color_2 = input.color(color.lime, "", inline = "h1", display = display.data_window, active = h_show_2, group = "Hareketli Ortalamalar")
cross_2 =   input.string("Yukarı", "Kesişim", options = ["Yukarı", "Aşağı"], inline = "h1", display = display.data_window, group = "Hareketli Ortalamalar", active = h_show_1)

h_show_3  = input.bool(true,  "", inline = "h2", display = display.data_window, group = "Hareketli Ortalamalar")
h_value_3 = input.int(14,     "", inline = "h2", display = display.data_window, active = h_show_3, group = "Hareketli Ortalamalar")
h_color_3 = input.color(color.blue, "", inline = "h2", display = display.data_window, active = h_show_3, group = "Hareketli Ortalamalar")
cross_3 =   input.string("Yukarı", "Kesişim", options = ["Yukarı", "Aşağı"], inline = "h2", display = display.data_window, group = "Hareketli Ortalamalar", active = h_show_1)

h_show_4  = input.bool(true,  "", inline = "h3", display = display.data_window, group = "Hareketli Ortalamalar")
h_value_4 = input.int(21,     "", inline = "h3", display = display.data_window, active = h_show_4, group = "Hareketli Ortalamalar")
h_color_4 = input.color(color.orange, "", inline = "h3", display = display.data_window, active = h_show_4, group = "Hareketli Ortalamalar")
cross_4 =   input.string("Yukarı", "Kesişim", options = ["Yukarı", "Aşağı"], inline = "h3", display = display.data_window, group = "Hareketli Ortalamalar", active = h_show_1)

h_show_5  = input.bool(true,  "", inline = "h4", display = display.data_window, group = "Hareketli Ortalamalar")
h_value_5 = input.int(34,     "", inline = "h4", display = display.data_window, active = h_show_5, group = "Hareketli Ortalamalar")
h_color_5 = input.color(color.purple, "", inline = "h4", display = display.data_window, active = h_show_5, group = "Hareketli Ortalamalar")
cross_5 =   input.string("Yukarı", "Kesişim", options = ["Yukarı", "Aşağı"], inline = "h4", display = display.data_window, group = "Hareketli Ortalamalar", active = h_show_1)

h_show_6  = input.bool(true,  "", inline = "h5", display = display.data_window, group = "Hareketli Ortalamalar")
h_value_6 = input.int(55,     "", inline = "h5", display = display.data_window, active = h_show_6, group = "Hareketli Ortalamalar")
h_color_6 = input.color(color.aqua, "", inline = "h5", display = display.data_window, active = h_show_6, group = "Hareketli Ortalamalar")
cross_6 =   input.string("Yukarı", "Kesişim", options = ["Yukarı", "Aşağı"], inline = "h5", display = display.data_window, group = "Hareketli Ortalamalar", active = h_show_1)

h_show_7  = input.bool(true,  "", inline = "h6", display = display.data_window, group = "Hareketli Ortalamalar")
h_value_7 = input.int(89,     "", inline = "h6", display = display.data_window, active = h_show_7, group = "Hareketli Ortalamalar")
h_color_7 = input.color(color.yellow, "", inline = "h6", display = display.data_window, active = h_show_7, group = "Hareketli Ortalamalar")
cross_7 =   input.string("Yukarı", "Kesişim", options = ["Yukarı", "Aşağı"], inline = "h6", display = display.data_window, group = "Hareketli Ortalamalar", active = h_show_1)

h_show_8  = input.bool(true,  "", inline = "h7", display = display.data_window, group = "Hareketli Ortalamalar")
h_value_8 = input.int(144,    "", inline = "h7", display = display.data_window, active = h_show_8, group = "Hareketli Ortalamalar")
h_color_8 = input.color(color.fuchsia, "", inline = "h7", display = display.data_window, active = h_show_8, group = "Hareketli Ortalamalar")
cross_8 =   input.string("Yukarı", "Kesişim", options = ["Yukarı", "Aşağı"], inline = "h7", display = display.data_window, group = "Hareketli Ortalamalar", active = h_show_1)

band1 = input.color(color.green, "Band 1", inline = "band1", group = "Hareketli Ortalamalar")
band1op = input.int(60, "", inline = "band1", group = "Hareketli Ortalamalar")
band2 = input.color(color.red, "Band 2", inline = "band2", group = "Hareketli Ortalamalar")
band2op = input.int(60, "", inline = "band2", group = "Hareketli Ortalamalar")

// Haftalık Boğa Çizgisi Ayarları
var string grp_boga = "Boğa Çizgisi"
show_w_boga_line  = input.bool(true, "Göster/Gizle", group = grp_boga)
w_boga_len        = 5 //input.int(5, "HO Uzunluğu", minval = 1, group = grp_boga)
w_boga_bars_back  = 50 //input.int(50, "Geriye Başlangıç Bar Sayısı", minval = 1, group = grp_boga)
w_boga_bars_ahead = 20 //input.int(20, "Sağa Uzatma Bar Sayısı", minval = 0, group = grp_boga)
w_boga_line_col   = input.color(color.red, "Çizgi Rengi", group = grp_boga)
w_boga_line_wid   = input.int(2, "Çizgi Kalınlığı", minval = 1, maxval = 10, group = grp_boga)
w_boga_style_str  = input.string("Düz", "Çizgi Stili", options = ["Düz", "Kesik", "Noktalı"], group = grp_boga)

w_boga_line_style = switch w_boga_style_str
    "Düz"     => line.style_solid
    "Kesik"   => line.style_dashed
    "Noktalı" => line.style_dotted
    => line.style_solid

rsilenght = input.int(34, "RSI", group = "RSI Kesişim")
rsicross = input.int(50, "Kesişim", group = "RSI Kesişim")

var string rsi_mesaj = "⏰ ---| RSI Kesişim |--- ⏰\n\nHisse: {hisse}\nPeriod: {periyot}\nFiyat: {close}\nRSI: "+ str.tostring(rsicross)
var string kom_mesaj = "⏰ --| Kompozit RSI Kesişim |-- ⏰\n\nHisse: {hisse}\nPeriod: {periyot}\nFiyat: {close}\nRSI: "+ str.tostring(rsicross)

// RSI
rsi = ta.rsi(close, rsilenght)

// BIST 100 endeksi kapanış fiyatı (BIST:XU100 sembolünü kullanıyoruz)
// Grafik periyodu ne olursa olsun, o periyotta çalışır
xu100_close = request.security("BIST:XU100", timeframe.period, close)

// Kompozit Fiyat Hesaplama
// Mevcut sembolün kapanış fiyatını BIST 100 endeksine bölerek oran hesapla
kc = close / xu100_close
// Kompozit fiyat oranı için RSI
composite_rsi = ta.rsi(kc, rsilenght)

if ta.cross(rsi, rsicross) and rsi > rsi[1]
    alertMsg = rsi_mesaj.placeholders()       
    alert(alertMsg)

if ta.cross(composite_rsi, rsicross) and rsi > rsi[1]
    alertMsg = kom_mesaj.placeholders()       
    alert(alertMsg)


// --- V HESAPLAMA BÖLÜMÜ ---
// V için Gerekli Girdiler
fixCMO = 9

// V hesaplama fonksiyonları
f1(m) =>
    m >= 0.0 ? m : 0.0
f2(m) =>
    m >= 0.0 ? 0.0 : -m
percent(nom, div) =>
    div == 0 ? 0 : 100 * nom / div // Sıfıra bölme hatasını önle

// V'yi belirli bir kaynak (source) ve periyot (pds) için hesaplayan fonksiyon
calc_v(src_series, pds) =>
    required_bars = fixCMO > 0 ? math.max(fixCMO, pds) : pds
    if bar_index < required_bars
        float(na)
    else
        // EMA smoothing faktörü
        alpha = 2.0 / (pds + 1)

        // CMO hesaplama
        momm = ta.change(src_series)
        m1 = f1(momm)   // pozitif değişimler
        m2 = f2(momm)   // negatif değişimler (mutlak)

        cmo_period = fixCMO > 0 ? fixCMO : pds
        sm1 = math.sum(m1, cmo_period)
        sm2 = math.sum(m2, cmo_period)
        raw_cmo = percent(sm1 - sm2, sm1 + sm2)
        k = math.abs(raw_cmo) / 100.0

        eff_alpha = alpha * math.max(0.0, math.min(1.0, k))  // 0-1 arasında clamp

        var float v = na
        v := na(v[1]) ? src_series : v[1] + eff_alpha * (src_series - v[1])
        v

v_1 = calc_v(close, h_value_1)
v_2 = calc_v(close, h_value_2)
v_3 = calc_v(close, h_value_3)
v_4 = calc_v(close, h_value_4)
v_5 = calc_v(close, h_value_5)
v_6 = calc_v(close, h_value_6)
v_7 = calc_v(close, h_value_7)
v_8 = calc_v(close, h_value_8)


// Günlük ve Haftalık HO değerlerini hesapla
[v1w, v2w, v3w, v4w, v5w, v6w, v7w, v8w] = request.security(syminfo.tickerid, "1W", [v_1, v_2, v_3, v_4, v_5, v_6, v_7, v_8])
[v1m, v2m, v3m, v4m, v5m, v6m, v7m, v8m] = request.security(syminfo.tickerid, "1M", [v_1, v_2, v_3, v_4, v_5, v_6, v_7, v_8])

f_calc_single_w() =>
    calc_v(close, w_boga_len)

w_boga_matched = w_boga_len == h_value_1 ? v1w :
                 w_boga_len == h_value_2 ? v2w :
                 w_boga_len == h_value_3 ? v3w :
                 w_boga_len == h_value_4 ? v4w :
                 w_boga_len == h_value_5 ? v5w :
                 w_boga_len == h_value_6 ? v6w :
                 w_boga_len == h_value_7 ? v7w :
                 w_boga_len == h_value_8 ? v8w : float(na)

w_boga_custom = not na(w_boga_matched) ? float(na) : request.security(syminfo.tickerid, "1W", f_calc_single_w())
w_boga_val = not na(w_boga_matched) ? w_boga_matched : w_boga_custom

v1d_str = not na(v_1) ? str.tostring(v_1, format.mintick) : "-"
v2d_str = not na(v_2) ? str.tostring(v_2, format.mintick) : "-"
v3d_str = not na(v_3) ? str.tostring(v_3, format.mintick) : "-"
v4d_str = not na(v_4) ? str.tostring(v_4, format.mintick) : "-"
v5d_str = not na(v_5) ? str.tostring(v_5, format.mintick) : "-"
v6d_str = not na(v_6) ? str.tostring(v_6, format.mintick) : "-"
v7d_str = not na(v_7) ? str.tostring(v_7, format.mintick) : "-"
v8d_str = not na(v_8) ? str.tostring(v_8, format.mintick) : "-"

v1w_str = not na(v1w) ? str.tostring(v1w, format.mintick) : "-"
v2w_str = not na(v2w) ? str.tostring(v2w, format.mintick) : "-"
v3w_str = not na(v3w) ? str.tostring(v3w, format.mintick) : "-"
v4w_str = not na(v4w) ? str.tostring(v4w, format.mintick) : "-"
v5w_str = not na(v5w) ? str.tostring(v5w, format.mintick) : "-"
v6w_str = not na(v6w) ? str.tostring(v6w, format.mintick) : "-"
v7w_str = not na(v7w) ? str.tostring(v7w, format.mintick) : "-"
v8w_str = not na(v8w) ? str.tostring(v8w, format.mintick) : "-"

v1m_str = not na(v1m) ? str.tostring(v1m, format.mintick) : "-"
v2m_str = not na(v2m) ? str.tostring(v2m, format.mintick) : "-"
v3m_str = not na(v3m) ? str.tostring(v3m, format.mintick) : "-"
v4m_str = not na(v4m) ? str.tostring(v4m, format.mintick) : "-"
v5m_str = not na(v5m) ? str.tostring(v5m, format.mintick) : "-"
v6m_str = not na(v6m) ? str.tostring(v6m, format.mintick) : "-"
v7m_str = not na(v7m) ? str.tostring(v7m, format.mintick) : "-"
v8m_str = not na(v8m) ? str.tostring(v8m, format.mintick) : "-"

check_cross(cross_type, v_value) =>
    cross_type == "Yukarı" ? close > v_value and close[1] < v_value : close < v_value and close[1] > v_value


h1 = plot(h_show_1 ? v_1 : na, title = "HO 1", color = h_color_1)
if h_show_1 and check_cross(cross_1, v_1)
    alertMsg = ho_mesaj.placeholders(ho = str.tostring(h_value_1))        
    alert(alertMsg)


h2 = plot(h_show_2 ? v_2 : na, title = "HO 2", color = h_color_2)
if h_show_2 and check_cross(cross_2, v_2)
    alertMsg = ho_mesaj.placeholders(ho = str.tostring(h_value_2))        
    alert(alertMsg)


h3 = plot(h_show_3 ? v_3 : na, title = "HO 3", color = h_color_3)
if h_show_3 and check_cross(cross_3, v_3)
    alertMsg = ho_mesaj.placeholders(ho = str.tostring(h_value_3))        
    alert(alertMsg)


plot(h_show_4 ? v_4 : na, title = "HO 4", color = h_color_4)
if h_show_4 and check_cross(cross_4, v_4)
    alertMsg = ho_mesaj.placeholders(ho = str.tostring(h_value_4))        
    alert(alertMsg)


plot(h_show_5 ? v_5 : na, title = "HO 5", color = h_color_5)
if h_show_5 and check_cross(cross_5, v_5)
    alertMsg = ho_mesaj.placeholders(ho = str.tostring(h_value_5))        
    alert(alertMsg)


plot(h_show_6 ? v_6 : na, title = "HO 6", color = h_color_6)
if h_show_6 and check_cross(cross_6, v_6)
    alertMsg = ho_mesaj.placeholders(ho = str.tostring(h_value_6))        
    alert(alertMsg)


plot(h_show_7 ? v_7 : na, title = "HO 7", color = h_color_7)
if h_show_7 and check_cross(cross_7, v_7)
    alertMsg = ho_mesaj.placeholders(ho = str.tostring(h_value_7))        
    alert(alertMsg)


plot(h_show_8 ? v_8 : na, title = "HO 8", color = h_color_8)
if h_show_8 and check_cross(cross_8, v_8)
    alertMsg = ho_mesaj.placeholders(ho = str.tostring(h_value_8))        
    alert(alertMsg)

// Boğa Çizgisi (Haftalık 5 HO) Yukarı Kesişim Alarmı
boga_kesisim = ta.crossover(close, w_boga_val)
if boga_kesisim
    alertMsg = boga_mesaj.placeholders(ho = str.tostring(w_boga_val, format.mintick))
    alert(alertMsg)

alertcondition(boga_kesisim, title = "Boğa Çizgisi Yukarı Kesişim", message = "🐂 Boğa Çizgisi Yukarı Kesişimi!\nHisse: {{ticker}}\nPeriod: {{interval}}\nFiyat: {{close}}")

fill(h1, h2, color.new(band1, band1op))
fill(h2, h3, color.new(band2, band2op))

// Tek hücrelik tablo: 1 sütun, 1 satır
var table myTable = table.new(position.bottom_right, 1, 1, border_width=1)


sinyalAktif = input.bool(true, title="MFI", inline = "mf")
mfiUzunluk = input.int(14, title="", minval=1, inline = "mf")

renkAlis  = input.color(color.green, title="", inline = "mf")
renkSatis = input.color(color.red, title="", inline = "mf")

// --- HESAPLAMALAR ---
// MFI hesaplaması (hlc3 PineScript v5'te built-in değişkendir)
mfi = ta.mfi(hlc3, mfiUzunluk)

// Kesişim Kontrolleri (Kullanıcı sinyalleri aktif ettiyse çalışır)
paraGirisi = ta.crossover(mfi, 50) and sinyalAktif
paraCikisi = ta.crossunder(mfi, 50) and sinyalAktif

// --- GRAFİĞE ÇİZİM ---
plotshape(paraGirisi, "MFI",  location=location.belowbar, style=shape.arrowup, color=renkAlis, size=size.normal)
plotshape(paraCikisi, "MFI",  location=location.abovebar, style=shape.arrowdown, color=renkSatis, size=size.normal)

// Ayarlar
trend =input.bool(true, "Trend")
pivotLeg = input.int(20, "Trend Pivot Uzunluğu")

// Pivot noktaları hesaplama
ph = ta.pivothigh(high, pivotLeg, pivotLeg)
pl = ta.pivotlow(low, pivotLeg, pivotLeg)

type Pivot
    float value
    int loc

var allPH = array.new<Pivot>()
var allPL = array.new<Pivot>()

// Pivot noktalarını ekleme
if not na(ph)
    array.push(allPH, Pivot.new(ph, bar_index[pivotLeg]))

if not na(pl)
    array.push(allPL, Pivot.new(pl, bar_index[pivotLeg]))

// Maximum pivot noktası kontrolü
var MAX_PIVOTS = 100
if array.size(allPH) > MAX_PIVOTS
    array.shift(allPH)
if array.size(allPL) > MAX_PIVOTS
    array.shift(allPL)

type lineArgs
    int x1
    int x2
    float y1
    float y2
    color color

type Signal
    bool valid
    lineArgs args

drawLine(lineArgs args) =>
    line.new(args.x1, args.y1, args.x2, args.y2,
     color = args.color, extend = extend.right, width = 2)

// Yükselen ve alçalan trendleri kontrol etme metodları
method isup(array<Pivot> this) =>
    if array.size(this) < 2
        Signal.new(false, lineArgs.new(0, 0, 0.0, 0.0, color.green))
    else
        curr = array.get(this, array.size(this) - 1)
        prev = array.get(this, array.size(this) - 2)
        valid = curr.value > prev.value
        Signal.new(valid, lineArgs.new(prev.loc, curr.loc, prev.value, curr.value, color.green))

method isdown(array<Pivot> this) =>
    if array.size(this) < 2
        Signal.new(false, lineArgs.new(0, 0, 0.0, 0.0, color.red))
    else
        curr = array.get(this, array.size(this) - 1)
        prev = array.get(this, array.size(this) - 2)
        valid = curr.value < prev.value
        Signal.new(valid, lineArgs.new(prev.loc, curr.loc, prev.value, curr.value, color.red))

type lineItem
    line line
    float x1
    bool active

var bullishline = array.new<lineItem>()
var bearishline = array.new<lineItem>()

// Yükselen trend çizgileri
if array.size(allPL) >= 2 and trend
    bullish = isup(allPL)
    if bullish.valid
        if array.size(bullishline) == 0
            array.push(bullishline, lineItem.new(drawLine(bullish.args), bullish.args.x1, true))
        else
            last = array.get(bullishline, array.size(bullishline) - 1)
            if bullish.args.x1 > last.x1
                array.push(bullishline, lineItem.new(drawLine(bullish.args), bullish.args.x1, true))

// Alçalan trend çizgileri
if array.size(allPH) >= 2 and trend
    bearish = isdown(allPH)
    if bearish.valid
        if array.size(bearishline) == 0
            array.push(bearishline, lineItem.new(drawLine(bearish.args), bearish.args.x1, true))
        else
            last = array.get(bearishline, array.size(bearishline) - 1)
            if bearish.args.x1 > last.x1
                array.push(bearishline, lineItem.new(drawLine(bearish.args), bearish.args.x1, true))

// Yükselen trend çizgilerini güncelleme
if array.size(bullishline) > 0 and trend
    for i = 0 to array.size(bullishline) - 1
        item = array.get(bullishline, i)
        if item.active
            price = line.get_price(item.line, bar_index)
            if low < price
                line.set_extend(item.line, extend.none)
                line.set_x2(item.line, bar_index)
                line.set_y2(item.line, price)
                item.active := false

// Alçalan trend çizgilerini güncelleme
if array.size(bearishline) > 0 and trend
    for i = 0 to array.size(bearishline) - 1
        item = array.get(bearishline, i)
        if item.active
            price = line.get_price(item.line, bar_index)
            if high > price
                line.set_extend(item.line, extend.none)
                line.set_x2(item.line, bar_index)
                line.set_y2(item.line, price)
                item.active := false


// Tablo Ayarları
var string grp_tbl = "Tablo Ayarları"
show_tbl   = input.bool(true, "M.O. Değerleri Tablosunu Göster", group = grp_tbl)
tbl_pos    = input.string("Üst Sağ", "Tablo Konumu", options = ["Üst Sağ", "Üst Sol", "Alt Sağ", "Alt Sol", "Üst Orta", "Alt Orta"], group = grp_tbl)
tsize      = input.int(11, "Tablo Boyutu", minval=8, maxval=24, group = grp_tbl)

tbl_position = switch tbl_pos
    "Üst Sağ"   => position.top_right
    "Üst Sol"   => position.top_left
    "Alt Sağ"   => position.bottom_right
    "Alt Sol"   => position.bottom_left
    "Üst Orta"  => position.top_center
    "Alt Orta"  => position.bottom_center
    => position.top_right



// Grafik periyodunu okunabilir metne çevir
tf_label() =>
    string tf = timeframe.period
    string result = tf
    if tf == "1D"
        result := "Günlük"
    else if tf == "1W"
        result := "Haftalık"
    else if tf == "1M"
        result := "Aylık"
    else
        float mins = str.tonumber(tf)
        if not na(mins)
            if mins < 60
                result := str.tostring(mins, "#") + " dk"
            else
                float hrs = mins / 60
                result := (hrs == math.round(hrs) ? str.tostring(hrs, "#") : str.tostring(hrs)) + " Saat"
    result

// Hareketli Ortalamalar Tablosu
var table hoTable = table.new(tbl_position, 8, 14, border_width=1, border_color=color.new(#A89070, 40))

if show_tbl and barstate.islast
    table.clear(hoTable, 0, 0, 7, 13)

    header_bg  = color.new(#5C4A1E, 10)
    price_bg_d = color.new(#e6bd1a, 20)
    price_bg_w = color.new(#0e709d, 20)
    price_bg_m = color.new(#6a1b9a, 20)
    price_txt  = #000000
    val_color  = #6B5A3A
    spacer_bg  = color.new(#f3e7cf, 0)

    table.cell(hoTable, 0, 0, "HO",       text_color=color.white, bgcolor=header_bg,  text_size=tsize)
    table.cell(hoTable, 1, 0, tf_label(), text_color=price_txt, bgcolor=price_bg_d, text_size=tsize)
    table.cell(hoTable, 2, 0, "",         bgcolor=spacer_bg)
    table.cell(hoTable, 3, 0, "HO",       text_color=color.white, bgcolor=header_bg,  text_size=tsize)
    table.cell(hoTable, 4, 0, "Haftalık", text_color=color.white, bgcolor=price_bg_w, text_size=tsize)
    table.cell(hoTable, 5, 0, "",         bgcolor=spacer_bg)
    table.cell(hoTable, 6, 0, "HO",       text_color=color.white, bgcolor=header_bg,  text_size=tsize)
    table.cell(hoTable, 7, 0, "Aylık",    text_color=color.white, bgcolor=price_bg_m, text_size=tsize)

    var ho_label = array.new_string(8)
    var ho_dval  = array.new_float(8)
    var ho_wval  = array.new_float(8)
    var ho_mval  = array.new_float(8)
    var ho_dstr  = array.new_string(8)
    var ho_wstr  = array.new_string(8)
    var ho_mstr  = array.new_string(8)
    var ho_col   = array.new_color(8)

    array.set(ho_label, 0, str.tostring(h_value_1)), array.set(ho_dval, 0, v_1), array.set(ho_wval, 0, v1w), array.set(ho_mval, 0, v1m), array.set(ho_dstr, 0, v1d_str), array.set(ho_wstr, 0, v1w_str), array.set(ho_mstr, 0, v1m_str), array.set(ho_col, 0, h_color_1)
    array.set(ho_label, 1, str.tostring(h_value_2)), array.set(ho_dval, 1, v_2), array.set(ho_wval, 1, v2w), array.set(ho_mval, 1, v2m), array.set(ho_dstr, 1, v2d_str), array.set(ho_wstr, 1, v2w_str), array.set(ho_mstr, 1, v2m_str), array.set(ho_col, 1, h_color_2)
    array.set(ho_label, 2, str.tostring(h_value_3)), array.set(ho_dval, 2, v_3), array.set(ho_wval, 2, v3w), array.set(ho_mval, 2, v3m), array.set(ho_dstr, 2, v3d_str), array.set(ho_wstr, 2, v3w_str), array.set(ho_mstr, 2, v3m_str), array.set(ho_col, 2, h_color_3)
    array.set(ho_label, 3, str.tostring(h_value_4)), array.set(ho_dval, 3, v_4), array.set(ho_wval, 3, v4w), array.set(ho_mval, 3, v4m), array.set(ho_dstr, 3, v4d_str), array.set(ho_wstr, 3, v4w_str), array.set(ho_mstr, 3, v4m_str), array.set(ho_col, 3, h_color_4)
    array.set(ho_label, 4, str.tostring(h_value_5)), array.set(ho_dval, 4, v_5), array.set(ho_wval, 4, v5w), array.set(ho_mval, 4, v5m), array.set(ho_dstr, 4, v5d_str), array.set(ho_wstr, 4, v5w_str), array.set(ho_mstr, 4, v5m_str), array.set(ho_col, 4, h_color_5)
    array.set(ho_label, 5, str.tostring(h_value_6)), array.set(ho_dval, 5, v_6), array.set(ho_wval, 5, v6w), array.set(ho_mval, 5, v6m), array.set(ho_dstr, 5, v6d_str), array.set(ho_wstr, 5, v6w_str), array.set(ho_mstr, 5, v6m_str), array.set(ho_col, 5, h_color_6)
    array.set(ho_label, 6, str.tostring(h_value_7)), array.set(ho_dval, 6, v_7), array.set(ho_wval, 6, v7w), array.set(ho_mval, 6, v7m), array.set(ho_dstr, 6, v7d_str), array.set(ho_wstr, 6, v7w_str), array.set(ho_mstr, 6, v7m_str), array.set(ho_col, 6, h_color_7)
    array.set(ho_label, 7, str.tostring(h_value_8)), array.set(ho_dval, 7, v_8), array.set(ho_wval, 7, v8w), array.set(ho_mval, 7, v8m), array.set(ho_dstr, 7, v8d_str), array.set(ho_wstr, 7, v8w_str), array.set(ho_mstr, 7, v8m_str), array.set(ho_col, 7, h_color_8)

    price = close

    // Değerlere göre büyükten küçüğe sıralanmış index listeleri (etiket/renk dizileri bozulmuyor)
    idx_d = array.sort_indices(ho_dval, order.descending)
    idx_w = array.sort_indices(ho_wval, order.descending)
    idx_m = array.sort_indices(ho_mval, order.descending)

    // ================= GÜNLÜK (SOL) TARAF =================
    int row_d = 1
    bool placed_d = false

    float top_d = array.get(ho_dval, array.get(idx_d, 0))
    float bot_d = array.get(ho_dval, array.get(idx_d, 7))
    bool above_all_d = not na(top_d) and price > top_d
    bool below_all_d = not na(bot_d) and price < bot_d

    if above_all_d
        table.cell(hoTable, 0, row_d, "", bgcolor=price_bg_d, text_size=tsize)
        table.cell(hoTable, 1, row_d, str.tostring(price, format.mintick), text_color=price_txt, bgcolor=price_bg_d, text_size=tsize)
        row_d += 1
        placed_d := true

    for k = 0 to 7
        i = array.get(idx_d, k)
        bg = k % 2 == 0 ? color.new(#F5F0E8, 20) : color.new(#EDE8DC, 20)
        table.cell(hoTable, 0, row_d, array.get(ho_label, i), text_color=array.get(ho_col, i), bgcolor=bg, text_size=tsize + 1, text_formatting = text.format_bold)
        table.cell(hoTable, 1, row_d, array.get(ho_dstr, i),  text_color=val_color, bgcolor=bg, text_size=tsize)
        row_d += 1

        if k < 7 and not placed_d
            float cur = array.get(ho_dval, i)
            float nxt = array.get(ho_dval, array.get(idx_d, k + 1))
            if not na(cur) and not na(nxt) and price <= cur and price >= nxt
                table.cell(hoTable, 0, row_d, "", bgcolor=price_bg_d, text_size=tsize)
                table.cell(hoTable, 1, row_d, str.tostring(price, format.mintick), text_color=price_txt, bgcolor=price_bg_d, text_size=tsize)
                row_d += 1
                placed_d := true

    if below_all_d and not placed_d
        table.cell(hoTable, 0, row_d, "", bgcolor=price_bg_d, text_size=tsize)
        table.cell(hoTable, 1, row_d, str.tostring(price, format.mintick), text_color=price_txt, bgcolor=price_bg_d, text_size=tsize)
        row_d += 1

    // ================= HAFTALIK (ORTA) TARAF =================
    int row_w = 1
    bool placed_w = false

    float top_w = array.get(ho_wval, array.get(idx_w, 0))
    float bot_w = array.get(ho_wval, array.get(idx_w, 7))
    bool above_all_w = not na(top_w) and price > top_w
    bool below_all_w = not na(bot_w) and price < bot_w

    if above_all_w
        table.cell(hoTable, 3, row_w, "", bgcolor=price_bg_w, text_size=tsize)
        table.cell(hoTable, 4, row_w, str.tostring(price, format.mintick), text_color=color.white, bgcolor=price_bg_w, text_size=tsize)
        row_w += 1
        placed_w := true

    for k = 0 to 7
        i = array.get(idx_w, k)
        bg = k % 2 == 0 ? color.new(#F5F0E8, 20) : color.new(#EDE8DC, 20)
        table.cell(hoTable, 3, row_w, array.get(ho_label, i), text_color=array.get(ho_col, i), bgcolor=bg, text_size=tsize + 1, text_formatting = text.format_bold)
        table.cell(hoTable, 4, row_w, array.get(ho_wstr, i),  text_color=val_color, bgcolor=bg, text_size=tsize)
        row_w += 1

        if k < 7 and not placed_w
            float cur = array.get(ho_wval, i)
            float nxt = array.get(ho_wval, array.get(idx_w, k + 1))
            if not na(cur) and not na(nxt) and price <= cur and price >= nxt
                table.cell(hoTable, 3, row_w, "", bgcolor=price_bg_w, text_size=tsize)
                table.cell(hoTable, 4, row_w, str.tostring(price, format.mintick), text_color=color.white, bgcolor=price_bg_w, text_size=tsize)
                row_w += 1
                placed_w := true

    if below_all_w and not placed_w
        table.cell(hoTable, 3, row_w, "", bgcolor=price_bg_w, text_size=tsize)
        table.cell(hoTable, 4, row_w, str.tostring(price, format.mintick), text_color=color.white, bgcolor=price_bg_w, text_size=tsize)
        row_w += 1

    // ================= AYLIK (SAĞ) TARAF =================
    int row_m = 1
    bool placed_m = false

    float top_m = array.get(ho_mval, array.get(idx_m, 0))
    float bot_m = array.get(ho_mval, array.get(idx_m, 7))
    bool above_all_m = not na(top_m) and price > top_m
    bool below_all_m = not na(bot_m) and price < bot_m

    if above_all_m
        table.cell(hoTable, 6, row_m, "", bgcolor=price_bg_m, text_size=tsize)
        table.cell(hoTable, 7, row_m, str.tostring(price, format.mintick), text_color=color.white, bgcolor=price_bg_m, text_size=tsize)
        row_m += 1
        placed_m := true

    for k = 0 to 7
        i = array.get(idx_m, k)
        bg = k % 2 == 0 ? color.new(#F5F0E8, 20) : color.new(#EDE8DC, 20)
        table.cell(hoTable, 6, row_m, array.get(ho_label, i), text_color=array.get(ho_col, i), bgcolor=bg, text_size=tsize + 1, text_formatting = text.format_bold)
        table.cell(hoTable, 7, row_m, array.get(ho_mstr, i),  text_color=val_color, bgcolor=bg, text_size=tsize)
        row_m += 1

        if k < 7 and not placed_m
            float cur = array.get(ho_mval, i)
            float nxt = array.get(ho_mval, array.get(idx_m, k + 1))
            if not na(cur) and not na(nxt) and price <= cur and price >= nxt
                table.cell(hoTable, 6, row_m, "", bgcolor=price_bg_m, text_size=tsize)
                table.cell(hoTable, 7, row_m, str.tostring(price, format.mintick), text_color=color.white, bgcolor=price_bg_m, text_size=tsize)
                row_m += 1
                placed_m := true

    if below_all_m and not placed_m
        table.cell(hoTable, 6, row_m, "", bgcolor=price_bg_m, text_size=tsize)
        table.cell(hoTable, 7, row_m, str.tostring(price, format.mintick), text_color=color.white, bgcolor=price_bg_m, text_size=tsize)
        row_m += 1

    // Ortadaki boşluk sütunlarını (2 ve 5), kullanılan en uzun tarafa göre doldur
    int max_row = math.max(row_d, math.max(row_w, row_m))
    for r = 1 to max_row - 1
        table.cell(hoTable, 2, r, "", bgcolor=spacer_bg)
        table.cell(hoTable, 5, r, "", bgcolor=spacer_bg)


if barstate.islast
    string yin = lastP.start.price > lastP.end.price ? "↘️" : "↗️"
    table.cell(myTable, 0, 0, text="FiboAyna v13 | Yön: " + yin + "\n\nFiboBorsa | Mr_Rakun", text_color=color.fuchsia, bgcolor=color.new(color.fuchsia, 70))

// =====================================================================
// HAFTALIK BOĞA ÇİZGİSİ ÇİZİMİ
// =====================================================================
var line ln_boga = na
var label lbl_boga = na

if barstate.islast
    if show_w_boga_line and not na(w_boga_val)
        x1 = math.max(0, bar_index - w_boga_bars_back)
        x2 = bar_index + w_boga_bars_ahead
        if na(ln_boga)
            ln_boga := line.new(x1, w_boga_val, x2, w_boga_val, xloc = xloc.bar_index, color = w_boga_line_col, width = w_boga_line_wid, style = w_boga_line_style)
            lbl_boga := label.new(x2, w_boga_val, "Boğa Çizgisi", xloc = xloc.bar_index, style = label.style_label_lower_right, color = color.new(color.white, 100), textcolor = w_boga_line_col, size = size.normal)
        else
            line.set_xy1(ln_boga, x1, w_boga_val)
            line.set_xy2(ln_boga, x2, w_boga_val)
            line.set_color(ln_boga, w_boga_line_col)
            line.set_width(ln_boga, w_boga_line_wid)
            line.set_style(ln_boga, w_boga_line_style)
            label.set_xy(lbl_boga, x2, w_boga_val)
            label.set_style(lbl_boga, label.style_label_lower_right)
            label.set_color(lbl_boga, color.new(color.white, 100))
            label.set_textcolor(lbl_boga, w_boga_line_col)
            label.set_text(lbl_boga, "Boğa Çizgisi")
    else
        if not na(ln_boga)
            line.delete(ln_boga)
            ln_boga := na
        if not na(lbl_boga)
            label.delete(lbl_boga)
            lbl_boga := na

//----------------------------------
Editor is loading...
Leave a Comment