Untitled

 avatar
unknown
plain_text
21 days ago
88 kB
6
Indexable
//@version=5
indicator("Kule Trend Ind", overlay=true)

// // EMA 8 için parametreler
// emaFast_tf = input.timeframe("1W", "EMA 8 Timeframe", inline="ema8")
// emaFastLength = input.int(8, "Periyot", inline="ema8")
// ema8Color = input.color(#20b725, "Renk", inline="ema8")

// // Günlük EMA 10 için parametreler
// emaH5_tf = input.timeframe("1W", "EMA 10 Timeframe", inline="Ema10")
// emaH5Length = input.int(10, "Periyot", inline="Ema10")
// emaH5Color = input.color(color.rgb(10, 243, 255), "Renk", inline="Ema10")

// // EMA 14 için parametreler
// emaSlow_tf = input.timeframe("1W", "EMA 14 Timeframe", inline="ema14")
// emaSlowLength = input.int(14, "Periyot", inline="ema14")
// ema14Color = input.color(color.orange, "Renk", inline="ema14")

// // Günlük EMA 34 için parametreler
// emaDaily_tf = input.timeframe("1D", "EMA 34 Timeframe", inline="ema34")
// emaDailyLength = input.int(34, "Periyot", inline="ema34")
// ema34Color = input.color(color.rgb(33, 37, 243), "Renk", inline="ema34")

// // Günlük EMA 610 için parametreler
// ema5144dak_tf = input.timeframe("5", "EMA 610 Timeframe", inline="Ema144")
// ema5144dakLength = input.int(610, "Periyot", inline="Ema144")
// ema5144Color = input.color(color.rgb(255, 255, 255), "Renk", inline="Ema144")

// // Kijun için parametreler
// kijun_tf = input.timeframe("1W", "Kijun Timeframe", inline="kijun")
// kijunPeriod = input.int(21, "Periyot", inline="kijun")
// kijunColor = input.color(#9b27b084, "Renk", inline="kijun", display=display.none)

// ghostColor = input.color(color.green, "Ghost Çizgi Rengi", display=display.none)

// // EMA hesaplamaları
// ema_8 = request.security(syminfo.tickerid, emaFast_tf, ta.ema(close, emaFastLength), barmerge.gaps_off)
// ema_10 = request.security(syminfo.tickerid, emaH5_tf, ta.ema(close, emaH5Length), barmerge.gaps_off)
// ema_14 = request.security(syminfo.tickerid, emaSlow_tf, ta.ema(close, emaSlowLength), barmerge.gaps_off)
// ema_34 = request.security(syminfo.tickerid, emaDaily_tf, ta.ema(close, emaDailyLength), barmerge.gaps_off)
// ema_144 = request.security(syminfo.tickerid, ema5144dak_tf, ta.ema(close, ema5144dakLength), barmerge.gaps_off)

// // Kijun hesaplaması
// kijun = request.security(syminfo.tickerid, kijun_tf, math.avg(ta.lowest(low, kijunPeriod), ta.highest(high, kijunPeriod)), barmerge.gaps_off)

// // EMA Ghost hesaplaması
// emaGhost = ema_8 * 1.10

// // Çizgilerin çizilmesi
// plot(ema_8, "EMA H_8", color=ema8Color, linewidth=2, display=display.none)
// plot(ema_10, "EMA H_10", color=emaH5Color, linewidth=2, display=display.none)
// plot(ema_14, "EMA H_14", color=ema14Color, linewidth=2, display=display.none)
// plot(ema_34, "EMA G_34", color=ema34Color, linewidth=2, display = display.none)
// plot(ema_144, "EMA 5D_610", color=ema5144Color, linewidth=2, display = display.none)
// plot(kijun, "Kijun", color=kijunColor, linewidth=2, display=display.none)
// plot(emaGhost, "EMA Ghost", color=ghostColor, linewidth=2, style=plot.style_circles, display=display.none)

// MTF KOMP 34 VE 233

// Zaman dilimi seçimi (menüdeki değerlerle)
selected_timeframe_str = input.string("1 Gün", title="Zaman Dilimi Seç", options=[    "1 Kademe", "10 Kademe", "4100 Kademe", "41000 Kademe",     "4 saniye", "5 saniye", "10 saniye", "15 saniye", "30 saniye",     "1 dakika", "2 dakika", "3 dakika", "5 dakika", "8 dakika", "9 dakika",     "10 dakika", "15 dakika", "19 dakika", "29 dakika", "30 dakika",     "31 dakika", "44 dakika", "45 dakika", "50 dakika", "64 dakika",     "118 dakika", "165 dakika", "170 dakika", "235 dakika", "535 dakika",     "1 saat", "2 saat", "3 saat", "4 saat", "6 saat", "8 saat", "12 saat",     "1 Gün", "2 Gün", "3 Gün", "1 Hafta", "1 Ay"], group="MTF Komp EMA ", inline="MTF 34 233")

// Comparative Relative Strength calculations
// comparativeTickerId = input.symbol('BIST:XU100', title = 'KOM SYMBOL', inline="group3", group='Komp - RSI Settings')
xu100 = request.security('BIST:XU100', timeframe.period, close)

//functions
xrf(values, length) =>
    r_val = float(na)
    if length >= 1
        for i = 0 to length by 1
            if na(r_val) or not na(values[i])
                r_val := values[i]
                r_val
    r_val

xsa(src, len, wei) =>
    sumf = 0.0
    ma = 0.0
    out = 0.0
    sumf := nz(sumf[1]) - nz(src[len]) + src
    ma := na(src[len]) ? na : sumf / len
    out := na(out[1]) ? ma : (src * wei + out[1] * (len - wei)) / len
    out

//set up a simple model of banker fund flow trend	
fundtrend = (3 * xsa((close - ta.lowest(low, 27)) / (ta.highest(high, 27) - ta.lowest(low, 27)) * 100, 5, 1) - 2 * xsa(xsa((close - ta.lowest(low, 27)) / (ta.highest(high, 27) - ta.lowest(low, 27)) * 100, 5, 1), 3, 1) - 50) * 1.032 + 50
//define typical price for banker fund
typ = (2 * close + high + low + open) / 5
//lowest low with mid term fib # 34
lol = ta.lowest(low, 34)
//highest high with mid term fib # 34
hoh = ta.highest(high, 34)
//define banker fund flow bull bear line
bullbearline = ta.ema((typ - lol) / (hoh - lol) * 100, 13)
//define banker entry signal
bankerentry = ta.crossover(fundtrend, bullbearline) and bullbearline < 41
bankerexit = ta.crossunder(fundtrend, bullbearline) and bullbearline > 75

//banker fund entry with yellow candle
// Banker fund entry with yellow circle
plotshape(bankerentry, style=shape.circle, location=location.belowbar, color=#ffffff92, size=size.small)

// // Banker fund exit with red circle
plotshape(bankerexit, style=shape.circle, location=location.abovebar, color=#b90cf34d, size=size.small)

// Variables for 3D timeframe
fundtrend_3d = request.security(syminfo.tickerid, "3D",  (3 * xsa((close - ta.lowest(low, 27)) / (ta.highest(high, 27) - ta.lowest(low, 27)) * 100, 5, 1) -  2 * xsa(xsa((close - ta.lowest(low, 27)) / (ta.highest(high, 27) - ta.lowest(low, 27)) * 100, 5, 1), 3, 1) -  50) * 1.032 + 50)

typ_3d = request.security(syminfo.tickerid, "3D", (2 * close + high + low + open) / 5)

lol_3d = request.security(syminfo.tickerid, "3D", ta.lowest(low, 34))
hoh_3d = request.security(syminfo.tickerid, "3D", ta.highest(high, 34))

bullbearline_3d = request.security(syminfo.tickerid, "3D", ta.ema((typ_3d - lol_3d) / (hoh_3d - lol_3d) * 100, 13))

bankerentry_3d = request.security(syminfo.tickerid, "3D", ta.crossover(fundtrend_3d, bullbearline_3d) and bullbearline_3d < 41)
bankerexit_3d = request.security(syminfo.tickerid, "3D", ta.crossunder(fundtrend_3d, bullbearline_3d) and bullbearline_3d > 60)

// Banker fund entry with yellow candle
// plotcandle(0, 50, 0, 5000, color = bankerentry_3d ? #ffffff33 : na, wickcolor = bankerentry_3d ? #00000000 : na, bordercolor = bankerentry_3d ? #00000000 : na, offset=0)
// plotcandle(0, 50, 0, 5000, color = bankerexit_3d ? #1613d35e : na, wickcolor = bankerexit_3d ? #00000000 : na, bordercolor = bankerexit_3d ? #00000000 : na, offset=0)

// Using plotshape for entry and exit signals with offset
plotshape(bankerentry_3d, color = #ffe10072, style = shape.triangleup, location = location.belowbar, offset = -8, size=size.small)  // Entry signal with offset
plotshape(bankerexit_3d, color = #6e1e1e9d, style = shape.triangledown, location = location.abovebar, offset = -8, size=size.small) // Exit signal with offset

// Zaman dilimini Pine Script formatına çeviren fonksiyon
f_convert_timeframe(tf_str) =>
    if tf_str == "1 Kademe"
        "1"
    else if tf_str == "10 Kademe"
        "10"
    else if tf_str == "4100 Kademe"
        "4100"
    else if tf_str == "41000 Kademe"
        "41000"
    else if tf_str == "4 saniye"
        "4S"
    else if tf_str == "5 saniye"
        "5S"
    else if tf_str == "10 saniye"
        "10S"
    else if tf_str == "15 saniye"
        "15S"
    else if tf_str == "30 saniye"
        "30S"
    else if tf_str == "1 dakika"
        "1"
    else if tf_str == "2 dakika"
        "2"
    else if tf_str == "3 dakika"
        "3"
    else if tf_str == "5 dakika"
        "5"
    else if tf_str == "8 dakika"
        "8"
    else if tf_str == "9 dakika"
        "9"
    else if tf_str == "10 dakika"
        "10"
    else if tf_str == "15 dakika"
        "15"
    else if tf_str == "19 dakika"
        "19"
    else if tf_str == "29 dakika"
        "29"
    else if tf_str == "30 dakika"
        "30"
    else if tf_str == "31 dakika"
        "31"
    else if tf_str == "44 dakika"
        "44"
    else if tf_str == "45 dakika"
        "45"
    else if tf_str == "50 dakika"
        "50"
    else if tf_str == "64 dakika"
        "64"
    else if tf_str == "118 dakika"
        "118"
    else if tf_str == "165 dakika"
        "165"
    else if tf_str == "170 dakika"
        "170"
    else if tf_str == "235 dakika"
        "235"
    else if tf_str == "535 dakika"
        "535"
    else if tf_str == "1 saat"
        "60"
    else if tf_str == "2 saat"
        "120"
    else if tf_str == "3 saat"
        "180"
    else if tf_str == "4 saat"
        "240"
    else if tf_str == "6 saat"
        "360"
    else if tf_str == "8 saat"
        "480"
    else if tf_str == "12 saat"
        "720"
    else if tf_str == "1 Gün"
        "D"
    else if tf_str == "2 Gün"
        "2D"
    else if tf_str == "3 Gün"
        "3D"
    else if tf_str == "1 Hafta"
        "W"
    else if tf_str == "1 Ay"
        "M"
    else
        "D"  // Varsayılan olarak 1 dakika

// Seçilen zaman dilimini Pine Script formatına çevir
selected_timeframe = f_convert_timeframe(selected_timeframe_str)

// XU100 fiyatı ve EMA uzunlukları
compEmaLength34mtf = input.int(34, title='MTF KOMP 34', group="MTF COMP EMA Display", inline="MTF - 34 233")
compEmaLength233mtf = input.int(233, title='MTF KOMP 233', group="MTF COMP EMA Display", inline="MTF - 34 233")

// Seçilen zaman dilimine göre EMA hesaplama
comp_ema34mtf = request.security(syminfo.tickerid, selected_timeframe, ta.ema(close / xu100, compEmaLength34mtf))
comp_ema233mtf = request.security(syminfo.tickerid, selected_timeframe, ta.ema(close / xu100, compEmaLength233mtf))

// Çizgi ve etiketler için değişkenler
var line ema_line34mtf = na
var label ema_label34mtf = na

var line ema_line233mtf = na
var label ema_label233mtf = na

// Çizgileri ve etiketleri oluşturma
if bar_index > 6
    // EMA 34
    if na(ema_line34mtf)
        ema_line34mtf := line.new(x1=bar_index, y1=comp_ema34mtf * xu100, x2=bar_index + 16, y2=comp_ema34mtf * xu100, color=#f30000, width=2)
        ema_label34mtf := label.new(x=bar_index + 17, y=comp_ema34mtf * xu100, text=selected_timeframe_str + " KOMP-34: " + str.tostring(comp_ema34mtf * xu100, '#.##'), style=label.style_label_left, color=color.new(color.white, 100), textcolor=#f30000, size=size.normal)
    else
        line.set_xy1(ema_line34mtf, bar_index, comp_ema34mtf * xu100)
        line.set_xy2(ema_line34mtf, bar_index + 16, comp_ema34mtf * xu100)
        label.set_x(ema_label34mtf, bar_index + 16)
        label.set_y(ema_label34mtf, comp_ema34mtf * xu100)
        label.set_text(ema_label34mtf, selected_timeframe_str + " KOMP-34: " + str.tostring(comp_ema34mtf * xu100, '#.##'))
        label.set_size(ema_label34mtf, size.normal)
    
    // EMA 233
    if na(ema_line233mtf)
        ema_line233mtf := line.new(x1=bar_index, y1=comp_ema233mtf * xu100, x2=bar_index + 16, y2=comp_ema233mtf * xu100, color=#ff9d00, width=2)
        ema_label233mtf := label.new(x=bar_index + 17, y=comp_ema233mtf * xu100, text=selected_timeframe_str + " KOMP-233: " + str.tostring(comp_ema233mtf * xu100, '#.##'), style=label.style_label_left, color=color.new(color.white, 100), textcolor=#ff9d00, size=size.normal)
    else
        line.set_xy1(ema_line233mtf, bar_index, comp_ema233mtf * xu100)
        line.set_xy2(ema_line233mtf, bar_index + 16, comp_ema233mtf * xu100)
        label.set_x(ema_label233mtf, bar_index + 16)
        label.set_y(ema_label233mtf, comp_ema233mtf * xu100)
        label.set_text(ema_label233mtf, selected_timeframe_str + " KOMP-233: " + str.tostring(comp_ema233mtf * xu100, '#.##'))
        label.set_size(ema_label233mtf, size.normal)

////hacim tablo///////

// Kullanıcıdan sembol girişleri
// Tabloyu göster/gizle düğmesi
showTable = input.bool(true, title="HACİM TABLOSUNU GÖSTER", group="HACİM TABLOSU")
string s01 = syminfo.ticker  // Mevcut grafikteki sembol kullanılır
frame_color1 = input.color(#000000, title="Çerçeve Rengi", group="HACİM TABLOSU", inline="THC")
frame_width1 = 2

// Parametreler
lookbackPeriod = input.int(23, title="Bar Sayısı", group="HACİM TABLOSU", inline="THC")

// Tablo konumu için kullanıcı girişi
tablePosition1 = input.string("top_center", title="Tablo Konumu", options=["top_left", "top_center", "top_right", "bottom_left", "bottom_center", "bottom_right"], group="HACİM TABLOSU", inline="THC")

// Tablo boyutu için kullanıcı girişi
tableSize = input.string("normal", title="Tablo Boyutu", options=["tiny", "small", "normal", "large"], group="HACİM TABLOSU", inline="THC")

// Tablo stil ayarları için kullanıcı girişleri
tableBgColor1 = input.color(#000000, title="Arka Plan Rengi", group="HACİM TABLOSU", inline="THCE")
tableBorderColor1 = input.color(color.orange, title="Çerçeve Rengi", group="HACİM TABLOSU", inline="THCE")
tableBorderWidth1 = 2
// Renk seçenekleri için kullanıcı girişleri
headerColor = input.color(color.new(color.black, 0), title="Başlık Arka Plan Rengi", group="HACİM TABLOSU", inline="THCE")
buyColor = input.color(#4caf4f69, title="Alış Hacmi Rengi", group="HACİM TABLOSU", inline="THCE")
sellColor = input.color(#ff525279, title="Satış Hacmi Rengi", group="HACİM TABLOSU", inline="THCE")
resultBuyColor = input.color(#4caf4f70, title="Alış Rengi", group="HACİM TABLOSU", inline="THCE")
resultSellColor = input.color(#ff525260, title="Satış Rengi", group="HACİM TABLOSU", inline="THCE")
textColor = input.color(color.white, title="Metin Rengi", group="HACİM TABLOSU", inline="THCE")



// Hücre boyutlarını belirleme fonksiyonu
getFontSize(size) =>
    switch size
        "tiny" => size.tiny
        "small" => size.small
        "normal" => size.normal
        "large" => size.large

// Hacim hesaplama fonksiyonu
calculateVolumes(closeData, volumeData) =>
    float upVolumeSum = 0.0
    float downVolumeSum = 0.0

    for i = 0 to lookbackPeriod - 1
        upVolumeSum += (closeData[i] > closeData[i + 1] ? volumeData[i] : 0)
        downVolumeSum += (closeData[i] < closeData[i + 1] ? volumeData[i] : 0)

    totalVolume = upVolumeSum + downVolumeSum
    result = upVolumeSum > downVolumeSum ? "Pozitif" : "Negatif"
    [upVolumeSum, downVolumeSum, result]

// Mevcut sembol için hacim hesaplaması
[up1, down1, res1] = calculateVolumes(close, volume) 

// Tablo oluştur
var table volumeTable = na
if showTable
    if na(volumeTable)
        volumeTable := table.new(position=tablePosition1, columns=4, rows=2, bgcolor=tableBgColor1, border_color=tableBorderColor1, border_width=tableBorderWidth1, frame_color=frame_color1, frame_width=frame_width1)

    // Başlık satırı
    if bar_index == 0
        table.cell(volumeTable, 0, 0, "Hacim Analizi", bgcolor=headerColor, text_color=textColor, text_size=getFontSize(tableSize))
        table.cell(volumeTable, 1, 0, "Alış Hacmi", bgcolor=headerColor, text_color=textColor, text_size=getFontSize(tableSize))
        table.cell(volumeTable, 2, 0, "Satış Hacmi", bgcolor=headerColor, text_color=textColor, text_size=getFontSize(tableSize))
        table.cell(volumeTable, 3, 0, "Sonuç", bgcolor=headerColor, text_color=textColor, text_size=getFontSize(tableSize))

    // Mevcut sembol verilerini tabloya ekle
    table.cell(volumeTable, 0, 1, s01, text_color=textColor, text_size=getFontSize(tableSize))
    table.cell(volumeTable, 1, 1, str.tostring(up1, format.volume), bgcolor=buyColor, text_color=textColor, text_size=getFontSize(tableSize))
    table.cell(volumeTable, 2, 1, str.tostring(down1, format.volume), bgcolor=sellColor, text_color=textColor, text_size=getFontSize(tableSize))
    table.cell(volumeTable, 3, 1, res1, bgcolor=res1 == "Pozitif" ? resultBuyColor : resultSellColor, text_color=textColor, text_size=getFontSize(tableSize))
else
    if not na(volumeTable)
        table.delete(volumeTable)
        volumeTable := na


// EMA VE KOMPOZİTLER

// Add enable/disable settings for comparative EMAs
show_comp_ema34 = input.bool(false, "KOMP EMA 34", group="Kompozit EMA ", inline="34")
color_ema34 = input.color(color.red, "", group="Kompozit EMA ", inline="34")

show_comp_ema55 = input.bool(false, "KOMP EMA 55", group="Kompozit EMA ", inline="55")
color_ema55 = input.color(color.orange, "", group="Kompozit EMA ", inline="55")

show_comp_ema89 = input.bool(false, "KOMP EMA 89", group="Kompozit EMA ", inline="89")
color_ema89 = input.color(color.teal, "", group="Kompozit EMA ", inline="89")

show_comp_ema233 = input.bool(false, "KOMP EMA 233", group="Kompozit EMA ", inline="233")
color_ema233 = input.color(color.purple, "", group="Kompozit EMA ", inline="233")

show_comp_ema377 = input.bool(false, "KOMP EMA 377", group="Kompozit EMA ", inline="377")
color_ema377 = input.color(color.blue, "", group="Kompozit EMA ", inline="377")

show_comp_ema610 = input.bool(false, "KOMP EMA 610", group="Kompozit EMA ", inline="610")
color_ema610 = input.color(color.gray, "", group="Kompozit EMA ", inline="610")

show_comp_ema987 = input.bool(false, "KOMP EMA 987", group="Kompozit EMA ", inline="987")
color_ema987 = input.color(color.maroon, "", group="Kompozit EMA ", inline="987")

show_comp_ema1597 = input.bool(false, "KOMP EMA 1597", group="Kompozit EMA ", inline="1597")
color_ema1597 = input.color(color.navy, "", group="Kompozit EMA ", inline="1597")

// show_comp_ema2584 = input.bool(false, "KOMP EMA 2584", group="Kompozit EMA ", inline="2584")
// color_ema2584 = input.color(color.aqua, "", group="Kompozit EMA ", inline="2584")

// show_comp_ema4181 = input.bool(false, "KOMP EMA 4181", group="Kompozit EMA ", inline="4181")
// color_ema4181 = input.color(color.fuchsia, "", group="Kompozit EMA ", inline="4181")

// showema34_1s  = input.bool(true, "EMA 34 1s", group="EMA Values")

// Add text size control for comparative EMA labels
comp_ema_text_size = input.string("normal", "KOMP EMA Label Size", options=["tiny", "small", "normal", "large"], group="Kompozit EMA ")

// Convert text size input to size constant
get_text_size() =>
    switch comp_ema_text_size
        "tiny" => size.tiny
        "small" => size.small
        "large" => size.large
        => size.normal

// EMA Display Settings
// show_regular_ema12 = input.bool(false, "EMA 12", group="EMA ", inline="12")
// color_regular_ema12 = input.color(#368c3c, "", group="EMA ", inline="12", display=display.none)

// show_regular_ema26 = input.bool(false, "EMA 26", group="EMA ", inline="26")
// color_regular_ema26 = input.color(#e4cb0c, "", group="EMA ", inline="26", display=display.none)

show_regular_ema14 = input.bool(false, "EMA 14", group="EMA ", inline="14")
color_regular_ema14 = input.color(color.rgb(0, 255, 17), "", group="EMA ", inline="14", display=display.none)

show_regular_ema34 = input.bool(false, "EMA 34", group="EMA ", inline="34")
color_regular_ema34 = input.color(color.rgb(253, 0, 0), "", group="EMA ", inline="34", display=display.none)

show_regular_ema55 = input.bool(false, "EMA 55", group="EMA ", inline="55")
color_regular_ema55 = input.color(#f8a407, "", group="EMA ", inline="55", display=display.none)

show_regular_ema89 = input.bool(false, "EMA 89", group="EMA ", inline="89")
color_regular_ema89 = input.color(color.rgb(207, 193, 166), "", group="EMA ", inline="89", display=display.none)

show_regular_ema144 = input.bool(false, "EMA 144", group="EMA ", inline="144")
color_regular_ema144 = input.color(color.rgb(184, 25, 232), "", group="EMA ", inline="144", display=display.none)

show_regular_ema233 = input.bool(false, "EMA 233", group="EMA ", inline="233")
color_regular_ema233 = input.color(color.rgb(0, 203, 254), "", group="EMA ", inline="233", display=display.none)

show_regular_ema377 = input.bool(false, "EMA 377", group="EMA ", inline="377")
color_regular_ema377 = input.color(color.rgb(7, 89, 240), "", group="EMA ", inline="377", display=display.none)

show_regular_ema610 = input.bool(false, "EMA 610", group="EMA ", inline="610")
color_regular_ema610 = input.color(color.rgb(124, 128, 131), "", group="EMA ", inline="610", display=display.none)

show_regular_ema987 = input.bool(false, "EMA 987", group="EMA ", inline="987")
color_regular_ema987 = input.color(#fc009b, "", group="EMA ", inline="987", display=display.none)

// show_regular_ema1597 = input.bool(false, "EMA 1597", group="EMA ", inline="1597")
// color_regular_ema1597 = input.color(color.rgb(145, 18, 18), "", group="EMA ", inline="1597", display=display.none)

// show_regular_ema115 = input.bool(false, "PIVOT 115", group="EMA ", inline="115")
// color_regular_ema115 = input.color(#ea754b, "", group="EMA ", inline="115", display=display.none)

// EMA Length inputs
// emaLength1 = input.int(12, title = '', group="EMA ", inline="12")
// emaLength2 = input.int(26, title = '', group="EMA ", inline="26")
emaLength12 = input.int(14, title = '', group="EMA ", inline="14")
emaLength3 = input.int(34, title = '', group="EMA ", inline="34")
emaLength4 = input.int(55, title = '', group="EMA ", inline="55")
emaLength10 = input.int(89, title = '', group="EMA ", inline="89")
emaLength5 = input.int(144, title = '', group="EMA ", inline="144")
emaLength6 = input.int(233, title = '', group="EMA ", inline="233")
emaLength7 = input.int(377, title = '', group="EMA ", inline="377")
emaLength8 = input.int(610, title = '', group="EMA ", inline="610")
emaLength9 = input.int(987, title = '', group="EMA ", inline="987")
// emaLength13 = input.int(115, title = '', group="EMA ", inline="115")

// Calculate Regular EMAs
// ema12 = ta.ema(close, emaLength1)
// ema26 = ta.ema(close, emaLength2)
ema14 = ta.ema(close, emaLength12)
ema34 = ta.ema(close, emaLength3)
ema55 = ta.ema(close, emaLength4)
ema89 = ta.ema(close, emaLength10)
ema144 = ta.ema(close, emaLength5)
ema233 = ta.ema(close, emaLength6)
ema377 = ta.ema(close, emaLength7)
ema610 = ta.ema(close, emaLength8)
ema987 = ta.ema(close, emaLength9)
// ema115 = ta.ema(close, emaLength13)

// Plot fonksiyonları - stil panelinde görünmeden ama parametre kontrolü çalışarak
// plot(show_regular_ema12 ? ema12 : na, title='12', color=color_regular_ema12, linewidth=2)
// plot(show_regular_ema26 ? ema26 : na, title='26', color=color_regular_ema26, linewidth=2)
plot(show_regular_ema14 ? ema14 : na, title='', color=color_regular_ema14, linewidth=2)
plot(show_regular_ema34 ? ema34 : na, title='34', color=color_regular_ema34, linewidth=2)
plot(show_regular_ema55 ? ema55 : na, title='55', color=color_regular_ema55, linewidth=2)
plot(show_regular_ema89 ? ema89 : na, title='89', color=color_regular_ema89, linewidth=2)
plot(show_regular_ema144 ? ema144 : na, title='144', color=color_regular_ema144, linewidth=2)
plot(show_regular_ema233 ? ema233 : na, title='233', color=color_regular_ema233, linewidth=2)
plot(show_regular_ema377 ? ema377 : na, title='377', color=color_regular_ema377, linewidth=2)
plot(show_regular_ema610 ? ema610 : na, title='610', color=color_regular_ema610, linewidth=2)
plot(show_regular_ema987 ? ema987 : na, title='987', color=color_regular_ema987, linewidth=2)
// plot(show_regular_ema115 ? ema115 : na, title='115', color=color_regular_ema115, linewidth=2)

// XU100 fiyatı ve EMA uzunlukları
xu100N = request.security('BIST:XU100', timeframe.period, close)
compEmaLength34 = input.int(34, title='', group="Kompozit EMA ", inline="34")
compEmaLength55 = input.int(55, title='', group="Kompozit EMA ", inline="55")
compEmaLength89 = input.int(89, title='', group="Kompozit EMA ", inline="89")
compEmaLength233 = input.int(233, title='', group="Kompozit EMA ", inline="233")
compEmaLength377 = input.int(377, title='', group="Kompozit EMA ", inline="377")
compEmaLength610 = input.int(610, title='', group="Kompozit EMA ", inline="610")
compEmaLength987 = input.int(987, title='', group="Kompozit EMA ", inline="987")
compEmaLength1597 = input.int(1597, title='', group="Kompozit EMA ", inline="1597")
// compEmaLength2584 = input.int(2584, title='', group="Kompozit EMA ", inline="2584")
// compEmaLength4181 = input.int(4181, title='', group="Kompozit EMA ", inline="4181")

// Mevcut varlığın fiyatı ile XU100 arasındaki oran üzerinden EMA hesaplama
comp_ema34 = ta.ema(close / xu100N, compEmaLength34)
comp_ema55 = ta.ema(close / xu100N, compEmaLength55)
comp_ema89 = ta.ema(close / xu100N, compEmaLength89)
comp_ema233 = ta.ema(close / xu100N, compEmaLength233)
comp_ema377 = ta.ema(close / xu100N, compEmaLength377)
comp_ema610 = ta.ema(close / xu100N, compEmaLength610)
comp_ema987 = ta.ema(close / xu100N, compEmaLength987)
comp_ema1597 = ta.ema(close / xu100N, compEmaLength1597)
// comp_ema2584 = ta.ema(close / xu100N, compEmaLength2584)
// comp_ema4181 = ta.ema(close / xu100N, compEmaLength4181)

// Çizgi ve etiketler için değişkenler
var line ema_line1 = na
var label ema_label1 = na

var line ema_line2 = na
var label ema_label2 = na

var line ema_line3 = na
var label ema_label3 = na

var line ema_line4 = na
var label ema_label4 = na

var line ema_line5 = na
var label ema_label5 = na

var line ema_line6 = na
var label ema_label6 = na

var line ema_line7 = na
var label ema_label7 = na

var line ema_line8 = na
var label ema_label8 = na

// var line ema_line9 = na
// var label ema_label9 = na

// var line ema_line10 = na
// var label ema_label10 = na

 // Çizgileri ve etiketleri oluşturma

if bar_index > 6

    // EMA 34
    if na(ema_line1) and show_comp_ema34
        ema_line1 := line.new(x1=bar_index, y1=comp_ema34 * xu100, x2=bar_index + 6, y2=comp_ema34 * xu100, color=color_ema34, width=2)
        ema_label1 := label.new(x=bar_index + 7, y=comp_ema34 * xu100, text=str.tostring(comp_ema34 * xu100, '#.##'), style=label.style_label_left, color=color.new(color.white, 100), textcolor=color_ema34, size=size.normal)
    else if show_comp_ema34
        line.set_xy1(ema_line1, bar_index, comp_ema34 * xu100)
        line.set_xy2(ema_line1, bar_index + 6, comp_ema34 * xu100)
        label.set_x(ema_label1, bar_index + 6)  // Çizginin bitiş noktasına sabitle
        label.set_y(ema_label1, comp_ema34 * xu100)
        label.set_text(ema_label1,  "KOMP-34: " +  str.tostring(comp_ema34 * xu100, '#.##'))
        label.set_size(ema_label1, get_text_size())
    
    // EMA 55
    if na(ema_line2) and show_comp_ema55
        ema_line2 := line.new(x1=bar_index, y1=comp_ema55 * xu100, x2=bar_index + 6, y2=comp_ema55 * xu100, color=color_ema55, width=2)
        ema_label2 := label.new(x=bar_index + 7, y=comp_ema55 * xu100, text=str.tostring(comp_ema55 * xu100, '#.##'), style=label.style_label_left, color=color.new(color.white, 100), textcolor=color_ema55, size=size.normal)
    else if show_comp_ema55
        line.set_xy1(ema_line2, bar_index, comp_ema55 * xu100)
        line.set_xy2(ema_line2, bar_index + 6, comp_ema55 * xu100)
        label.set_x(ema_label2, bar_index + 6)
        label.set_y(ema_label2, comp_ema55 * xu100)
        label.set_text(ema_label2,  "KOMP-55: " + str.tostring(comp_ema55 * xu100, '#.##'))
        label.set_size(ema_label2, get_text_size())

    // EMA 89
    if na(ema_line6) and show_comp_ema89
        ema_line6 := line.new(x1=bar_index, y1=comp_ema89 * xu100, x2=bar_index + 6, y2=comp_ema89 * xu100, color=color_ema89, width=2)
        ema_label6 := label.new(x=bar_index + 7, y=comp_ema89 * xu100, text=str.tostring(comp_ema89 * xu100, '#.##'), style=label.style_label_left, color=color.new(color.white, 100), textcolor=color_ema89, size=size.normal)
    else if show_comp_ema89
        line.set_xy1(ema_line6, bar_index, comp_ema89 * xu100)
        line.set_xy2(ema_line6, bar_index + 6, comp_ema89 * xu100)
        label.set_x(ema_label6, bar_index + 6)
        label.set_y(ema_label6, comp_ema89 * xu100)
        label.set_text(ema_label6,  "KOMP-89: " + str.tostring(comp_ema89 * xu100, '#.##'))
        label.set_size(ema_label6, get_text_size())

    // EMA 233
    if na(ema_line3) and show_comp_ema233
        ema_line3 := line.new(x1=bar_index, y1=comp_ema233 * xu100, x2=bar_index + 6, y2=comp_ema233 * xu100, color=color_ema233, width=2)
        ema_label3 := label.new(x=bar_index + 7, y=comp_ema233 * xu100, text=str.tostring(comp_ema233 * xu100, '#.##'), style=label.style_label_left, color=color.new(color.white, 100), textcolor=color_ema233, size=size.normal)
    else if show_comp_ema233
        line.set_xy1(ema_line3, bar_index, comp_ema233 * xu100)
        line.set_xy2(ema_line3, bar_index + 6, comp_ema233 * xu100)
        label.set_x(ema_label3, bar_index + 6)
        label.set_y(ema_label3, comp_ema233 * xu100)
        label.set_text(ema_label3,  "KOMP-233: " + str.tostring(comp_ema233 * xu100, '#.##'))
        label.set_size(ema_label3, get_text_size())

    // EMA 377
    if na(ema_line4) and show_comp_ema377
        ema_line4 := line.new(x1=bar_index, y1=comp_ema377 * xu100, x2=bar_index + 6, y2=comp_ema377 * xu100, color=color_ema377, width=2)
        ema_label4 := label.new(x=bar_index + 7, y=comp_ema377 * xu100, text=str.tostring(comp_ema377 * xu100, '#.##'), style=label.style_label_left, color=color.new(color.white, 100), textcolor=color_ema377, size=size.normal)
    else if show_comp_ema377
        line.set_xy1(ema_line4, bar_index, comp_ema377 * xu100)
        line.set_xy2(ema_line4, bar_index + 6, comp_ema377 * xu100)
        label.set_x(ema_label4, bar_index + 6)
        label.set_y(ema_label4, comp_ema377 * xu100)
        label.set_text(ema_label4,  "KOMP-377: " + str.tostring(comp_ema377 * xu100, '#.##'))
        label.set_size(ema_label4, get_text_size())

    // EMA 610
    if na(ema_line5) and show_comp_ema610
        ema_line5 := line.new(x1=bar_index, y1=comp_ema610 * xu100, x2=bar_index + 6, y2=comp_ema610 * xu100, color=color_ema610, width=2)
        ema_label5 := label.new(x=bar_index + 7, y=comp_ema610 * xu100, text=str.tostring(comp_ema610 * xu100, '#.##'), style=label.style_label_left, color=color.new(color.white, 100), textcolor=color_ema610, size=size.normal)
    else if show_comp_ema610
        line.set_xy1(ema_line5, bar_index, comp_ema610 * xu100)
        line.set_xy2(ema_line5, bar_index + 6, comp_ema610 * xu100)
        label.set_x(ema_label5, bar_index + 6)
        label.set_y(ema_label5, comp_ema610 * xu100)
        label.set_text(ema_label5,  "KOMP-610: " + str.tostring(comp_ema610 * xu100, '#.##'))
        label.set_size(ema_label5, get_text_size())

    // EMA 987
    if na(ema_line8) and show_comp_ema987
        ema_line8 := line.new(x1=bar_index, y1=comp_ema987 * xu100, x2=bar_index + 6, y2=comp_ema987 * xu100, color=color_ema987, width=2)
        ema_label8 := label.new(x=bar_index + 7, y=comp_ema987 * xu100, text=str.tostring(comp_ema987 * xu100, '#.##'), style=label.style_label_left, color=color.new(color.white, 100), textcolor=color_ema987, size=size.normal)
    else if show_comp_ema987
        line.set_xy1(ema_line8, bar_index, comp_ema987 * xu100)
        line.set_xy2(ema_line8, bar_index + 6, comp_ema987 * xu100)
        label.set_x(ema_label8, bar_index + 6)  // Çizginin bitiş noktasına sabitle
        label.set_y(ema_label8, comp_ema987 * xu100)
        label.set_text(ema_label8,  "KOMP-987: " + str.tostring(comp_ema987 * xu100, '#.##'))
        label.set_size(ema_label8, get_text_size())

    // EMA 1597
    if na(ema_line7) and show_comp_ema1597
        ema_line7 := line.new(x1=bar_index, y1=comp_ema1597 * xu100, x2=bar_index + 6, y2=comp_ema1597 * xu100, color=color_ema1597, width=2)
        ema_label7 := label.new(x=bar_index + 7, y=comp_ema1597 * xu100, text="EMA-1597: " + str.tostring(comp_ema1597 * xu100, '#.##'), style=label.style_label_left, color=color.new(color.white, 100), textcolor=color_ema1597, size=size.normal)
    else if show_comp_ema1597
        line.set_xy1(ema_line7, bar_index, comp_ema1597 * xu100)
        line.set_xy2(ema_line7, bar_index + 6, comp_ema1597 * xu100)
        label.set_x(ema_label7, bar_index + 6)
        label.set_y(ema_label7, comp_ema1597 * xu100)
        label.set_text(ema_label7, "KOMP-1597: " + str.tostring(comp_ema1597 * xu100, '#.##'))
        label.set_size(ema_label7, get_text_size())

    // // EMA 2584
    // if na(ema_line9) and show_comp_ema2584
    //     ema_line9 := line.new(x1=bar_index, y1=comp_ema2584 * xu100, x2=bar_index + 6, y2=comp_ema2584 * xu100, color=color_ema2584, width=2)
    //     ema_label9 := label.new(x=bar_index + 7, y=comp_ema2584 * xu100, text=str.tostring(comp_ema2584 * xu100, '#.##'), style=label.style_label_left, color=color.new(color.white, 100), textcolor=color_ema2584, size=get_text_size())
    // else if show_comp_ema2584
    //     line.set_xy1(ema_line9, bar_index, comp_ema2584 * xu100)
    //     line.set_xy2(ema_line9, bar_index + 6, comp_ema2584 * xu100)
    //     label.set_x(ema_label9, bar_index + 6)
    //     label.set_y(ema_label9, comp_ema2584 * xu100)
    //     label.set_text(ema_label9, "KOMP-2584: " + str.tostring(comp_ema2584 * xu100, '#.##'))
    //     label.set_size(ema_label9, get_text_size())
    
    // // EMA 4181
    // if na(ema_line10) and show_comp_ema4181
    //     ema_line10 := line.new(x1=bar_index, y1=comp_ema4181 * xu100, x2=bar_index + 6, y2=comp_ema4181 * xu100, color=color_ema4181, width=2)
    //     ema_label10 := label.new(x=bar_index + 7, y=comp_ema4181 * xu100, text=str.tostring(comp_ema4181 * xu100, '#.##'), style=label.style_label_left, color=color.new(color.white, 100), textcolor=color_ema4181, size=size.large)
    // else if show_comp_ema4181
    //     line.set_xy1(ema_line10, bar_index, comp_ema4181 * xu100)
    //     line.set_xy2(ema_line10, bar_index + 6, comp_ema4181 * xu100)
    //     label.set_x(ema_label10, bar_index + 6)  // Çizginin bitiş noktasına sabitle
    //     label.set_y(ema_label10, comp_ema4181 * xu100)
    //     label.set_text(ema_label10, str.tostring(comp_ema4181 * xu100, '#.##'))

// ---------------------------- Theme --------------------------------------- //
// Colors
red = color.red
green = color.rgb(21, 194, 122)
brightred = color.rgb(158, 43, 35)
brightgreen = color.rgb(21, 194, 122)
cautioncol = color.yellow
gray= color.gray
aqua = color.aqua
orange= color.orange
darkgreen = color.rgb(21, 194, 122)
darkred = color.rgb(165, 57, 66)

// Groups 
grma = "📈 Moving Averages 📈"
grhts = "Trend Seviyeleri"
grt = "🎯 Targets 🎯"
grll = "🩸 Leverage Liquidations 🩸"
gla= "🔔 Alerts 🔔"

// Constants
dataType = "Custom"
instructions = "Off"
smaS = "Off"
constant = 1>0
rsi=ta.rsi(close,14)

// ------------------------- Trend State ------------------------------------ //
// Code Author: © Koalafied_3
showtrend = true
//   tooltip ="Check this box if you want to see the Bull, Bear, or Chop trend state background according to Hayden.\n(Page 56) 10 Lies That Traders Believe = The RSI is unable to indicate trend direction, because it's only a momentum indicator.")
showbc = input(true, title='Bar Boyama Göster?',group=grhts)
ts1 = input.float(defval=66, title=" Bullish RSI  60 to 75", minval=60, maxval=75, step=1, group=grhts)
ts2 = input.float(defval=36, title=" Bearish RSI  28 to 40", minval=28, maxval=40, step=1, group=grhts)
ts1a = 61
ts2a = 39
// Trend State
var state = 0
if ta.crossover(rsi, ts1)
    state := 1
    state
if ta.crossunder(rsi, ts2) 
    state := 2
    state
state := state

//-----------------3 State RSI Gradient Bar Color on Chart--------------------//
cbullu = brightgreen
cbulld = darkgreen
cbearu = brightred
cbeard = darkred
cbearc = brightgreen
cbullc = brightred 

barcolor(state==1 and rsi>50?cbullu: state==1 and rsi<50?cbulld: state==2 and rsi<50 ?cbearu: state==2 and rsi>50 ?cbeard:color.new(color.from_gradient(rsi, ts2, ts1, cbearu, cbullu),0),title="Chart Bar Color", display = showbc ? display.all : display.none, editable=false)

// RSI 50 Line
// @ LazyBear
obLevelM = 50
src = close
length = 14
ep = 2 * length - 1
auc = ta.ema(math.max(src - src[1], 0), ep)
adc = ta.ema(math.max(src[1] - src, 0), ep)

x7 = (length - 1) * (adc * obLevelM / (100 - obLevelM) - auc)
ub4 = x7 >= 0 ? src + x7 : src + x7 * (100 - obLevelM) / obLevelM
plot(ub4, title='Rsn Mov', color=color.new(ub4>ub4[1]?color.green:ub4<ub4[1]?color.red:color.white, 25), linewidth=3)

// ------------------------------- Alerts ----------------------------------- // 
alert_freq = input.string(alert.freq_once_per_bar_close, "Alarm Türü", options=[alert.freq_once_per_bar_close, alert.freq_once_per_bar, alert.freq_all], group = gla)
bar_update_alerts = false

// ---------------------------- Trade Setup --------------------------------- //
// Inspired by @ KioseffTrading
lot_size = 1
dcaorstop = input.string("DCA 3", "DCA 3 or Stop", options=["DCA 3", "Stop"], group=grt)
// Number of Decimals for Labels
pricedecimals= 2
truncateprice(number, pricedecimals) =>
    factor = math.pow(10, pricedecimals)
    int(number * factor) / factor

// Define a bull/bear cross
bullcross= state==1 and state[1]==2
bearcross= state==2 and state[1]==1

// Detect what was last signal (long or short)
long_short = 0
long_last = bullcross and (nz(long_short[1]) == 0 or nz(long_short[1]) == -1)
short_last = bearcross and (nz(long_short[1]) == 0 or nz(long_short[1]) == 1)
long_short := long_last ? 1 : short_last ? -1 : long_short[1]

// Remove first bar for SL/TP (you can't enter a trade at bar close and THEN hit your SL on that same bar)
longBar1 = ta.barssince(long_last)
longBar2 = longBar1 >= 1 ? true : false
shortBar1 = ta.barssince(short_last)
shortBar2 = shortBar1 >= 1 ? true : false

// Wen entry, sir?
bullentry = ta.valuewhen(bullcross, close, 0) 
bearentry = ta.valuewhen(bearcross, close, 0) 
entin= state==1 and long_short==1?bullentry:state==2 and long_short==-1?bearentry:na
entout=plot(entin, 'Giriş', color=color.new(color.green, 0), style=plot.style_circles, editable=false)

// Targets
// ATR TP & SL
srcATR = input(title='ATR', defval=close, group=grt)
atrPeriod = input.int(title='ATR Period', defval=55, minval=1, group=grt)
per = atrPeriod
atrMultiplier = input.float(title='ATR Çarpanı', defval=3, group=grt)

atr = ta.atr(atrPeriod)
ATRupper=srcATR + atr * atrMultiplier
ATRlower=srcATR - atr * atrMultiplier
ATRupper2=srcATR + atr * (atrMultiplier*0.800)
ATRlower2=srcATR - atr * (atrMultiplier*0.800)
ATRupper3=srcATR + atr * (atrMultiplier*0.763)
ATRlower3=srcATR - atr * (atrMultiplier*0.763)
ATRupper4=srcATR + atr * (atrMultiplier*0.618)
ATRlower4=srcATR - atr * (atrMultiplier*0.618)
ATRupper5=srcATR + atr * (atrMultiplier*0.5)
ATRlower5=srcATR - atr * (atrMultiplier*0.5)
ATRupper6=srcATR + atr * (atrMultiplier*0.382)
ATRlower6=srcATR - atr * (atrMultiplier*0.382)
ATRupper7=srcATR + atr * (atrMultiplier*0.236)
ATRlower7=srcATR - atr * (atrMultiplier*0.236)
ATRupper8=srcATR + atr * (atrMultiplier*0.146)
ATRlower8=srcATR - atr * (atrMultiplier*0.146)
bearse=srcATR + atr * (atrMultiplier*0.146)
bullse=srcATR - atr * (atrMultiplier*0.146)
bearse2=srcATR + atr * (atrMultiplier*0.236)
bullse2=srcATR - atr * (atrMultiplier*0.236)
bearse3=srcATR + atr * (atrMultiplier*0.382)
bullse3=srcATR - atr * (atrMultiplier*0.382)

ATRbulltp1=ta.valuewhen(bullcross,ATRupper,0)
ATRbeartp1=ta.valuewhen(bearcross,ATRlower,0)
ATRbulltp2=ta.valuewhen(bullcross,ATRupper2,0)
ATRbeartp2=ta.valuewhen(bearcross,ATRlower2,0)
ATRbulltp3=ta.valuewhen(bullcross,ATRupper3,0)
ATRbeartp3=ta.valuewhen(bearcross,ATRlower3,0)
ATRbulltp4=ta.valuewhen(bullcross,ATRupper4,0)
ATRbeartp4=ta.valuewhen(bearcross,ATRlower4,0)
ATRbulltp5=ta.valuewhen(bullcross,ATRupper5,0)
ATRbeartp5=ta.valuewhen(bearcross,ATRlower5,0)
ATRbulltp6=ta.valuewhen(bullcross,ATRupper6,0)
ATRbeartp6=ta.valuewhen(bearcross,ATRlower6,0)
ATRbulltp7=ta.valuewhen(bullcross,ATRupper7,0)
ATRbeartp7=ta.valuewhen(bearcross,ATRlower7,0)
ATRbulltp8=ta.valuewhen(bullcross,ATRupper8,0)
ATRbeartp8=ta.valuewhen(bearcross,ATRlower8,0)
vwbearse=ta.valuewhen(bearcross,bearse,0)
vwbullse=ta.valuewhen(bullcross,bullse,0)
vwbearse2=ta.valuewhen(bearcross,bearse2,0)
vwbullse2=ta.valuewhen(bullcross,bullse2,0)
vwbearse3=ta.valuewhen(bearcross,bearse3,0)
vwbullse3=ta.valuewhen(bullcross,bullse3,0)

bgrad = 80
tgrad = 95

exin = state==1 and long_short==1?ATRbulltp1:state==2 and long_short==-1?ATRbeartp1:na
excol = long_short == 1 and close<ATRbulltp1?green: long_short==-1 and close>ATRbeartp1?red:color.yellow
exout = plot(exin, 'Kar AL', color=color.new(excol, 0), style=plot.style_circles, editable=false)
fill(entout,exout,exin,long_short==1?bullentry:long_short==-1?bearentry:na, top_color=color.new(long_short==1?darkgreen:long_short==-1?darkred:na,bgrad), bottom_color=color.new(long_short==1?darkgreen:long_short==-1?darkred:na,tgrad))
// tp2out = state==1 and long_short==1?ATRbulltp2:state==2 and long_short==-1?ATRbeartp2:na
// tp2col = long_short == 1 and close<ATRbulltp2?green: long_short==-1 and close>ATRbeartp2?red:color.white
// plot(tp2out, "TP 7", color=color.new(tp2col,10), style=plot.style_circles, show_last=1, editable=false)
// tp3out = state==1 and long_short==1?ATRbulltp3:state==2 and long_short==-1?ATRbeartp3:na
// tp3col = long_short == 1 and close<ATRbulltp3?green: long_short==-1 and close>ATRbeartp3?red:color.white
// plot(tp3out, "TP 6", color=color.new(tp3col,20), style=plot.style_circles, show_last=1, editable=false)
// tp4out = state==1 and long_short==1?ATRbulltp4:state==2 and long_short==-1?ATRbeartp4:na
// tp4col = long_short == 1 and close<ATRbulltp4?green: long_short==-1 and close>ATRbeartp4?red:color.white
// plot(tp4out, "TP 5", color=color.new(tp4col,30), style=plot.style_circles, show_last=1, editable=false)
// tp5out = state==1 and long_short==1?ATRbulltp5:state==2 and long_short==-1?ATRbeartp5:na
// tp5col = long_short == 1 and close<ATRbulltp5?green: long_short==-1 and close>ATRbeartp5?red:color.white
// plot(tp5out, "TP 4", color=color.new(tp5col,40), style=plot.style_circles, show_last=1, editable=false)
// tp6out = state==1 and long_short==1?ATRbulltp6:state==2 and long_short==-1?ATRbeartp6:na
// tp6col = long_short == 1 and close<ATRbulltp6?green: long_short==-1 and close>ATRbeartp6?red:color.white
// plot(tp6out, "TP 3", color=color.new(tp6col,50), style=plot.style_circles, show_last=1, editable=false)
// tp7out = state==1 and long_short==1?ATRbulltp7:state==2 and long_short==-1?ATRbeartp7:na
// tp7col = long_short == 1 and close<ATRbulltp7?green: long_short==-1 and close>ATRbeartp7?red:color.white
// plot(tp7out, "TP 2", color=color.new(tp7col,60), style=plot.style_circles, show_last=1, editable=false)
// tp8out = state==1 and long_short==1?ATRbulltp8:state==2 and long_short==-1?ATRbeartp8:na
// tp8col = long_short == 1 and close<ATRbulltp8?green: long_short==-1 and close>ATRbeartp8?red:color.white
// plot(tp8out, "TP 1", color=color.new(tp8col,60), style=plot.style_circles, show_last=1, editable=false)

// dca1in=state==1 and long_short==1?vwbullse:state==2 and long_short==-1?vwbearse:na
// dca1out=plot(dca1in, "DCA/Stop 1", color=color.new(color.white, 40), style=plot.style_circles, show_last=1, editable=false)
// dca2in=state==1 and long_short==1?vwbullse2:state==2 and long_short==-1?vwbearse2:na
// dca2out=plot(dca2in, "DCA/Stop 2", color=color.new(color.white, 20), style=plot.style_circles, show_last=1, editable=false)
dca3in=state==1 and long_short==1?vwbullse3:state==2 and long_short==-1?vwbearse3:na
dca3out=plot(dca3in, "Stop", color=color.new(color.red, 0), style=plot.style_circles, editable=false)
// fill(entout,dca3out,long_short==1?vwbullse3:long_short==-1?vwbearse3:na,long_short==1?bullentry:long_short==-1?bearentry:na, top_color=color.new(gray,85), bottom_color=color.new(gray,tgrad))

// Trade Setup Labels
// Profit
bullt1profit=(((ATRbulltp1/bullentry)- 1)*100)
beart1profit=((1-(bearentry/ATRbeartp1))*-100)
bullt2profit=(((ATRbulltp2/bullentry)- 1)*100)
beart2profit=((1-(bearentry/ATRbeartp2))*-100)
bullt3profit=(((ATRbulltp3/bullentry)- 1)*100)
beart3profit=((1-(bearentry/ATRbeartp3))*-100)
bullt4profit=(((ATRbulltp4/bullentry)- 1)*100)
beart4profit=((1-(bearentry/ATRbeartp4))*-100)
bullt5profit=(((ATRbulltp5/bullentry)- 1)*100)
beart5profit=((1-(bearentry/ATRbeartp5))*-100)
bullt6profit=(((ATRbulltp6/bullentry)- 1)*100)
beart6profit=((1-(bearentry/ATRbeartp6))*-100)
bullt7profit=(((ATRbulltp7/bullentry)- 1)*100)
beart7profit=((1-(bearentry/ATRbeartp7))*-100)
bullt8profit=(((ATRbulltp8/bullentry)- 1)*100)
beart8profit=((1-(bearentry/ATRbeartp8))*-100)

//-----------------------------Liquidation levels-----------------------------//
// @ mabonyi
i_show_x1 = false
i_nonlinear = false
i_maintmargin = 0.05
maint_margin = 1 - i_maintmargin
i_x1 = 100
i_showlast = 0
i_offset = 0 
i_label_offset = 0

// Calculations
f_leveraged(_price, _x) =>
    _xlong = i_nonlinear ? _x + 1 : _x
    _xshort = i_nonlinear ? _x - 1 : _x
    _liq_long = _price * (1 - 1 / _xlong * maint_margin)
    _liq_short = _price * (1 + 1 / _xshort * maint_margin)
    [_liq_long, _liq_short]

f_print(_y, _txt, _c) =>
    t = time_close + (i_offset + i_label_offset) * timeframe.multiplier * 60 * 1000
    var _lbl = label.new(t, _y, _txt, xloc.bar_time, yloc.price, color.white, label.style_none, _c, size.small)
    label.set_xy(_lbl, t, _y)
    label.set_text(_lbl, _txt)

[x1_long, x1_short] = f_leveraged(close, i_x1)

// Entry Liquidation Levels
longLiquidation = ta.valuewhen(long_last, x1_long, 0)
shortLiquidation = ta.valuewhen(short_last, x1_short, 0)
// Liquidation Line Adaptive Coloring
longliqlinecol = longLiquidation<vwbullse3 ? color.yellow:brightred
shortliqlinecol = shortLiquidation>vwbearse3 ? color.yellow:brightred
llcolout= long_short == 1 ? longliqlinecol : long_short==-1 ? shortliqlinecol : na
// Liquidation Lines & Fill 
llin=long_short == 1 and i_show_x1 ? longLiquidation : long_short == -1 and i_show_x1 ? shortLiquidation : na
llout=plot(llin, style=plot.style_circles, color=color.new(llcolout, 0), linewidth=1, title='Liquidation Level', editable=false)
liqfiltopcol=long_short==1 and longLiquidation < vwbullse3 ? color.new(color.yellow,85) : long_short==-1 and shortLiquidation > vwbearse3 ? color.new(color.yellow,90) : na
liqfilbotcol=long_short==1 and longLiquidation < vwbullse3 ? color.new(color.yellow,97) : long_short==-1 and shortLiquidation > vwbearse3 ? color.new(color.yellow,98) : na
fill(llout,dca3out, long_short==1?longLiquidation: long_short==-1?shortLiquidation: na, long_short==1?vwbullse3: long_short==-1?vwbearse3: na, top_color=liqfiltopcol, bottom_color=liqfilbotcol)
liqtip2 = i_show_x1 ? str.tostring(truncateprice(llin, pricedecimals)) : "None"
 // Liquidation Occured?
longliqhit=(ta.crossunder(low, longLiquidation) or low<longLiquidation) and long_short==1 and i_show_x1
shortliqhit=(ta.crossover(high, shortLiquidation) or high>shortLiquidation) and long_short==-1 and i_show_x1
// Last Liquidations
leverage= i_show_x1 ? i_x1 : 1
lastlliq = "💯 Leverage: " + str.tostring(leverage) + "x\n🩸 Long Liquidation: " + str.tostring(truncateprice(longLiquidation, pricedecimals)) + "\n📅 Last Long Liquidation: " + str.tostring(ta.barssince(longliqhit[1])) + " candles"
lastsliq = "💯 Leverage: " + str.tostring(leverage) + "x\n🩸 Short Liquidation: " + str.tostring(truncateprice(shortLiquidation, pricedecimals)) + "\n📅 Last Short Liquidation: " + str.tostring(ta.barssince(shortliqhit[1])) + " candles"
// Liquidation Event
// var label liqhit = na
// if longliqhit and long_short==1 and i_show_x1
//     label.new(bar_index,low,yloc=yloc.belowbar,text='🩸',textcolor=color.white, style=label.style_none, tooltip=lastlliq)
//     alertsyntax_longliq='🔔 Long Liquidated 🩸\n' + lastlliq
//     alert(message=alertsyntax_longliq, freq=alert_freq)
// if shortliqhit and long_short==-1 and i_show_x1
//     label.new(bar_index,high,yloc=yloc.abovebar,text='🩸',textcolor=color.white, style=label.style_none, tooltip=lastsliq)
//     alertsyntax_shortliq='🔔 Short Liquidated 🩸\n' + lastsliq
//     alert(message=alertsyntax_shortliq, freq=alert_freq)



import HoanGhetti/SimpleTrendlines/4 as tl

input_len       = 20
input_pivotType = input.string(defval = 'Normal', title = 'Trend Çizgi Türü', options = ['Normal', 'Fast'], tooltip = 'Normal: Uses Pine\'s built-in pivot system.\n\nFast: Uses a custom pivot system that tracks every reversal.')
input_repaint   = true
input_targets   = false
input_bearC     = input.color(defval = #af26266b, title = 'Bear Renk', group = 'Trend Çizimi')
input_bullC     = input.color(defval = #21972161, title = 'Bull Renk', group = 'Trend Çizimi')
input_extend    = extend.none
input_style     = line.style_dotted
input_tstyle    = line.style_dotted
input_override  = false
input_useSrc    = true
input_source    = low

pl = fixnan(ta.pivotlow(input_override ? input_source : low, input_pivotType == 'Normal' ? input_len : 1, input_len))
ph = fixnan(ta.pivothigh(input_override ? input_source : high, input_pivotType == 'Normal' ? input_len : 1, input_len))

pivot(float pType) =>
    pivot = pType == pl ? pl : ph
    xAxis = ta.valuewhen(ta.change(pivot), bar_index, 0) - ta.valuewhen(ta.change(pivot), bar_index, 1)
    prevPivot = ta.valuewhen(ta.change(pivot), pivot, 1)
    pivotCond = ta.change(pivot) and (pType == pl ? pivot > prevPivot : pivot < prevPivot)
    pData = tl.new(x_axis = xAxis, offset = input_len, strictMode = true, strictType = pType == pl ? 0 : 1)
    pData.drawLine(pivotCond, prevPivot, pivot, input_override ? input_source : na)
    pData

breakout(tl.Trendline this, float pType) =>
    var bool hasCrossed = false
    if ta.change(this.lines.startline.get_y1())
        hasCrossed := false
    this.drawTrendline(not hasCrossed)
    confirmation = not hasCrossed and (input_repaint ? not hasCrossed : barstate.isconfirmed)
    if (pType == pl ? (input_override and input_useSrc ? input_source : close) < this.lines.trendline.get_y2() : (input_override and input_useSrc ? input_source : close) > this.lines.trendline.get_y2()) and confirmation
        hasCrossed := true
        this.lines.startline.set_xy2(this.lines.trendline.get_x2(), this.lines.trendline.get_y2())
        this.lines.trendline.set_xy2(na, na)
        this.lines.startline.copy()
    hasCrossed

plData = pivot(pl)
phData = pivot(ph)

style(tl.Trendline this, color col) =>
    this.lines.startline.set_color(col), this.lines.trendline.set_color(col)
    this.lines.startline.set_width(2), this.lines.trendline.set_width(2)
    this.lines.trendline.set_style(input_style), this.lines.trendline.set_extend(input_extend)
style(plData, input_bearC), style(phData, input_bullC)

cu = breakout(plData, pl)
co = breakout(phData, ph)
// plotshape(ta.change(cu) and cu ? plData.lines.startline.get_y2() : na, title = 'Bearish Breakout', style = shape.labeldown, color = input_bearC, textcolor = color.white, location = location.absolute, text = 'KIRILIM')
// plotshape(ta.change(co) and co ? phData.lines.startline.get_y2() : na, title = 'Bullish Breakout', style = shape.labelup, color = input_bullC, textcolor = #000000, location = location.absolute, text = 'KIRILIM')
alertcondition(ta.change(cu) and cu, 'Bearish Trend Çizgi Alarm')
alertcondition(ta.change(co) and co, 'Bullish Trend Çizgi Alarm')

// Target Levels [v4 Update]
phData_target = tl.new(phData.values.changeInX)
plData_target = tl.new(plData.values.changeInX)
phData_target.drawLine(ta.change(phData.values.y1) and input_targets, phData.values.y2, phData.values.y2)
plData_target.drawLine(ta.change(plData.values.y1) and input_targets, plData.values.y2, plData.values.y2)

target_style(tl.Trendline this, color col) =>
    this.lines.startline.set_style(input_tstyle)
    this.lines.trendline.set_style(input_tstyle)
    this.lines.startline.set_color(col)
    this.lines.trendline.set_color(col)
target_style(plData_target, input_bearC)
target_style(phData_target, input_bullC)
breakout(phData_target, ph)
breakout(plData_target, pl)

// --------------------------------- Trade Labels --------------------------- //
//-------------------- Backtesting 
// @ Capissimo
bidask = close 

tbase = (time - time[1]) / 1000
tcurr = (timenow - time_close[1]) / 1000
barlife = tcurr / tbase

var float start_long_trade = bidask
var float long_trades = 0.
var float start_short_trade = bidask
var float short_trades = 0.
var int wins = 0
var int trade_count = 0

longtphit = ta.crossover(high, ATRbulltp1) and longBar2
longstophit = ta.crossunder(low, vwbullse3) and dcaorstop =="Stop" and longBar2
shorttphit = ta.crossunder(low, ATRbeartp1) and shortBar2
shortstophit = ta.crossover(high, vwbearse3) and dcaorstop =="Stop" and shortBar2

if bullcross //enter bull
    start_long_trade := bidask
    start_long_trade
if bearcross or (i_show_x1?longliqhit:na) or longtphit or (dcaorstop=="Stop"?longstophit:na)//exit bull
    ldiff = bidask - start_long_trade // long profit in dollars
    wins := ldiff > 0 ? 1 : 0
    long_trades := ldiff * lot_size
    trade_count := 1
    trade_count
if bearcross //enter bear
    start_short_trade := bidask
    start_short_trade
if bullcross or (i_show_x1?shortliqhit:na) or shorttphit or (dcaorstop=="Stop"?shortstophit:na)//exitbear
    sdiff = start_short_trade - bidask // short profit in dollars
    wins := sdiff > 0 ? 1 : 0
    short_trades := sdiff * lot_size
    trade_count := 1
    trade_count

bullcprofit=((bidask-start_long_trade)/start_long_trade)
bearcprofit=((start_short_trade-bidask)/start_short_trade)

cumbull = ta.cum(long_trades)
cumbear = ta.cum(short_trades)
cumpbull = ta.cum(bullcprofit)
cumpbear = ta.cum(bearcprofit)
cumreturn = ta.cum(long_trades) + ta.cum(short_trades) // sum of both short profit and long profit in $
cumpreturn = ta.cum(bullcprofit) + ta.cum(bearcprofit) // sum of both short profit and long profit in %
totaltrades = ta.cum(trade_count) //# trades
totalwins = ta.cum(wins)
totallosses = totaltrades - totalwins == 0 ? 1 : totaltrades - totalwins
avgreturn = cumreturn / totaltrades
avgpreturn = cumpreturn / totaltrades
avgbulltp = bullentry*(1+ta.valuewhen(bullcross,avgpreturn,0)) 
avgbeartp = bearentry*(1-ta.valuewhen(bearcross,avgpreturn,0))
avgtp = long_short==1?avgbulltp:long_short==-1?avgbeartp:na
avgtpcol = long_short == 1 and avgtp>bullentry?green:long_short == 1 and avgtp<bullentry?red: long_short==-1 and avgtp<bearentry?red: long_short==-1 and avgtp>bearentry?red:na
// plot(avgtp, "Avg TP", color=color.new(avgtpcol,50), style=plot.style_circles)
info =  "\n\n  📈 Cumulative Backtesting 📈" 
  + '\nBull Profit: $ ' + str.tostring(cumbull, '#.##') +'\nBear Profit: $ ' + str.tostring(cumbear, '#.##') + '\nTotal Profit: $ ' + str.tostring(cumreturn, '#.##')  + '\nAverage Total Profit: $ ' + str.tostring(avgreturn, '#.##')
  +  '\nBull Return: ' + str.tostring(cumpbull, '#.## %') +'\nBear Return: ' + str.tostring(cumpbear, '#.## %')  + '\nTotal Return: ' + str.tostring(cumpreturn, '#.## %') + '\nAverage Total Return: ' + str.tostring(avgpreturn, '#.## %') 
  + '\nTotal Wins: ' + str.tostring(totalwins, '#') + '\nTotal Losses: ' + str.tostring(totallosses, '#') + '\n🚦 Total Trades: ' + str.tostring(totaltrades, '#') + '\nWins/Trades: ' + str.tostring(totalwins / totaltrades, '#.## %')

// Crossover profit
bullxprofit = (((close - bullentry)/bullentry)*100)
bearxprofit = (((close - bearentry)/bearentry)*-100)
curbullprof = close-bullentry
curbearprof = bearentry-close
tradelabsize = input.string(size.normal, "Size", [size.tiny, size.small, size.normal, size.large, size.huge, size.auto], group=grt)
tradetime = ta.barssince(bullcross or bearcross)

// Plot Labels
bullentrytt = " Entry: " + (long_short==1?"🟢 AL @ ":long_short==-1?" 🔴 SAT @ ":na) + str.tostring(truncateprice(bullentry, pricedecimals)) 
  + "\n🛑 DCA/Stop 3: " + str.tostring(truncateprice(dca3in, pricedecimals)) + "\n🩸 Liquidation: " + liqtip2 
  + "\n🎯 Average Return Target: " + str.tostring(truncateprice(avgtp, pricedecimals)) + "\n🎯 Take Profit 8: " + str.tostring(truncateprice(exin, pricedecimals)) 
  + "\n💸 Lot Size: " + str.tostring(lot_size) 
bearentrytt = " Entry: " + (long_short==1?"🟢 AL @ ":long_short==-1?" 🔴 SAT @ ":na) + str.tostring(truncateprice(bearentry, pricedecimals)) 
  + "\n🛑 DCA/Stop 3: " + str.tostring(truncateprice(dca3in, pricedecimals)) + "\n🩸 Liquidation: " + liqtip2 
  + "\n🎯 Average Return Target: " + str.tostring(truncateprice(avgtp, pricedecimals)) + "\n🎯 Take Profit 8: " + str.tostring(truncateprice(exin, pricedecimals)) 
  + "\n💸 Lot Size: " + str.tostring(lot_size) 

var label signal = na
if bullcross
    label.new(bar_index,low,yloc=yloc.belowbar,text='\AL',textcolor=color.white, style=label.style_none, tooltip=bullentrytt)
    alertsyntax_golong= "🔔 AL 🟢\n" + bullentrytt 
    alert(message=alertsyntax_golong, freq=alert_freq)
if bearcross
    label.new(bar_index,high,yloc=yloc.abovebar,text='\SAT',textcolor=color.white, style=label.style_none, tooltip=bearentrytt)
    alertsyntax_goshort= "🔔 SAT 🔴\n" + bearentrytt 
    alert(message=alertsyntax_goshort, freq=alert_freq)
// var label entry = na
// if state==1 and long_short==1 and barstate.islast
//     entry := label.new(bar_index, y=bullentry, text=str.tostring(truncateprice(bullxprofit*leverage, pricedecimals)) + " %", size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor=bullxprofit>0?brightgreen:bullxprofit<0?brightred:color.white, 
//       tooltip=bullentrytt + "\n⌚ Trade Time: " + str.tostring(tradetime) + " candles" + "\nCurrent Bull Profit: $ " + str.tostring(curbullprof, '#.##') + "\nCurrent Bull Return: " + str.tostring(bullcprofit*leverage, '#.## %') + info)
//     label.delete(entry[1])
// if state==1 and long_short==1 and barstate.islast and bar_update_alerts
//     alertsyntax_longupdate= "🔔 Long Update 🟢: " + str.tostring(truncateprice(close,pricedecimals)) + "\n⌚ Trade Time: " + str.tostring(tradetime) + " candles" + "\n💵Current Bull Profit: $ " + str.tostring(curbullprof, '#.##') + "\n📈Current Bull Return: " + str.tostring(bullcprofit*leverage, '#.## %') + "\n" + bullentrytt  //+ info
//     alert(message=alertsyntax_longupdate, freq=alert_freq)
// if state==2 and long_short==-1 and barstate.islast
//     entry := label.new(bar_index, y=bearentry, text=str.tostring(truncateprice(bearxprofit*leverage, pricedecimals)) + " %", size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor=bearxprofit>0?brightgreen:bearxprofit<0?brightred:color.white, 
//       tooltip=bearentrytt + "\n⌚ Trade Time: " + str.tostring(tradetime) + " candles" + "\nCurrent Bear Profit: $ " + str.tostring(curbearprof, '#.##') + "\nCurrent Bear Return: " + str.tostring(bearcprofit*leverage, '#.## %') + info)
//     label.delete(entry[1])
// if state==2 and long_short==-1 and barstate.islast and bar_update_alerts
//     alertsyntax_shortupdate= "🔔 Short Update 🔴: " + str.tostring(truncateprice(close,pricedecimals)) + "\n⌚ Trade Time: " + str.tostring(tradetime) + " candles" + "\n💵Current Bear Profit: $ " + str.tostring(curbearprof, '#.##') + "\n📈Current Bear Return: " + str.tostring(bearcprofit*leverage, '#.## %') + "\n" + bearentrytt //+ info
//     alert(message=alertsyntax_shortupdate, freq=alert_freq)
// var label tp1 = na
// if state==1 and long_short==1 and barstate.islast
//     tp1 := label.new(bar_index, y=ATRbulltp1 , text=str.tostring(truncateprice(ATRbulltp1 , pricedecimals)), size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor=green, tooltip="🎯: " + str.tostring(truncateprice(ATRbulltp1, pricedecimals)) + "\nProfit: " + str.tostring(truncateprice(bullt1profit*leverage, pricedecimals)) + " %\n" + str.tostring(truncateprice(atrMultiplier, pricedecimals)) + "x "+ "ATR "  + str.tostring(atrPeriod))
//     label.delete(tp1[1])
// if state==2 and long_short==-1 and barstate.islast
//     tp1 := label.new(bar_index, y=ATRbeartp1 , text=str.tostring(truncateprice(ATRbeartp1 , pricedecimals)), size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor=red, tooltip="🎯: " + str.tostring(truncateprice(ATRbeartp1, pricedecimals)) + "\nProfit: " + str.tostring(truncateprice(beart1profit*leverage, pricedecimals)) + " %\n" + str.tostring(truncateprice(atrMultiplier, pricedecimals)) + "x "  + "ATR " + str.tostring(atrPeriod))
//     label.delete(tp1[1])
// var label tp2 = na
// if state==1 and long_short==1 and barstate.islast
//     tp2 := label.new(bar_index, y=ATRbulltp2, text=str.tostring(truncateprice(ATRbulltp2, pricedecimals)), size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(close<ATRbulltp2?green:gray,10), tooltip="🎯: " + str.tostring(truncateprice(ATRbulltp2, pricedecimals)) + "\nProfit: " + str.tostring(truncateprice(bullt2profit*leverage, pricedecimals)) + " %\n" + str.tostring(truncateprice(atrMultiplier*0.854, pricedecimals)) + "x " + "ATR " + str.tostring(atrPeriod))
//     label.delete(tp2[1])
// if state==2 and long_short==-1 and barstate.islast
//     tp2 := label.new(bar_index, y=ATRbeartp2, text=str.tostring(truncateprice(ATRbeartp2, pricedecimals)), size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(close>ATRbeartp2?red:gray,10), tooltip="🎯: " + str.tostring(truncateprice(ATRbeartp2, pricedecimals)) + "\nProfit: " + str.tostring(truncateprice(beart2profit*leverage, pricedecimals)) + " %\n" + str.tostring(truncateprice(atrMultiplier*0.854, pricedecimals)) + "x " + "ATR "+ str.tostring(atrPeriod))
//     label.delete(tp2[1])
// var label tp3 = na
// if state==1 and long_short==1 and barstate.islast
//     tp3 := label.new(bar_index, y=ATRbulltp3, text=str.tostring(truncateprice(ATRbulltp3, pricedecimals)), size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(close<ATRbulltp3?green:gray,20), tooltip="🎯: " + str.tostring(truncateprice(ATRbulltp3, pricedecimals)) + "\nProfit: " + str.tostring(truncateprice(bullt3profit*leverage, pricedecimals)) + " %\n" + str.tostring(truncateprice(atrMultiplier*0.763, pricedecimals)) + "x " + "ATR " + str.tostring(atrPeriod))
//     label.delete(tp3[1])
// if state==2 and long_short==-1 and barstate.islast
//     tp3 := label.new(bar_index, y=ATRbeartp3, text=str.tostring(truncateprice(ATRbeartp3, pricedecimals)), size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(close>ATRbeartp3?red:gray,20), tooltip="🎯: " + str.tostring(truncateprice(ATRbeartp3, pricedecimals)) + "\nProfit: " + str.tostring(truncateprice(beart3profit*leverage, pricedecimals)) + " %\n" + str.tostring(truncateprice(atrMultiplier*0.763, pricedecimals)) + "x " + "ATR " + str.tostring(atrPeriod))
//     label.delete(tp3[1])
// var label tp4 = na
// if state==1 and long_short==1 and barstate.islast
//     tp4 := label.new(bar_index, y=ATRbulltp4, text=str.tostring(truncateprice(ATRbulltp4, pricedecimals)), size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(close<ATRbulltp4?green:gray,30), tooltip="🎯: " + str.tostring(truncateprice(ATRbulltp4, pricedecimals)) + "\nProfit: " + str.tostring(truncateprice(bullt4profit*leverage, pricedecimals)) + " %\n" + str.tostring(truncateprice(atrMultiplier*0.618, pricedecimals)) + "x " + "ATR "  + str.tostring(atrPeriod))
//     label.delete(tp4[1])
// if state==2 and long_short==-1 and barstate.islast
//     tp4 := label.new(bar_index, y=ATRbeartp4, text=str.tostring(truncateprice(ATRbeartp4, pricedecimals)), size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(close>ATRbeartp4?red:gray, 30), tooltip="🎯: " + str.tostring(truncateprice(ATRbeartp4, pricedecimals)) + "\nProfit: " + str.tostring(truncateprice(beart4profit*leverage, pricedecimals)) + " %\n" + str.tostring(truncateprice(atrMultiplier*0.618, pricedecimals)) + "x " + "ATR "  + str.tostring(atrPeriod))
//     label.delete(tp4[1])
// var label tp5 = na
// if state==1 and long_short==1 and barstate.islast
//     tp5 := label.new(bar_index, y=ATRbulltp5, text=str.tostring(truncateprice(ATRbulltp5, pricedecimals)), size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(close<ATRbulltp5?green:gray, 40), tooltip="🎯: " + str.tostring(truncateprice(ATRbulltp5, pricedecimals)) + "\nProfit: " + str.tostring(truncateprice(bullt5profit*leverage, pricedecimals)) + " %\n" + str.tostring(truncateprice(atrMultiplier*0.5, pricedecimals)) + "x " + "ATR " + str.tostring(atrPeriod))
//     label.delete(tp5[1])
// if state==2 and long_short==-1 and barstate.islast
//     tp5 := label.new(bar_index, y=ATRbeartp5, text=str.tostring(truncateprice(ATRbeartp5, pricedecimals)), size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(close>ATRbeartp5?red:gray, 40), tooltip="🎯: " + str.tostring(truncateprice(ATRbeartp5, pricedecimals)) + "\nProfit: " + str.tostring(truncateprice(beart5profit*leverage, pricedecimals)) + " %\n" + str.tostring(truncateprice(atrMultiplier*0.5, pricedecimals)) + "x " + "ATR "+ str.tostring(atrPeriod))
//     label.delete(tp5[1])
// var label tp6 = na
// if state==1 and long_short==1 and barstate.islast
//     tp6 := label.new(bar_index, y=ATRbulltp6, text=str.tostring(truncateprice(ATRbulltp6, pricedecimals)), size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(close<ATRbulltp6?green:gray, 50), tooltip="🎯: " + str.tostring(truncateprice(ATRbulltp6, pricedecimals)) + "\nProfit: " + str.tostring(truncateprice(bullt6profit*leverage, pricedecimals)) + " %\n" + str.tostring(truncateprice(atrMultiplier*0.382, pricedecimals)) + "x " + "ATR " + str.tostring(atrPeriod))
//     label.delete(tp6[1])
// if state==2 and long_short==-1 and barstate.islast
//     tp6 := label.new(bar_index, y=ATRbeartp6, text=str.tostring(truncateprice(ATRbeartp6, pricedecimals)), size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(close>ATRbeartp6?red:gray,50), tooltip="🎯: " + str.tostring(truncateprice(ATRbeartp6, pricedecimals)) + "\nProfit: " + str.tostring(truncateprice(beart6profit*leverage, pricedecimals)) + " %\n" + str.tostring(truncateprice(atrMultiplier*0.382, pricedecimals)) + "x " + "ATR " + str.tostring(atrPeriod))
//     label.delete(tp6[1])
// var label tp7 = na
// if state==1 and long_short==1 and barstate.islast
//     tp7 := label.new(bar_index, y=ATRbulltp7, text=str.tostring(truncateprice(ATRbulltp7, pricedecimals)), size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(close<ATRbulltp7?green:gray,60), tooltip="🎯: " + str.tostring(truncateprice(ATRbulltp7, pricedecimals)) + "\nProfit: " + str.tostring(truncateprice(bullt7profit*leverage, pricedecimals)) + " %\n" + str.tostring(truncateprice(atrMultiplier*0.236, pricedecimals)) + "x " + "ATR "+ str.tostring(atrPeriod))
//     label.delete(tp7[1])
// if state==2 and long_short==-1 and barstate.islast
//     tp7 := label.new(bar_index, y=ATRbeartp7, text=str.tostring(truncateprice(ATRbeartp7, pricedecimals)), size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(close>ATRbeartp7?red:gray,60), tooltip="🎯: " + str.tostring(truncateprice(ATRbeartp7, pricedecimals)) + "\nProfit: " + str.tostring(truncateprice(beart7profit*leverage, pricedecimals)) + " %\n" + str.tostring(truncateprice(atrMultiplier*0.236, pricedecimals)) + "x " + "ATR " + str.tostring(atrPeriod))
//     label.delete(tp7[1])
var label tp8 = na
if state==1 and long_short==1 and barstate.islast
    tp8 := label.new(bar_index, y=ATRbulltp8, text=str.tostring(truncateprice(ATRbulltp8, pricedecimals)), size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(close<ATRbulltp8?green:gray,70), tooltip="🎯: " + str.tostring(truncateprice(ATRbulltp8, pricedecimals)) + "\nProfit: " + str.tostring(truncateprice(bullt8profit*leverage, pricedecimals)) + " %\n" + str.tostring(truncateprice(atrMultiplier*0.146, pricedecimals)) + "x " + "ATR "+ str.tostring(atrPeriod))
    label.delete(tp8[1])
if state==2 and long_short==-1 and barstate.islast
    tp8 := label.new(bar_index, y=ATRbeartp8, text=str.tostring(truncateprice(ATRbeartp8, pricedecimals)), size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(close>ATRbeartp8?red:gray,70), tooltip="🎯: " + str.tostring(truncateprice(ATRbeartp8, pricedecimals)) + "\nProfit: " + str.tostring(truncateprice(beart8profit*leverage, pricedecimals)) + " %\n" + str.tostring(truncateprice(atrMultiplier*0.146, pricedecimals)) + "x " + "ATR "+ str.tostring(atrPeriod))
    label.delete(tp8[1])
// var label dca1 = na
// if state==1 and long_short==1 and barstate.islast
//     dca1 := label.new(bar_index, y=vwbullse, text=str.tostring(truncateprice(vwbullse, pricedecimals)), size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(color.gray, 40), tooltip="📍: " + str.tostring(truncateprice(vwbullse, pricedecimals)) + "\n-" + str.tostring(truncateprice(atrMultiplier*0.146, pricedecimals)) + "x " + "ATR " + str.tostring(atrPeriod)) //, tooltip=str.tostring(truncateprice(bullt8profit, pricedecimals)) + " %")
//     label.delete(dca1[1])
// if state==2 and long_short==-1 and barstate.islast
//     dca1 := label.new(bar_index, y=vwbearse, text=str.tostring(truncateprice(vwbearse, pricedecimals)), size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(color.gray, 40), tooltip="📍: " + str.tostring(truncateprice(vwbearse, pricedecimals)) + "\n-" + str.tostring(truncateprice(atrMultiplier*0.146, pricedecimals)) + "x " + "ATR " + str.tostring(atrPeriod)) //, tooltip=str.tostring(truncateprice(beart8profit, pricedecimals)) + " %")
//     label.delete(dca1[1])
// var label dca2 = na
// if state==1 and long_short==1 and barstate.islast
//     dca2 := label.new(bar_index, y=vwbullse2, text=str.tostring(truncateprice(vwbullse2, pricedecimals)), size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(color.gray, 20), tooltip="📍: " + str.tostring(truncateprice(vwbullse2, pricedecimals)) + "\n-" + str.tostring(truncateprice(atrMultiplier*0.236, pricedecimals)) + "x " + "ATR " + str.tostring(atrPeriod)) //, tooltip=str.tostring(truncateprice(bullt8profit, pricedecimals)) + " %")
//     label.delete(dca2[1])
// if state==2 and long_short==-1 and barstate.islast
//     dca2 := label.new(bar_index, y=vwbearse2, text=str.tostring(truncateprice(vwbearse2, pricedecimals)), size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(color.gray, 20), tooltip="📍: " + str.tostring(truncateprice(vwbearse2, pricedecimals)) + "\n-" + str.tostring(truncateprice(atrMultiplier*0.236, pricedecimals)) + "x " + "ATR " + str.tostring(atrPeriod)) //, tooltip=str.tostring(truncateprice(beart8profit, pricedecimals)) + " %")
//     label.delete(dca2[1])
var label dca3 = na
if state==1 and long_short==1 and barstate.islast
    dca3 := label.new(bar_index, y=vwbullse3, text=str.tostring(truncateprice(vwbullse3, pricedecimals)), size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(color.gray, 0), tooltip="📍: " + str.tostring(truncateprice(vwbullse3, pricedecimals)) + "\n-" + str.tostring(truncateprice(atrMultiplier*0.382, pricedecimals)) + "x " + "ATR " + str.tostring(atrPeriod)) //, tooltip=str.tostring(truncateprice(bullt8profit, pricedecimals)) + " %")
    label.delete(dca3[1])
if state==2 and long_short==-1 and barstate.islast
    dca3 := label.new(bar_index, y=vwbearse3, text=str.tostring(truncateprice(vwbearse3, pricedecimals)), size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(color.gray, 0), tooltip="📍: " + str.tostring(truncateprice(vwbearse3, pricedecimals)) + "\n-" + str.tostring(truncateprice(atrMultiplier*0.382, pricedecimals)) + "x " + "ATR " + str.tostring(atrPeriod)) //, tooltip=str.tostring(truncateprice(beart8profit, pricedecimals)) + " %")
    label.delete(dca3[1])
var label cp = na
if state==1 and long_short==0 and barstate.islast
    cp := label.new(bar_index, y=high, text=str.tostring(truncateprice(bullxprofit*leverage, pricedecimals)) + " %", size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(green,0), tooltip="🚦 Entry: " + str.tostring(truncateprice(bullentry, pricedecimals)) + "\n💵 Current Profit: $ " + str.tostring(curbullprof, '#.##') + "\n📈 Current Return: " + str.tostring(bullcprofit*leverage, '#.## %') + (i_show_x1?("\n💯 Leverage: " + str.tostring(leverage) + "x"):na) + info) // + (automan=="Auto"?optMAtip:na) + info) //, tooltip=str.tostring(truncateprice(bullt8profit, pricedecimals)) + " %")
    label.delete(cp[1])
if state==2 and long_short==0 and barstate.islast
    cp := label.new(bar_index, y=low, text=str.tostring(truncateprice(bearxprofit*leverage, pricedecimals)) + " %", size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor=color.new(red,0), tooltip="🚦 Entry: " + str.tostring(truncateprice(bearentry, pricedecimals)) + "\n💵 Current Profit: $ " + str.tostring(curbearprof, '#.##') + "\n📈 Current Return: " + str.tostring(bearcprofit*leverage, '#.## %')+ (i_show_x1?("\n💯 Leverage: " + str.tostring(leverage) + "x"):na) + info) // + (automan=="Auto"?optMAtip:na) + info) //, tooltip=str.tostring(truncateprice(beart8profit, pricedecimals)) + " %")
    label.delete(cp[1])
var label liq = na
if state==1 and long_short==1 and i_show_x1 and barstate.islast
    liq := label.new(bar_index, y=longLiquidation, text=str.tostring(truncateprice(longLiquidation, pricedecimals)), size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor= longLiquidation < vwbullse3 ? color.yellow : brightred, tooltip=lastlliq)
    label.delete(liq[1])
if state==2 and long_short==-1 and i_show_x1 and barstate.islast
    liq := label.new(bar_index, y=shortLiquidation, text=str.tostring(truncateprice(shortLiquidation, pricedecimals)), size=tradelabsize, style=label.style_label_left, color=color.new(color.white,100), textcolor= shortLiquidation > vwbearse3 ? color.yellow : brightred, tooltip=lastsliq)
    label.delete(liq[1])

//------------Reset long_short if SL/TP hit during bar------------------------//
tpreset = true 
longclose = longtphit or longstophit 
shortclose = shorttphit or shortstophit

bullstopp = ((vwbullse3 - bullentry)/bullentry)*100
bearstopp = ((bearentry - vwbearse3)/bearentry)*100
bulltpp = ((ATRbulltp1 - bullentry)/bullentry)*100
beartpp = ((bearentry - ATRbeartp1)/bearentry)*100

tradesetuptt = "🚦 Entry: " + (long_short==1?"🟢 AL @ ":long_short==-1?" 🔴 SAT @ ":na) + str.tostring(truncateprice(entin,pricedecimals)) + 
  "\n🛑 DCA/Stop 3: " + str.tostring(truncateprice(dca3in, pricedecimals)) +
  "\n🩸 Liquidation: " + liqtip2 +
  "\n💰 Take Profit 8: " + str.tostring(truncateprice(exin,pricedecimals)) + 
  "\n📈 Return: " + str.tostring(truncateprice((long_short==1?bullstopp:long_short==-1?bearstopp:na)*leverage,pricedecimals)) + " %" + 
  "\n💵 Loss * "+ str.tostring(lot_size) + " lots: $ " + str.tostring(truncateprice(long_short==1?(vwbullse3 - bullentry):long_short==-1?(bearentry - vwbearse3):na,pricedecimals)) +
  "\n⌚ Trade Time: " + str.tostring(tradetime)

tradesetuptt2 = "🚦 Entry: " + (long_short==1?"🟢 AL @ ":long_short==-1?" 🔴 SAT @ ":na) + str.tostring(truncateprice(entin,pricedecimals)) + 
  "\n🛑 DCA/Stop 3: " + str.tostring(truncateprice(dca3in, pricedecimals)) + 
  "\n🩸 Liquidation: " + liqtip2 + 
  "\n💰 Take Profit 8: " + str.tostring(truncateprice(exin,pricedecimals)) + 
  "\n📈 Return: " + str.tostring(truncateprice((long_short==1?bulltpp:long_short==-1?beartpp:na)*leverage,pricedecimals)) + " %" + 
  "\n💵 Profit * "+ str.tostring(lot_size) + " lots: $ " + str.tostring(truncateprice(long_short==1?((ATRbulltp1 - bullentry)):long_short==-1?((bearentry - ATRbeartp1)):na,pricedecimals)) +
  "\n⌚ Trade Time: " + str.tostring(tradetime)

// loss labels
var label tclose = na
if longstophit and long_short==1
    label.new(bar_index,low,yloc=yloc.belowbar,text='❌',textcolor=color.white, style=label.style_none, tooltip=tradesetuptt)
    alertsyntax_longstop='🔔 Long Stopped ❌\n' + tradesetuptt 
    alert(message=alertsyntax_longstop, freq=alert_freq)
if shortstophit and long_short==-1
    label.new(bar_index,high,yloc=yloc.abovebar,text='❌',textcolor=color.white, style=label.style_none, tooltip=tradesetuptt)
    alertsyntax_shortstop='🔔 Short Stopped ❌\n' + tradesetuptt 
    alert(message=alertsyntax_shortstop, freq=alert_freq)

//  profit labels
var label tphit = na
if longtphit and long_short==1 
    label.new(bar_index,high,yloc=yloc.abovebar,text='',textcolor=color.white, style=label.style_none,  
      tooltip=tradesetuptt2)
    alertsyntax_longtp='🔔 Kar AL \n' +  tradesetuptt2 
    alert(message=alertsyntax_longtp, freq=alert_freq)
if shorttphit and long_short==-1 
    label.new(bar_index,low,yloc=yloc.belowbar,text='',textcolor=color.white, style=label.style_none, 
      tooltip=tradesetuptt2)
    alertsyntax_shorttp='🔔 Kar AL \n' +  tradesetuptt2 
    alert(message=alertsyntax_shorttp, freq=alert_freq)

long_short := (long_short == 1 or long_short == 0) and (longclose or longliqhit) and tpreset ? 0 : (long_short == -1 or long_short == 0) and (shortclose or shortliqhit) and tpreset ? 0 : long_short

bgcol2 = state==1 and state[1]==2 ?color.green : state==2 and state[1]==1 ? color.red :na
// Candle Color Logic
var color candle_col = na
if bullcross
    candle_col := brightgreen
if bearcross
    candle_col := brightred

// Plot Candles
plotcandle(open, high, low, close, title = 'Title', color = candle_col, wickcolor = candle_col, bordercolor = candle_col)

// Plot Trend State
barcolor(state==1 and rsi>50?brightgreen: state==1 and rsi<50?darkgreen: state==2 and rsi<50 ?brightred: state==2 and rsi>50 ?darkred:color.new(color.from_gradient(rsi, ts2, ts1, brightred, brightgreen),0),title="Chart Bar Color", display = showbc ? display.all : display.none, editable=false)

// Alarm ayarları (Enable/Disable)
// enableEma8Alarm = input.bool(true, title = 'Haftalık EMA 8 Alarm', group="Trade Alarm Ayarları")
// enableEma5Alarm = input.bool(true, title = 'Haftalık EMA 10 Alarm', group="Trade Alarm Ayarları")
// enableEma14Alarm = input.bool(true, title = 'Hfatlık EMA 14 Alarm', group="Trade Alarm Ayarları")
// enablefibogirisAlarm = input.bool(true, title = 'Fibo Giriş Alarm', group="Fibo Alarm Ayarları")
// enablefibotuzak1Alarm = input.bool(true, title = 'Fibo Tuzak 1 Alarm', group="Fibo Alarm Ayarları")
// enablefibotuzak2Alarm = input.bool(true, title = 'Fibo Altın Oran Alarm', group="Fibo Alarm Ayarları")
// enablefibostopAlarm = input.bool(true, title = 'Fibo Stop Alarm', group="Fibo Alarm Ayarları")
enabledikyesilzigiAlarm = input.bool(true, title = 'Toplama Bölgesi Alarm', group="MAl Toplama Stama Alarm Ayarları")
enabledikkirmiicizgiAlarm = input.bool(true, title = 'Satım Bölgesi Alarm', group="MAl Toplama Stama Alarm Ayarları")
enableEma34Alarm = input.bool(true, title = 'EMA 34 Alarm', group="Temel Alarm Ayarları")
enableEma55Alarm = input.bool(true, title = 'EMA 55 Alarm', group="Temel Alarm Ayarları")
enablekomp34Alarm = input.bool(true, title = 'KOMP 34 Alarm', group="Kompozit Alarm Ayarları")
enablekomp55Alarm = input.bool(true, title = 'KOMP 55 Alarm', group="Kompozit Alarm Ayarları")
enablekomp89Alarm = input.bool(true, title = 'KOMP 89 Alarm', group="Kompozit Alarm Ayarları")
enablekomp233Alarm = input.bool(true, title = 'KOMP 233 Alarm', group="Kompozit Alarm Ayarları")
enablekomp377Alarm = input.bool(true, title = 'KOMP 377 Alarm', group="Kompozit Alarm Ayarları")

// Alarmları etkinleştirme ayarları
enableBuyAlarm = input.bool(true, title="TEKRAR AL Alarmını", group="Alarm Ayarları")
enableSellAlarm = input.bool(true, title="KAR AL Alarmını", group="Alarm Ayarları")
enableTrendAlarm = input.bool(true, title="Trend Alarmını", group="Alarm Ayarları")


// Mal SAtım Alarm Koşulları
emadikyesilcizgiCrossUp =  bankerexit // Mal Toplama Bölgei

if emadikyesilcizgiCrossUp
    if (enabledikkirmiicizgiAlarm)
        alert("Tepe Mal Satım Bölgesi!", alert.freq_once_per_bar)

// Mal Toplama Alarm Koşulları
emadikkirmizicizgiCrossUp = bankerentry // Mal Satım Bölgei

if emadikkirmizicizgiCrossUp
    if (enabledikyesilzigiAlarm)
        alert("Dip Mal Toplama Bölgesi!", alert.freq_once_per_bar)

// // Fibo Giriş Alarm Koşulları
// emafibostopCrossUp = ta.crossunder(close, fib1) // Fiyat 0.236'ün üzerine çıkıyor

// if enablefibostopAlarm
//     if (emafibostopCrossUp)
//         alert("FİYAT Stop Oldu!", alert.freq_once_per_bar)



// // Fibo Giriş Alarm Koşulları
// emafibogirisCrossUp = ta.crossover(close, fib3) // Fiyat 0.236'ün üzerine çıkıyor

// if enablefibogirisAlarm
//     if (emafibogirisCrossUp)
//         alert("FİYAT YUKARI KESTİ Fibo Giriş!", alert.freq_once_per_bar)

// // Fibo Tuzak 1 Alarm Koşulları
// emafibotuzak1CrossUp = ta.crossover(close, fib7) // Fiyat Fibo 0.880'ün üzerine çıkıyor

// if enablefibotuzak1Alarm
//     if (emafibotuzak1CrossUp)
//         alert("FİYAT YUKARI KESTİ Fibo Tuzak 1!", alert.freq_once_per_bar)

// // Fibo Tuzak 2 Alarm Koşulları
// emafibotuzak2CrossUp = ta.crossover(close, fib6) // Fiyat Altın Oran ın üzerine çıkıyor
// emafibotuzak2Crossdown = ta.crossunder(close, fib6) // Fiyat Altın Oran ın üzerine çıkıyor

// if enablefibotuzak2Alarm
//     if (emafibotuzak2CrossUp)
//         alert("FİYAT YUKARI KESTİ Fibo Altın Oran!", alert.freq_once_per_bar)
//     if emafibotuzak2Crossdown
//         alert('FİYAT AŞAĞI KESTİ Fibo Altın Oran!', alert.freq_once_per_bar)

// // EMA 8 Alarm Koşulları
// ema8CrossUp = ta.crossover(close, ema_8) // Fiyat EMA 8'ün üzerine çıkıyor
// ema8CrossDown = ta.crossunder(close, ema_8) // Fiyat EMA 8'ün altına iniyor

// if enableEma8Alarm
//     if (ema8CrossUp)
//         alert("FİYAT YUKARI KESTİ HAFTA EMA 8!", alert.freq_once_per_bar)
//     if ema8CrossDown
//         alert('FİYAT AŞAĞI KESTİ HAFTA EMA 8!', alert.freq_once_per_bar)



// // EMA 10 Alarm Koşulları
// ema5CrossUp = ta.crossover(close, ema_10) // Fiyat EMA 10'ün üzerine çıkıyor
// ema5CrossDown = ta.crossunder(close, ema_10) // Fiyat EMA 10'ün altına iniyor

// if enableEma5Alarm
//     if (ema5CrossUp)
//         alert("FİYAT YUKARI KESTİ HAFTA EMA 10!", alert.freq_once_per_bar)
//     if ema5CrossDown
//         alert('FİYAT AŞAĞI KESTİ HAFTA EMA 10!', alert.freq_once_per_bar)



// // EMA 14 Alarm Koşulları
// ema14CrossUp = ta.crossover(close, ema_14) // Fiyat EMA 14'ün üzerine çıkıyor
// ema14CrossDown = ta.crossunder(close, ema_14) // Fiyat EMA 14'ün altına iniyor

// if enableEma14Alarm
//     if (ema14CrossUp)
//         alert("FİYAT YUKARI KESTİ HAFTA EMA 14!", alert.freq_once_per_bar)
//     if ema14CrossDown
//         alert('FİYAT AŞAĞI KESTİ HAFTA EMA 14!', alert.freq_once_per_bar)


// EMA 34 Alarm Koşulları
ema34CrossUp = ta.crossover(close, ema34) // Fiyat EMA 34'ün üzerine çıkıyor
ema34CrossDown = ta.crossunder(close, ema34) // Fiyat EMA 34'ün altına iniyor

if enableEma34Alarm
    if (ema34CrossUp)
        alert("FİYAT YUKARI KESTİ EMA 34!", alert.freq_once_per_bar)
    if ema34CrossDown
        alert('FİYAT AŞAĞI KESTİ EMA 34!', alert.freq_once_per_bar)

// EMA 55 Alarm Koşulları
ema55CrossUp = ta.crossover(close, ema55) // Fiyat EMA 55'in üzerine çıkıyor
ema55CrossDown = ta.crossunder(close, ema55) // Fiyat EMA 55'in altına iniyor

if enableEma55Alarm
    if (ema55CrossUp)
        alert("FİYAT YUKARI KESTİ EMA 55!", alert.freq_once_per_bar)
    if ema55CrossDown
        alert('FİYAT AŞAĞI KESTİ EMA 55!', alert.freq_once_per_bar)


komp233CrossUp = ta.crossover(close, comp_ema233 * xu100) // Fiyat EMA 55'in üzerine çıkıyor
komp233CrossDown = ta.crossunder(close, comp_ema233 * xu100) // Fiyat EMA 55'in altına iniyor

if enablekomp233Alarm
    if (komp233CrossUp)
        alert("FİYAT YUKARI KESTİ KOMP 233!", alert.freq_once_per_bar)
    if komp233CrossDown
        alert('FİYAT AŞAĞI KESTİ KOMP 233!', alert.freq_once_per_bar)

komp89CrossUp = ta.crossover(close, comp_ema89 * xu100) // Fiyat EMA 55'in üzerine çıkıyor
komp89CrossDown = ta.crossunder(close, comp_ema89 * xu100) // Fiyat EMA 55'in altına iniyor

if enablekomp89Alarm
    if (komp89CrossUp)
        alert("FİYAT YUKARI KESTİ KOMP 89!", alert.freq_once_per_bar)
    if komp89CrossDown
        alert('FİYAT AŞAĞI KESTİ KOMP 89!', alert.freq_once_per_bar)

komp34CrossUp = ta.crossover(close, comp_ema34 * xu100) // Fiyat EMA 55'in üzerine çıkıyor
komp34CrossDown = ta.crossunder(close, comp_ema34 * xu100) // Fiyat EMA 55'in altına iniyor

if enablekomp34Alarm
    if (komp34CrossUp)
        alert("FİYAT YUKARI KESTİ KOMP 34!", alert.freq_once_per_bar)
    if komp34CrossDown
        alert('FİYAT AŞAĞI KESTİ KOMP 34!', alert.freq_once_per_bar)

komp55CrossUp = ta.crossover(close, comp_ema55) // Fiyat EMA 55'in üzerine çıkıyor
komp55CrossDown = ta.crossunder(close, comp_ema55) // Fiyat EMA 55'in altına iniyor

if enablekomp55Alarm
    if (komp55CrossUp)
        alert("FİYAT YUKARI KESTİ KOMP 55!", alert.freq_once_per_bar)
    if komp55CrossDown
        alert('FİYAT AŞAĞI KESTİ KOMP 55!', alert.freq_once_per_bar)

komp377CrossUp = ta.crossover(close, comp_ema377) // Fiyat EMA 55'in üzerine çıkıyor
komp377CrossDown = ta.crossunder(close, comp_ema377) // Fiyat EMA 55'in altına iniyor

if enablekomp377Alarm
    if (komp377CrossUp)
        alert("FİYAT YUKARI KESTİ KOMP 377!", alert.freq_once_per_bar)
    if komp377CrossDown
        alert('FİYAT AŞAĞI KESTİ KOMP 377!', alert.freq_once_per_bar)


al =ta.crossover(close , ub4)
sat= ta.crossunder(close, ub4)

miidlineflt = close > ub4

// // LONG pozisyonları için giriş ve çıkış koşulları
// if (bullcross)
//     strategy.entry("Long", strategy.long)

// if (bearcross)
//     strategy.close("Long")

// SHORT pozisyonlarını devre dışı bırakma
// if (bearcross)
//     strategy.entry("Short", strategy.short)

// if (shorttphit or shortstophit)
//     strategy.close("Short")

// EoS made w/ ❤ by @BarefootJoey ✌💗📈
Leave a Comment