Untitled

 avatar
unknown
plain_text
a year ago
63 kB
16
Indexable

//@version=5
indicator("telegram MultiIndicatorTrendAnalyzer[ChochBos Telegram]", "ChocH+&BoS[ChochBos Telegram]"
  , overlay = true
  ,precision=0
  ,explicit_plot_zorder=true
  , max_lines_count = 500
  , max_labels_count = 500
  , max_boxes_count = 500
  , max_bars_back = 500
  , max_polylines_count = 100)



//-----------------------------------------------------------------------------{
//Constants
//-----------------------------------------------------------------------------{
color TRANSP_CSS = #ffffff00

//Tooltips
string MODE_TOOLTIP          = 'Tarihsel Yapının veya yalnızca son yapıların görüntülenmesine izin verir'
string STYLE_TOOLTIP         = 'Gösterge renk teması [ DAHA SADE GÖRÜNÜM]'
string COLOR_CANDLES_TOOLTIP = 'TREND YAPISI MUMLAR BOYANIR'
string SHOW_INTERNAL         = 'İç pazar İNTERNAL yapısını göster'
string CONFLUENCE_FILTER     = 'Önemli olmayan iç yapı kesintilerini filtreleyin'
string SHOW_SWING            = 'İç pazar SWİNG yapısını göster'
string SHOW_SWING_POINTS     = 'Pivot noktarlarını etiket olarak göster ?'
string SHOW_SWHL_POINTS      = 'Grafikteki en güncel güçlü ve zayıf yüksek/düşük noktaları vurgulayın'
string INTERNAL_OB           = 'İç pazar İNTERNAL yapısı kaç tane  gösterilsin'
string SWING_OB              = 'İç pazar SWİNG yapısı kaçtane  gösterilsin'
string FILTER_OB             = 'Geçici sipariş bloklarını filtrelemek için kullanılan yöntem \n\nDüşük miktarda veri mevcut olduğunda kümülatif ortalama aralık yönteminin kullanılması önerilir'
string SHOW_EQHL             = 'Display equal highs and equal lows on the chart'
string EQHL_BARS             = 'Number of bars used to confirm equal highs and equal lows'
string EQHL_THRESHOLD        = 'Sensitivity threshold in a range (0, 1) used for the detection of equal highs & lows\n\nLower values will return fewer but more pertinent results'
string SHOW_FVG              = 'Display fair values gaps on the chart'
string AUTO_FVG              = 'Filter out non significant fair value gaps'
string FVG_TF                = 'Fair value gaps timeframe'
string EXTEND_FVG            = 'Determine how many bars to extend the Fair Value Gap boxes on chart'
string PED_ZONES             = 'Display premium, discount, and equilibrium zones on chart'

//-----------------------------------------------------------------------------{style
//Settings
//-----------------------------------------------------------------------------{
//General
//----------------------------------------{
GrafikSadelestir = input.string('TEMIZLE'
  , options = ['CHoCHBOSGOSTER', 'TEMIZLE']
  , group = 'CHoCH+BOS+GOSTER'
  , tooltip = MODE_TOOLTIP)

style = input.string('SadeBoyama', options = ['DolgunBoyama', 'SadeBoyama'], group = 'CHoCH+BOS+GOSTER', tooltip = STYLE_TOOLTIP)

show_trend = input(false, 'MUMLAR BOYANSIN MI ?', group = 'İç Yapıyı  Göster Internal BoS CHoCH ?', tooltip = COLOR_CANDLES_TOOLTIP)

//----------------------------------------}
//Internal Structure
//----------------------------------------{
show_internals = input(true, 'İç Yapıyı  Göster Internal BoS CHoCH ?', group = 'İç Yapıyı  Göster Internal BoS CHoCH ?', tooltip = SHOW_INTERNAL)

show_Structure = input(true, ' Swing CHoCH BoS Yapıyı Göster ?', group = 'İç Yapıyı  Göster Internal BoS CHoCH ?', tooltip = SHOW_SWING)

//Swings
show_swings = input(false, 'Pivot Noktalarını Göster', inline = 'swings', group = 'İç Yapıyı  Göster Internal BoS CHoCH ?', tooltip = SHOW_SWING_POINTS)
length = input.int(50, '', minval = 10, inline = 'swings', group = 'İç Yapıyı  Göster Internal BoS CHoCH ?')
showTrendLines = input(true, "Trend Lines Göster ?", group = 'İç Yapıyı  Göster Internal BoS CHoCH ?')



show_ibull = 'All'//input.string('All', 'Bullish Structure', options = ['All', 'BOS', 'CHoCH'], inline = 'ibull', group = 'İç Yapıyı  Göster Internal BoS CHoCH ?')

swing_ibull_css = #089981//input(#089981, '', inline = 'ibull', group = 'İç Yapıyı  Göster Internal BoS CHoCH ?')

//Bear Structure
show_ibear = 'All'//input.string('All', 'Bearish Structure', options = ['All', 'BOS', 'CHoCH'], inline = 'ibear', group = 'İç Yapıyı  Göster Internal BoS CHoCH ?')

swing_ibear_css = #f23645//input(#f23645, '', inline = 'ibear', group = 'İç Yapıyı  Göster Internal BoS CHoCH ?')

ifilter_confluence = false//input(true, 'Gerçek Zamanlı İç Yapı filtre ?', group = 'İç Yapıyı  Göster Internal BoS CHoCH ?', tooltip = CONFLUENCE_FILTER)

internal_structure_size = input.string('Tiny', 'Internal CHoCH BoS Yazı Boyutu'
  , options = ['Tiny', 'Small', 'Normal']
  , group = 'Internal Swing BoS CHoCH Yazı Boyutu ?')
swing_structure_size = input.string('Tiny', 'Swing CHoCH BoS Yazı Boyutu'
  , options = ['Tiny', 'Small', 'Normal']
  , group = 'Internal Swing BoS CHoCH Yazı Boyutu ?')

//----------------------------------------}
//Swing Structure
//----------------------------------------{


//Bull Structure
show_bull = 'All'//input.string('All', 'Bullish Structure', options = ['All', 'BOS', 'CHoCH'], inline = 'bull', group = ' Swing CHoCH BoS Yapıyı Göster ?')

swing_bull_css = #089981//input(#089981, '', inline = 'bull', group = ' Swing CHoCH BoS Yapıyı Göster ?')

//Bear Structure
show_bear = 'All'//input.string('All', 'Bearish Structure', options = ['All', 'BOS', 'CHoCH'], inline = 'bear', group = ' Swing CHoCH BoS Yapıyı Göster ?')

swing_bear_css = #f23645//input(#f23645, '', inline = 'bear', group = ' Swing CHoCH BoS Yapıyı Göster ?')


show_hl_swings = true//input(true, 'Show Strong/Weak High/Low', group = ' Swing CHoCH BoS Yapıyı Göster ?', tooltip = SHOW_SWHL_POINTS)

//----------------------------------------}
//Order Blocks
//----------------------------------------{
show_iob = input(true, 'Internal Order Blocks'
  , inline = 'iob'
  , group = 'Order Blocks Bölgelerini Göster ?'
  , tooltip = INTERNAL_OB)

iob_showlast = input.int(10, ''
  , minval = 1
  , inline = 'iob'
  , group = 'Order Blocks Bölgelerini Göster ?')

show_ob = input(true, 'Swing Order Blocks'
  , inline = 'ob'
  , group = 'Order Blocks Bölgelerini Göster ?'
  , tooltip = SWING_OB)

ob_showlast = input.int(10, ''
  , minval = 1
  , inline = 'ob'
  , group = 'Order Blocks Bölgelerini Göster ?')


//----------------------------------------}
//Premium/Discount zones
//----------------------------------------{
show_sd = input(true, 'Premium/Discount ', group = 'Order Blocks Bölgelerini Göster ?', tooltip = PED_ZONES)

premium_css = #f23645//input.color(#f23645, 'Premium Zone', group = 'Premium & Discount Zones')

eq_css = #b2b5be//input.color(#b2b5be, 'Equilibrium Zone', group = 'Premium & Discount Zones')

discount_css = #089981//input.color(#089981, 'Discount Zone', group = 'Premium & Discount Zones')
/////////////

ob_filter = input.string('Cumulative Mean Range', 'Order Block Filter'
  , options = ['Atr', 'Cumulative Mean Range']
  , group = 'Order Blocks Bölgelerini Göster ?'
  , tooltip = FILTER_OB)
////////
ibull_ob_css = color.new(#3179f5, 80)//input.color(color.new(#3179f5, 80), 'Internal Bullish OB', group = 'Order Blocks')

ibear_ob_css = color.new(#f77c80, 80)//input.color(color.new(#f77c80, 80), 'Internal Bearish OB', group = 'Order Blocks')

bull_ob_css = color.new(#1848cc, 80)//input.color(color.new(#1848cc, 80), 'Bullish OB', group = 'Order Blocks')

bear_ob_css = color.new(#b22833, 80)//input.color(color.new(#b22833, 80), 'Bearish OB', group = 'Order Blocks')

//----------------------------------------}
//EQH/EQL
//----------------------------------------{
show_eq = false//input(false, 'Equal High/Low', group = 'EQH/EQL', tooltip = SHOW_EQHL)

eq_len = 3//input.int(3, 'Bars Confirmation', minval = 1, group = 'EQH/EQL', tooltip = EQHL_BARS)

eq_threshold = 0.1//input.float(0.1, 'Threshold', minval = 0, maxval = 0.5, step = 0.1, tooltip = EQHL_THRESHOLD)

eq_size = 'Tiny'//input.string('Tiny', 'Label Size', options = ['Tiny', 'Small', 'Normal'], group = 'EQH/EQL')

//----------------------------------------}
//Fair Value Gaps
//----------------------------------------{
show_fvg = false//input(false, 'Fair Value Gaps', group = 'Fair Value Gaps', tooltip = SHOW_FVG)
  
fvg_auto = true//input(true, "Auto Threshold", group = 'Fair Value Gaps', tooltip = AUTO_FVG)

fvg_tf ="Timeframe"// input.timeframe('', "Timeframe", group = 'Fair Value Gaps', tooltip = FVG_TF)

bull_fvg_css = color.new(#00ff68, 70)//input.color(color.new(#00ff68, 70), 'Bullish FVG', group = 'Fair Value Gaps')

bear_fvg_css = color.new(#ff0008, 70)//input.color(color.new(#ff0008, 70), 'Bearish FVG', group = 'Fair Value Gaps')

fvg_extend = 1//input.int(1, "Extend FVG", minval = 0, group = 'Fair Value Gaps', tooltip = EXTEND_FVG)

//----------------------------------------}
//Previous day/week high/low
//----------------------------------------{
//Daily
show_pdhl = false//input(false, 'Daily', inline = 'daily', group = 'Highs & Lows MTF')

pdhl_style = '⎯⎯⎯'//input.string('⎯⎯⎯', '', options = ['⎯⎯⎯', '----', '····'], inline = 'daily', group = 'Highs & Lows MTF')

pdhl_css = #2157f3//input(#2157f3, '', inline = 'daily', group = 'Highs & Lows MTF')

//Weekly
show_pwhl = false//input(false, 'Weekly', inline = 'weekly', group = 'Highs & Lows MTF')

pwhl_style = '⎯⎯⎯'//input.string('⎯⎯⎯', '', options = ['⎯⎯⎯', '----', '····'], inline = 'weekly', group = 'Highs & Lows MTF')

pwhl_css = #2157f3//input(#2157f3, '', inline = 'weekly', group = 'Highs & Lows MTF')

//Monthly
show_pmhl = false//input(false, 'Monthly', inline = 'monthly', group = 'Highs & Lows MTF')

pmhl_style = '⎯⎯⎯'//input.string('⎯⎯⎯', '', options = ['⎯⎯⎯', '----', '····'], inline = 'monthly', group = 'Highs & Lows MTF')

pmhl_css = #2157f3//input(#2157f3, '', inline = 'monthly', group = 'Highs & Lows MTF')


//-----------------------------------------------------------------------------}
//Functions
//-----------------------------------------------------------------------------{
n = bar_index

atr = ta.atr(200)
cmean_range = ta.cum(high - low) / n

//HL Output function
hl() => [high, low]

//Get ohlc values function
get_ohlc()=> [close[1], open[1], high, low, high[2], low[2]]

//Display Structure function
display_Structure(x, y, txt, css, dashed, down, lbl_size)=>
    structure_line = line.new(x, y, n, y
      , color = css
      , style = dashed ? line.style_dashed : line.style_solid)

    structure_lbl = label.new(int(math.avg(x, n)), y, txt
      , color = TRANSP_CSS
      , textcolor = css
      , style = down ? label.style_label_down : label.style_label_up
      , size = lbl_size)

    if GrafikSadelestir == 'TEMIZLE'
        line.delete(structure_line[1])
        label.delete(structure_lbl[1])

//Swings detection/measurements
swings(len)=>
    var os = 0
    
    upper = ta.highest(len)
    lower = ta.lowest(len)

    os := high[len] > upper ? 0 : low[len] < lower ? 1 : os[1]

    top = os == 0 and os[1] != 0 ? high[len] : 0
    btm = os == 1 and os[1] != 1 ? low[len] : 0

    [top, btm]

//Order block coordinates function
ob_coord(use_max, loc, target_top, target_btm, target_left, target_type)=>
    min = 99999999.
    max = 0.
    idx = 1

    ob_threshold = ob_filter == 'Atr' ? atr : cmean_range 

    //Search for highest/lowest high within the structure interval and get range
    if use_max
        for i = 1 to (n - loc)-1
            if (high[i] - low[i]) < ob_threshold[i] * 2
                max := math.max(high[i], max)
                min := max == high[i] ? low[i] : min
                idx := max == high[i] ? i : idx
    else
        for i = 1 to (n - loc)-1
            if (high[i] - low[i]) < ob_threshold[i] * 2
                min := math.min(low[i], min)
                max := min == low[i] ? high[i] : max
                idx := min == low[i] ? i : idx

    array.unshift(target_top, max)
    array.unshift(target_btm, min)
    array.unshift(target_left, time[idx])
    array.unshift(target_type, use_max ? -1 : 1)

//Set order blocks
display_ob(boxes, target_top, target_btm, target_left, target_type, show_last, swing, size)=>
    for i = 0 to math.min(show_last-1, size-1)
        get_box = array.get(boxes, i)

        box.set_lefttop(get_box, array.get(target_left, i), array.get(target_top, i))
        box.set_rightbottom(get_box, array.get(target_left, i), array.get(target_btm, i))
        box.set_extend(get_box, extend.right)

        color css = na
        
        if swing 
            if style == 'SadeBoyama'
                css := array.get(target_type, i) == 1 ? color.new(#b2b5be, 80) : color.new(#5d606b, 80)
                border_css = array.get(target_type, i) == 1 ? #b2b5be : #5d606b
                box.set_border_color(get_box, border_css)
            else
                css := array.get(target_type, i) == 1 ? bull_ob_css : bear_ob_css
                box.set_border_color(get_box, css)

            box.set_bgcolor(get_box, css)
        else
            if style == 'SadeBoyama'
                css := array.get(target_type, i) == 1 ? color.new(#b2b5be, 80) : color.new(#5d606b, 80)
            else
                css := array.get(target_type, i) == 1 ? ibull_ob_css : ibear_ob_css
            
            box.set_border_color(get_box, css)
            box.set_bgcolor(get_box, css)
        
//Line style function
get_line_style(style) =>
    out = switch style
        '⎯⎯⎯'  => line.style_solid
        '----' => line.style_dashed
        '····' => line.style_dotted

//Set line/labels function for previous high/lows
phl(h, l, tf, css)=>
    var line high_line = line.new(na,na,na,na
      , xloc = xloc.bar_time
      , color = css
      , style = get_line_style(pdhl_style))

    var label high_lbl = label.new(na,na
      , xloc = xloc.bar_time
      , text = str.format('P{0}H', tf)
      , color = TRANSP_CSS
      , textcolor = css
      , size = size.small
      , style = label.style_label_left)

    var line low_line = line.new(na,na,na,na
      , xloc = xloc.bar_time
      , color = css
      , style = get_line_style(pdhl_style))

    var label low_lbl = label.new(na,na
      , xloc = xloc.bar_time
      , text = str.format('P{0}L', tf)
      , color = TRANSP_CSS
      , textcolor = css
      , size = size.small
      , style = label.style_label_left)

    hy = ta.valuewhen(h != h[1], h, 1)
    hx = ta.valuewhen(h == high, time, 1)

    ly = ta.valuewhen(l != l[1], l, 1)
    lx = ta.valuewhen(l == low, time, 1)

    if barstate.islast
        ext = time + (time - time[1])*20

        //High
        line.set_xy1(high_line, hx, hy)
        line.set_xy2(high_line, ext, hy)

        label.set_xy(high_lbl, ext, hy)

        //Low
        line.set_xy1(low_line, lx, ly)
        line.set_xy2(low_line, ext, ly)

        label.set_xy(low_lbl, ext, ly)

//-----------------------------------------------------------------------------}
//Global variables
//-----------------------------------------------------------------------------{
var trend = 0, var itrend = 0

var top_y = 0., var top_x = 0
var btm_y = 0., var btm_x = 0

var itop_y = 0., var itop_x = 0
var ibtm_y = 0., var ibtm_x = 0

var trail_up = high, var trail_dn = low
var trail_up_x = 0,  var trail_dn_x = 0

var top_cross = true,  var btm_cross = true
var itop_cross = true, var ibtm_cross = true

var txt_top = '',  var txt_btm = ''

//Alerts
bull_choch_alert = false 
bull_bos_alert   = false 

bear_choch_alert = false 
bear_bos_alert   = false 

bull_ichoch_alert = false 
bull_ibos_alert   = false 

bear_ichoch_alert = false 
bear_ibos_alert   = false 

bull_iob_break = false 
bear_iob_break = false

bull_ob_break = false 
bear_ob_break = false

eqh_alert = false 
eql_alert = false 

//Structure colors
var bull_css = style == 'SadeBoyama' ? #b2b5be 
  : swing_bull_css

var bear_css = style == 'SadeBoyama' ? #b2b5be 
  : swing_bear_css

var ibull_css = style == 'SadeBoyama' ? #b2b5be 
  : swing_ibull_css

var ibear_css = style == 'SadeBoyama' ? #b2b5be 
  : swing_ibear_css

//Labels size
var internal_structure_lbl_size = internal_structure_size == 'Tiny' 
  ? size.tiny 
  : internal_structure_size == 'Small' 
  ? size.small 
  : size.normal 

var swing_structure_lbl_size = swing_structure_size == 'Tiny' 
  ? size.tiny 
  : swing_structure_size == 'Small' 
  ? size.small 
  : size.normal 

var eqhl_lbl_size = eq_size == 'Tiny' 
  ? size.tiny 
  : eq_size == 'Small' 
  ? size.small
  : size.normal 

//Swings
[top, btm] = swings(length)

[itop, ibtm] = swings(5)

//-----------------------------------------------------------------------------}
//Pivot High
//-----------------------------------------------------------------------------{
var line extend_top = na

var label extend_top_lbl = label.new(na, na
  , color = TRANSP_CSS
  , textcolor = bear_css
  , style = label.style_label_down
  , size = size.tiny)

if top
    top_cross := true
    txt_top := top > top_y ? 'HH' : 'LH'

    if show_swings
        top_lbl = label.new(n-length, top, txt_top
          , color = TRANSP_CSS
          , textcolor = bear_css
          , style = label.style_label_down
          , size = swing_structure_lbl_size)

        if GrafikSadelestir == 'TEMIZLE'
            label.delete(top_lbl[1])

    //Extend recent top to last bar
    line.delete(extend_top[1])
    extend_top := line.new(n-length, top, n, top
      , color = bear_css)

    top_y := top
    top_x := n - length

    trail_up := top
    trail_up_x := n - length

if itop
    itop_cross := true

    itop_y := itop
    itop_x := n - 5

//Trailing maximum
trail_up := math.max(high, trail_up)
trail_up_x := trail_up == high ? n : trail_up_x

//Set top extension label/line
if barstate.islast and show_hl_swings
    line.set_xy1(extend_top, trail_up_x, trail_up)
    line.set_xy2(extend_top, n + 20, trail_up)

    label.set_x(extend_top_lbl, n + 20)
    label.set_y(extend_top_lbl, trail_up)
    label.set_text(extend_top_lbl, trend < 0 ? 'Strong High' : 'Weak High')

//-----------------------------------------------------------------------------}
//Pivot Low
//-----------------------------------------------------------------------------{
var line extend_btm = na 

var label extend_btm_lbl = label.new(na, na
  , color = TRANSP_CSS
  , textcolor = bull_css
  , style = label.style_label_up
  , size = size.tiny)

if btm
    btm_cross := true
    txt_btm := btm < btm_y ? 'LL' : 'HL'
    
    if show_swings
        btm_lbl = label.new(n - length, btm, txt_btm
          , color = TRANSP_CSS
          , textcolor = bull_css
          , style = label.style_label_up
          , size = swing_structure_lbl_size)

        if GrafikSadelestir == 'TEMIZLE'
            label.delete(btm_lbl[1])
    
    //Extend recent btm to last bar
    line.delete(extend_btm[1])
    extend_btm := line.new(n - length, btm, n, btm
      , color = bull_css)

    btm_y := btm
    btm_x := n-length

    trail_dn := btm
    trail_dn_x := n-length

if ibtm
    ibtm_cross := true

    ibtm_y := ibtm
    ibtm_x := n - 5

//Trailing minimum
trail_dn := math.min(low, trail_dn)
trail_dn_x := trail_dn == low ? n : trail_dn_x

//Set btm extension label/line
if barstate.islast and show_hl_swings
    line.set_xy1(extend_btm, trail_dn_x, trail_dn)
    line.set_xy2(extend_btm, n + 20, trail_dn)

    label.set_x(extend_btm_lbl, n + 20)
    label.set_y(extend_btm_lbl, trail_dn)
    label.set_text(extend_btm_lbl, trend > 0 ? 'Strong Low' : 'Weak Low')

//-----------------------------------------------------------------------------}
//Order Blocks Arrays
//-----------------------------------------------------------------------------{
var iob_top = array.new_float(0)
var iob_btm = array.new_float(0)
var iob_left = array.new_int(0)
var iob_type = array.new_int(0)

var ob_top = array.new_float(0)
var ob_btm = array.new_float(0)
var ob_left = array.new_int(0)
var ob_type = array.new_int(0)

//-----------------------------------------------------------------------------}
//Pivot High BOS/CHoCH
//-----------------------------------------------------------------------------{
//Filtering
var bull_concordant = true

if ifilter_confluence
    bull_concordant := high - math.max(close, open) > math.min(close, open - low)

//Detect internal bullish Structure
if ta.crossover(close, itop_y) and itop_cross and top_y != itop_y and bull_concordant
    bool choch = na
    
    if itrend < 0
        choch := true
        bull_ichoch_alert := true
    else 
        bull_ibos_alert := true
    
    txt = choch ? 'CHoCH' : 'BOS'

    if show_internals
        if show_ibull == 'All' or (show_ibull == 'BOS' and not choch) or (show_ibull == 'CHoCH' and choch)
            display_Structure(itop_x, itop_y, txt, ibull_css, true, true, internal_structure_lbl_size)
    
    itop_cross := false
    itrend := 1
    
    //Internal Order Block
    if show_iob
        ob_coord(false, itop_x, iob_top, iob_btm, iob_left, iob_type)

//Detect bullish Structure
if ta.crossover(close, top_y) and top_cross
    bool choch = na
    
    if trend < 0
        choch := true
        bull_choch_alert := true
    else 
        bull_bos_alert := true

    txt = choch ? 'CHoCH' : 'BOS'
    
    if show_Structure
        if show_bull == 'All' or (show_bull == 'BOS' and not choch) or (show_bull == 'CHoCH' and choch)
            display_Structure(top_x, top_y, txt, bull_css, false, true, swing_structure_lbl_size)
    
    //Order Block
    if show_ob
        ob_coord(false, top_x, ob_top, ob_btm, ob_left, ob_type)

    top_cross := false
    trend := 1

//-----------------------------------------------------------------------------}
//Pivot Low BOS/CHoCH
//-----------------------------------------------------------------------------{
var bear_concordant = true

if ifilter_confluence
    bear_concordant := high - math.max(close, open) < math.min(close, open - low)

//Detect internal bearish Structure
if ta.crossunder(close, ibtm_y) and ibtm_cross and btm_y != ibtm_y and bear_concordant
    bool choch = false
    
    if itrend > 0
        choch := true
        bear_ichoch_alert := true
    else 
        bear_ibos_alert := true
    
    txt = choch ? 'CHoCH' : 'BOS'

    if show_internals
        if show_ibear == 'All' or (show_ibear == 'BOS' and not choch) or (show_ibear == 'CHoCH' and choch)
            display_Structure(ibtm_x, ibtm_y, txt, ibear_css, true, false, internal_structure_lbl_size)
    
    ibtm_cross := false
    itrend := -1
    
    //Internal Order Block
    if show_iob
        ob_coord(true, ibtm_x, iob_top, iob_btm, iob_left, iob_type)

//Detect bearish Structure
if ta.crossunder(close, btm_y) and btm_cross
    bool choch = na
    
    if trend > 0
        choch := true
        bear_choch_alert := true
    else 
        bear_bos_alert := true

    txt = choch ? 'CHoCH' : 'BOS'
    
    if show_Structure
        if show_bear == 'All' or (show_bear == 'BOS' and not choch) or (show_bear == 'CHoCH' and choch)
            display_Structure(btm_x, btm_y, txt, bear_css, false, false, swing_structure_lbl_size)
    
    //Order Block
    if show_ob
        ob_coord(true, btm_x, ob_top, ob_btm, ob_left, ob_type)

    btm_cross := false
    trend := -1

//-----------------------------------------------------------------------------}
//Order Blocks
//-----------------------------------------------------------------------------{
//Set order blocks
var iob_boxes = array.new_box(0)
var ob_boxes = array.new_box(0)

//Delete internal order blocks box coordinates if top/bottom is broken
for element in iob_type
    index = array.indexof(iob_type, element)

    if close < array.get(iob_btm, index) and element == 1
        array.remove(iob_top, index) 
        array.remove(iob_btm, index) 
        array.remove(iob_left, index) 
        array.remove(iob_type, index)
        bull_iob_break := true

    else if close > array.get(iob_top, index) and element == -1
        array.remove(iob_top, index) 
        array.remove(iob_btm, index)
        array.remove(iob_left, index) 
        array.remove(iob_type, index)
        bear_iob_break := true

//Delete internal order blocks box coordinates if top/bottom is broken
for element in ob_type
    index = array.indexof(ob_type, element)

    if close < array.get(ob_btm, index) and element == 1
        array.remove(ob_top, index) 
        array.remove(ob_btm, index) 
        array.remove(ob_left, index) 
        array.remove(ob_type, index)
        bull_ob_break := true

    else if close > array.get(ob_top, index) and element == -1
        array.remove(ob_top, index) 
        array.remove(ob_btm, index)
        array.remove(ob_left, index) 
        array.remove(ob_type, index)
        bear_ob_break := true

iob_size = array.size(iob_type)
ob_size = array.size(ob_type)

if barstate.isfirst
    if show_iob
        for i = 0 to iob_showlast-1
            array.push(iob_boxes, box.new(na,na,na,na, xloc = xloc.bar_time))
    if show_ob
        for i = 0 to ob_showlast-1
            array.push(ob_boxes, box.new(na,na,na,na, xloc = xloc.bar_time))

if iob_size > 0
    if barstate.islast
        display_ob(iob_boxes, iob_top, iob_btm, iob_left, iob_type, iob_showlast, false, iob_size)

if ob_size > 0
    if barstate.islast
        display_ob(ob_boxes, ob_top, ob_btm, ob_left, ob_type, ob_showlast, true, ob_size)

//-----------------------------------------------------------------------------}
//EQH/EQL
//-----------------------------------------------------------------------------{
var eq_prev_top = 0.
var eq_top_x = 0

var eq_prev_btm = 0.
var eq_btm_x = 0

if show_eq
    eq_top = ta.pivothigh(eq_len, eq_len)
    eq_btm = ta.pivotlow(eq_len, eq_len)

    if eq_top 
        max = math.max(eq_top, eq_prev_top)
        min = math.min(eq_top, eq_prev_top)
        
        if max < min + atr * eq_threshold
            eqh_line = line.new(eq_top_x, eq_prev_top, n-eq_len, eq_top
              , color = bear_css
              , style = line.style_dotted)

            eqh_lbl = label.new(int(math.avg(n-eq_len, eq_top_x)), eq_top, 'EQH'
              , color = #00000000
              , textcolor = bear_css
              , style = label.style_label_down
              , size = eqhl_lbl_size)

            if GrafikSadelestir == 'TEMIZLE'
                line.delete(eqh_line[1])
                label.delete(eqh_lbl[1])
            
            eqh_alert := true

        eq_prev_top := eq_top
        eq_top_x := n-eq_len

    if eq_btm 
        max = math.max(eq_btm, eq_prev_btm)
        min = math.min(eq_btm, eq_prev_btm)
        
        if min > max - atr * eq_threshold
            eql_line = line.new(eq_btm_x, eq_prev_btm, n-eq_len, eq_btm
              , color = bull_css
              , style = line.style_dotted)

            eql_lbl = label.new(int(math.avg(n-eq_len, eq_btm_x)), eq_btm, 'EQL'
              , color = #00000000
              , textcolor = bull_css
              , style = label.style_label_up
              , size = eqhl_lbl_size)

            eql_alert := true

            if GrafikSadelestir == 'TEMIZLE'
                line.delete(eql_line[1])
                label.delete(eql_lbl[1])

        eq_prev_btm := eq_btm
        eq_btm_x := n-eq_len



//-----------------------------------------------------------------------------}
//Premium/Discount/Equilibrium zones
//-----------------------------------------------------------------------------{
var premium = box.new(na, na, na, na
  , bgcolor = color.new(premium_css, 80)
  , border_color = na)

var premium_lbl = label.new(na, na
  , text = 'Premium'
  , color = TRANSP_CSS
  , textcolor = premium_css
  , style = label.style_label_down
  , size = size.small)

var eq = box.new(na, na, na, na
  , bgcolor = color.rgb(120, 123, 134, 80)
  , border_color = na)

var eq_lbl = label.new(na, na
  , text = 'Equilibrium'
  , color = TRANSP_CSS
  , textcolor = eq_css
  , style = label.style_label_left
  , size = size.small)

var discount = box.new(na, na, na, na
  , bgcolor = color.new(discount_css, 80)
  , border_color = na)

var discount_lbl = label.new(na, na
  , text = 'Discount'
  , color = TRANSP_CSS
  , textcolor = discount_css
  , style = label.style_label_up
  , size = size.small)

//Show Premium/Discount Areas
if barstate.islast and show_sd
    avg = math.avg(trail_up, trail_dn)

    box.set_lefttop(premium, math.max(top_x, btm_x), trail_up)
    box.set_rightbottom(premium, n, .95 * trail_up + .05 * trail_dn)

    label.set_xy(premium_lbl, int(math.avg(math.max(top_x, btm_x), n)), trail_up)

    box.set_lefttop(eq, math.max(top_x, btm_x), .525 * trail_up + .475*trail_dn)
    box.set_rightbottom(eq, n, .525 * trail_dn + .475 * trail_up)

    label.set_xy(eq_lbl, n, avg)
    
    box.set_lefttop(discount, math.max(top_x, btm_x), .95 * trail_dn + .05 * trail_up)
    box.set_rightbottom(discount, n, trail_dn)
    label.set_xy(discount_lbl, int(math.avg(math.max(top_x, btm_x), n)), trail_dn)

//-----------------------------------------------------------------------------}
//Trend
//-----------------------------------------------------------------------------{
var color trend_css = na

if show_trend
    if style == 'DolgunBoyama'
        trend_css := itrend == 1 ? bull_css : bear_css
    else if style == 'SadeBoyama'
        trend_css := itrend == 1 ? #b2b5be : #5d606b

plotcandle(open, high, low, close
  , color = trend_css
  , wickcolor = trend_css
  , bordercolor = trend_css
  , editable = false)

//-----------------------------------------------------------------------------}
//Alerts
//-----------------------------------------------------------------------------{
//Internal Structure
alertcondition(bull_ibos_alert, 'Internal Bullish BOS', 'Internal Bullish BOS formed')
alertcondition(bull_ichoch_alert, 'Internal Bullish CHoCH', 'Internal Bullish CHoCH formed')

alertcondition(bear_ibos_alert, 'Internal Bearish BOS', 'Internal Bearish BOS formed')
alertcondition(bear_ichoch_alert, 'Internal Bearish CHoCH', 'Internal Bearish CHoCH formed')

//Swing Structure
alertcondition(bull_bos_alert, 'Bullish BOS', 'güçlü Bullish bos')
alertcondition(bull_choch_alert, 'Bullish CHoCH', 'güçlü Bullish choch')


alertcondition(bear_bos_alert, 'Bearish BOS', 'güçlü Bearish bos')
alertcondition(bear_choch_alert, 'Bearish CHoCH', 'güçlü Bearish choch')

//order Blocks
alertcondition(bull_iob_break, 'Bullish Internal OB Breakout', 'Price broke bullish internal OB')
alertcondition(bear_iob_break, 'Bearish Internal OB Breakout', 'Price broke bearish internal OB')

alertcondition(bull_ob_break, 'Bullish Swing OB Breakout', 'Price broke bullish swing OB')
alertcondition(bear_ob_break, 'Bearish Swing OB Breakout', 'Price broke bearish swing OB')

//EQH/EQL
alertcondition(eqh_alert, 'Equal Highs', 'Equal highs detected')
alertcondition(eql_alert, 'Equal Lows', 'Equal lows detected')





///////////////////
//////////////////
/////////////////////
/////////////////////
//////////////////////

// GİRİŞLER
lengthlux = 18//input.int(18, 'Swing Detection Lookback')
mult = 1.//input.float(1., 'Slope', minval = 0, step = .1)
calcMethod = 'Atr'//input.string('Atr', 'Slope Calculation Method', options = ['Atr','Stdev','Linreg'])
backpaint = true//input(true, tooltip = 'Backpainting offset displayed elements in the past. Disable backpainting to see real time information returned by the indicator.',group = srGR)

//Style
upCss = color.teal//input.color(color.teal, 'Up Trendline Color',group = srGR)
dnCss = color.red//input.color(color.red, 'Down Trendline Color', group = srGR)
showExt = true//input(true, 'Show Extended Lines')
//showTrendLines = input(true, "Trend Lines Göster ?")


//-----------------------------------------------------------------------------}
//Calculations
//-----------------------------------------------------------------------------{
var upperlux = 0.
var lowerlux = 0.
var slope_ph = 0.
var slope_pl = 0.

var offset = backpaint ? lengthlux : 0

nlux = bar_index
srclux = close

phluxx = ta.pivothigh(lengthlux, lengthlux)
plluxx = ta.pivotlow(lengthlux, lengthlux)

//Slope Calculation Method
slope = switch calcMethod
    'Atr'    => ta.atr(lengthlux) / lengthlux * mult
    'Stdev'  => ta.stdev(srclux,lengthlux) / lengthlux * mult
    'Linreg' => math.abs(ta.sma(srclux * nlux, lengthlux) - ta.sma(srclux, lengthlux) * ta.sma(nlux, lengthlux)) / ta.variance(nlux, lengthlux) / 2 * mult

//Get slopes and calculate trendlines
slope_ph := phluxx ? slope : slope_ph
slope_pl := plluxx ? slope : slope_pl

upperlux :=  phluxx ? phluxx : upperlux - slope_ph
lowerlux :=  plluxx ? plluxx : lowerlux + slope_pl

var upos = 0
var dnos = 0
upos :=  phluxx ? 0 : close > upperlux - slope_ph * lengthlux ? 1 : upos
dnos :=  plluxx ? 0 : close < lowerlux + slope_pl * lengthlux ? 1 : dnos

//-----------------------------------------------------------------------------}
//Extended Lines
//-----------------------------------------------------------------------------{

var uptl  =  line.new(na,na,na,na, color = upCss, style = line.style_dashed, extend = extend.right) 
var dntl  =  line.new(na,na,na,na, color = dnCss, style = line.style_dashed, extend = extend.right) 
if   phluxx and showExt 
    uptl.set_xy1(nlux-offset, backpaint ? phluxx : upperlux - slope_ph * lengthlux)
    uptl.set_xy2(nlux-offset+1, backpaint ? phluxx - slope : upperlux - slope_ph * (lengthlux+1))

if   plluxx and showExt 
    dntl.set_xy1(nlux-offset, backpaint ? plluxx : lowerlux + slope_pl * lengthlux)
    dntl.set_xy2(nlux-offset+1, backpaint ? plluxx + slope : lowerlux + slope_pl * (lengthlux+1))

//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{

plot(showTrendLines ? (backpaint ? upperlux : upperlux - slope_ph * lengthlux) : na, 'Upper', color = phluxx ? na : upCss, offset = -offset)
plot(showTrendLines ? (backpaint ? lowerlux : lowerlux + slope_pl * lengthlux) : na, 'Lower', color = plluxx ? na : dnCss, offset = -offset)

// Alım Satım Koşulları
///////////////////////////////////////////////////////////////////////////////////////////////

luxalgoal = upos > upos[1] 
luxalgosat = dnos > dnos[1]  


//luxalgo = input(false, title="luxalgo", group="Teyit")


//plotshape(luxalgo and luxalgoal  ? low : na, "Upper Break", shape.labelup, location.absolute, upCss, text = "B", textcolor = color.white, size = size.tiny)

//plotshape(luxalgo and luxalgosat  ? high : na, "Lower Break", shape.labeldown , location.absolute, dnCss, text = "B", textcolor = color.white, size = size.tiny)

////////////////////////////////////////////////
//////////////////
///////////////
/////////////
prd31 = 14//input.int(defval=14, title='Pivot Period', minval=1, maxval=50)
source31 = 'Close'//input.string(defval='Close', title='source31 for Pivot Points', options=['Close', 'High/Low'])
searchdiv = 'Regular/Hidden'//input.string(defval='Regular/Hidden', title='Divergence Type', options=['Regular', 'Hidden', 'Regular/Hidden'])
showindis = 'Don\'t Show'//input.string(defval='Don\'t Show', title='Show Indicator Names', options=['Full', 'First Letter', 'Don\'t Show'])
showlimit = input.int(5, title='Minimum Uyumsuzluk?', minval=1, maxval=11,group="Uyumsuzluk")
maxpp = 10//input.int(defval=10, title='Maximum Pivot Points to Check', minval=10, maxval=20)
maxbars = 100//input.int(defval=100, title='Maximum Bars to Check', minval=100, maxval=200)
shownum = input(defval=false, title='Uyumsuzluk göster?',group="Uyumsuzluk")
showlast = false//input(defval=false, title='Show Only Last Divergence')
dontconfirm = input(defval=true, title='Onay Beklemeyin?',group="Uyumsuzluk")
showlines = input(defval=false, title='Uyumsuzluk Ciz?',group="Uyumsuzluk")
showpivot = false//input(defval=false, title='Show Pivot Points')
calcmacd = true//input(defval=true, title='MACD')
calcmacda = true//input(defval=true, title='MACD Histogram')
calcrsi = true//input(defval=true, title='RSI')
calcstoc = true//input(defval=true, title='Stochastic')
calccci = true//input(defval=true, title='CCI')
calcmom = true//input(defval=true, title='Momentum')
calcobv = true//input(defval=true, title='OBV')
calcvwmacd = true//input(true, title='VWmacd')
calccmf = true//input(true, title='Chaikin Money Flow')
calcmfi = true//input(true, title='Money Flow Index')
calcext = true//input(true, title='Check External Indicator')
externalindi = close//input(defval=close, title='External Indicator')
pos_reg_div_col = color.yellow//input(defval=color.yellow, title='Positive Regular Divergence')
neg_reg_div_col = color.navy//input(defval=color.navy, title='Negative Regular Divergence')
pos_hid_div_col = color.lime//input(defval=color.lime, title='Positive Hidden Divergence')
neg_hid_div_col = color.red//input(defval=color.red, title='Negative Hidden Divergence')
pos_div_text_col = color.black//input(defval=color.black, title='Positive Divergence Text Color')
neg_div_text_col = color.white//input(defval=color.white, title='Negative Divergence Text Color')
reg_div_l_style_ = 'Solid'//input.string(defval='Solid', title='Regular Divergence Line Style', options=['Solid', 'Dashed', 'Dotted'])
hid_div_l_style_ = 'Dashed'//input.string(defval='Dashed', title='Hdden Divergence Line Style', options=['Solid', 'Dashed', 'Dotted'])
reg_div_l_width = 2//input.int(defval=2, title='Regular Divergence Line Width', minval=1, maxval=5)
hid_div_l_width = 1//input.int(defval=1, title='Hidden Divergence Line Width', minval=1, maxval=5)
showmas = false//input.bool(defval=false, title='Show MAs 50 & 200', inline='ma12')
cma1col = color.lime//input.color(defval=color.lime, title='', inline='ma12')
cma2col = color.red//input.color(defval=color.red, title='', inline='ma12')

//plot(showmas ? ta.sma(close, 50) : na, color=showmas ? cma1col : na)
//plot(showmas ? ta.sma(close, 200) : na, color=showmas ? cma2col : na)

// set line styles
var reg_div_l_style = reg_div_l_style_ == 'Solid' ? line.style_solid : reg_div_l_style_ == 'Dashed' ? line.style_dashed : line.style_dotted
var hid_div_l_style = hid_div_l_style_ == 'Solid' ? line.style_solid : hid_div_l_style_ == 'Dashed' ? line.style_dashed : line.style_dotted




// get indicators
rsi31 = ta.rsi(close, 14)  // RSI
[macd31, signal1, deltamacd] = ta.macd(close, 12, 26, 9)  // MACD
moment = ta.mom(close, 10)  // Momentum
cci = ta.cci(close, 10)  // CCI
Obv = ta.obv  // OBV
stk = ta.sma(ta.stoch(close, high, low, 14), 3)  // Stoch
maFast = ta.vwma(close, 12)  // volume weighted macd
maSlow = ta.vwma(close, 26)
vwmacd = maFast - maSlow
Cmfm = (close - low - (high - close)) / (high - low)  // Chaikin money flow
Cmfv = Cmfm * volume
cmf = ta.sma(Cmfv, 21) / ta.sma(volume, 21)
Mfi = ta.mfi(close, 14)  // Moneyt Flow Index

// keep indicators names and colors in arrays
var indicators_name = array.new_string(11)
var div_colors = array.new_color(4)
if barstate.isfirst
    // names
    array.set(indicators_name, 0, showindis == 'Full' ? 'MACD' : 'M')
    array.set(indicators_name, 1, showindis == 'Full' ? 'Hist' : 'H')
    array.set(indicators_name, 2, showindis == 'Full' ? 'RSI' : 'E')
    array.set(indicators_name, 3, showindis == 'Full' ? 'Stoch' : 'S')
    array.set(indicators_name, 4, showindis == 'Full' ? 'CCI' : 'C')
    array.set(indicators_name, 5, showindis == 'Full' ? 'MOM' : 'M')
    array.set(indicators_name, 6, showindis == 'Full' ? 'OBV' : 'O')
    array.set(indicators_name, 7, showindis == 'Full' ? 'VWMACD' : 'V')
    array.set(indicators_name, 8, showindis == 'Full' ? 'CMF' : 'C')
    array.set(indicators_name, 9, showindis == 'Full' ? 'MFI' : 'M')
    array.set(indicators_name, 10, showindis == 'Full' ? 'Extrn' : 'X')
    //colors
    array.set(div_colors, 0, pos_reg_div_col)
    array.set(div_colors, 1, neg_reg_div_col)
    array.set(div_colors, 2, pos_hid_div_col)
    array.set(div_colors, 3, neg_hid_div_col)

// Check if we get new Pivot High Or Pivot Low
float phuyum = ta.pivothigh(source31 == 'Close' ? close : high, prd31, prd31)
float pluyum = ta.pivotlow(source31 == 'Close' ? close : low, prd31, prd31)
plotshape(phuyum and showpivot, text='H', style=shape.labeldown, color=color.new(color.white, 100), textcolor=color.new(color.red, 0), location=location.abovebar, offset=-prd31)
plotshape(pluyum and showpivot, text='L', style=shape.labelup, color=color.new(color.white, 100), textcolor=color.new(color.lime, 0), location=location.belowbar, offset=-prd31)

// keep values and positions of Pivot Highs/Lows in the arrays
var int maxarraysize = 20
var ph_positions = array.new_int(maxarraysize, 0)
var pl_positions = array.new_int(maxarraysize, 0)
var ph_vals = array.new_float(maxarraysize, 0.)
var pl_vals = array.new_float(maxarraysize, 0.)

// add PHs to the array
if phuyum
    array.unshift(ph_positions, bar_index)
    array.unshift(ph_vals, phuyum)
    if array.size(ph_positions) > maxarraysize
        array.pop(ph_positions)
        array.pop(ph_vals)

// add PLs to the array
if pluyum
    array.unshift(pl_positions, bar_index)
    array.unshift(pl_vals, pluyum)
    if array.size(pl_positions) > maxarraysize
        array.pop(pl_positions)
        array.pop(pl_vals)

// functions to check Regular Divergences and Hidden Divergences

// function to check positive regular or negative hidden divergence
// cond == 1 => positive_regular, cond == 2=> negative_hidden
positive_regular_positive_hidden_divergence(src, cond) =>
    divlen = 0
    prsc = source31 == 'Close' ? close : low
    // if indicators higher than last value and close price is higher than las close 
    if dontconfirm or src > src[1] or close > close[1]
        startpoint = dontconfirm ? 0 : 1  // don't check last candle
        // we search last 15 PPs
        for x = 0 to maxpp - 1 by 1
            len = bar_index - array.get(pl_positions, x) + prd31
            // if we reach non valued array element or arrived 101. or previous bars then we don't search more
            if array.get(pl_positions, x) == 0 or len > maxbars
                break
            if len > 5 and (cond == 1 and src[startpoint] > src[len] and prsc[startpoint] < nz(array.get(pl_vals, x)) or cond == 2 and src[startpoint] < src[len] and prsc[startpoint] > nz(array.get(pl_vals, x)))
                slope1 = (src[startpoint] - src[len]) / (len - startpoint)
                virtual_line1 = src[startpoint] - slope1
                slope2 = (close[startpoint] - close[len]) / (len - startpoint)
                virtual_line2 = close[startpoint] - slope2
                arrived = true
                for y = 1 + startpoint to len - 1 by 1
                    if src[y] < virtual_line1 or nz(close[y]) < virtual_line2
                        arrived := false
                        break
                    virtual_line1 -= slope1
                    virtual_line2 -= slope2
                    virtual_line2

                if arrived
                    divlen := len
                    break
    divlen

// function to check negative regular or positive hidden divergence
// cond == 1 => negative_regular, cond == 2=> positive_hidden
negative_regular_negative_hidden_divergence(src, cond) =>
    divlen = 0
    prsc = source31 == 'Close' ? close : high
    // if indicators higher than last value and close price is higher than las close 
    if dontconfirm or src < src[1] or close < close[1]
        startpoint = dontconfirm ? 0 : 1  // don't check last candle
        // we search last 15 PPs
        for x = 0 to maxpp - 1 by 1
            len = bar_index - array.get(ph_positions, x) + prd31
            // if we reach non valued array element or arrived 101. or previous bars then we don't search more
            if array.get(ph_positions, x) == 0 or len > maxbars
                break
            if len > 5 and (cond == 1 and src[startpoint] < src[len] and prsc[startpoint] > nz(array.get(ph_vals, x)) or cond == 2 and src[startpoint] > src[len] and prsc[startpoint] < nz(array.get(ph_vals, x)))
                slope1 = (src[startpoint] - src[len]) / (len - startpoint)
                virtual_line1 = src[startpoint] - slope1
                slope2 = (close[startpoint] - nz(close[len])) / (len - startpoint)
                virtual_line2 = close[startpoint] - slope2
                arrived = true
                for y = 1 + startpoint to len - 1 by 1
                    if src[y] > virtual_line1 or nz(close[y]) > virtual_line2
                        arrived := false
                        break
                    virtual_line1 -= slope1
                    virtual_line2 -= slope2
                    virtual_line2

                if arrived
                    divlen := len
                    break
    divlen

// calculate 4 types of divergence if enabled in the options and return divergences in an array
calculate_divs(cond, indicator_1) =>
    divs = array.new_int(4, 0)
    array.set(divs, 0, cond and (searchdiv == 'Regular' or searchdiv == 'Regular/Hidden') ? positive_regular_positive_hidden_divergence(indicator_1, 1) : 0)
    array.set(divs, 1, cond and (searchdiv == 'Regular' or searchdiv == 'Regular/Hidden') ? negative_regular_negative_hidden_divergence(indicator_1, 1) : 0)
    array.set(divs, 2, cond and (searchdiv == 'Hidden' or searchdiv == 'Regular/Hidden') ? positive_regular_positive_hidden_divergence(indicator_1, 2) : 0)
    array.set(divs, 3, cond and (searchdiv == 'Hidden' or searchdiv == 'Regular/Hidden') ? negative_regular_negative_hidden_divergence(indicator_1, 2) : 0)
    divs

// array to keep all divergences
var all_divergences = array.new_int(44)  // 11 indicators * 4 divergence = 44 elements
// set related array elements
array_set_divs(div_pointer, index) =>
    for x = 0 to 3 by 1
        array.set(all_divergences, index * 4 + x, array.get(div_pointer, x))

// set divergences array 
array_set_divs(calculate_divs(calcmacd, macd31), 0)
array_set_divs(calculate_divs(calcmacda, deltamacd), 1)
array_set_divs(calculate_divs(calcrsi, rsi31), 2)
array_set_divs(calculate_divs(calcstoc, stk), 3)
array_set_divs(calculate_divs(calccci, cci), 4)
array_set_divs(calculate_divs(calcmom, moment), 5)
array_set_divs(calculate_divs(calcobv, Obv), 6)
array_set_divs(calculate_divs(calcvwmacd, vwmacd), 7)
array_set_divs(calculate_divs(calccmf, cmf), 8)
array_set_divs(calculate_divs(calcmfi, Mfi), 9)
array_set_divs(calculate_divs(calcext, externalindi), 10)

// check minimum number of divergence, if less than showlimit then delete all divergence
total_div = 0
for x = 0 to array.size(all_divergences) - 1 by 1
    total_div += math.round(math.sign(array.get(all_divergences, x)))
    total_div

if total_div < showlimit
    array.fill(all_divergences, 0)

// keep line in an array
var pos_div_lines = array.new_line(0)
var neg_div_lines = array.new_line(0)
var pos_div_labels = array.new_label(0)
var neg_div_labels = array.new_label(0)

// remove old lines and labels if showlast option is enabled
delete_old_pos_div_lines() =>
    if array.size(pos_div_lines) > 0
        for j = 0 to array.size(pos_div_lines) - 1 by 1
            line.delete(array.get(pos_div_lines, j))
        array.clear(pos_div_lines)

delete_old_neg_div_lines() =>
    if array.size(neg_div_lines) > 0
        for j = 0 to array.size(neg_div_lines) - 1 by 1
            line.delete(array.get(neg_div_lines, j))
        array.clear(neg_div_lines)

delete_old_pos_div_labels() =>
    if array.size(pos_div_labels) > 0
        for j = 0 to array.size(pos_div_labels) - 1 by 1
            label.delete(array.get(pos_div_labels, j))
        array.clear(pos_div_labels)

delete_old_neg_div_labels() =>
    if array.size(neg_div_labels) > 0
        for j = 0 to array.size(neg_div_labels) - 1 by 1
            label.delete(array.get(neg_div_labels, j))
        array.clear(neg_div_labels)

// delete last creted lines and labels until we met new phuyum/PV 
delete_last_pos_div_lines_label(n) =>
    if n > 0 and array.size(pos_div_lines) >= n
        asz = array.size(pos_div_lines)
        for j = 1 to n by 1
            line.delete(array.get(pos_div_lines, asz - j))
            array.pop(pos_div_lines)
        if array.size(pos_div_labels) > 0
            label.delete(array.get(pos_div_labels, array.size(pos_div_labels) - 1))
            array.pop(pos_div_labels)

delete_last_neg_div_lines_label(n) =>
    if n > 0 and array.size(neg_div_lines) >= n
        asz = array.size(neg_div_lines)
        for j = 1 to n by 1
            line.delete(array.get(neg_div_lines, asz - j))
            array.pop(neg_div_lines)
        if array.size(neg_div_labels) > 0
            label.delete(array.get(neg_div_labels, array.size(neg_div_labels) - 1))
            array.pop(neg_div_labels)

// variables for Alerts
pos_reg_div_detected = false
neg_reg_div_detected = false
pos_hid_div_detected = false
neg_hid_div_detected = false

// to remove lines/labels until we met new // phuyum/pluyum
var last_pos_div_lines = 0
var last_neg_div_lines = 0
var remove_last_pos_divs = false
var remove_last_neg_divs = false
if pluyum
    remove_last_pos_divs := false
    last_pos_div_lines := 0
    last_pos_div_lines
if phuyum
    remove_last_neg_divs := false
    last_neg_div_lines := 0
    last_neg_div_lines

// draw divergences lines and labels
divergence_text_top = ''
divergence_text_bottom = ''
distances = array.new_int(0)
dnumdiv_top = 0
dnumdiv_bottom = 0
top_label_col = color.white
bottom_label_col = color.white
old_pos_divs_can_be_removed = true
old_neg_divs_can_be_removed = true
startpoint = dontconfirm ? 0 : 1  // used for don't confirm option

for x = 0 to 10 by 1
    div_type = -1
    for y = 0 to 3 by 1
        if array.get(all_divergences, x * 4 + y) > 0  // any divergence?
            div_type := y
            if y % 2 == 1
                dnumdiv_top += 1
                top_label_col := array.get(div_colors, y)
                top_label_col
            if y % 2 == 0
                dnumdiv_bottom += 1
                bottom_label_col := array.get(div_colors, y)
                bottom_label_col
            if not array.includes(distances, array.get(all_divergences, x * 4 + y))  // line not exist ?
                array.push(distances, array.get(all_divergences, x * 4 + y))
                new_line = showlines ? line.new(x1=bar_index - array.get(all_divergences, x * 4 + y), y1=source31 == 'Close' ? close[array.get(all_divergences, x * 4 + y)] : y % 2 == 0 ? low[array.get(all_divergences, x * 4 + y)] : high[array.get(all_divergences, x * 4 + y)], x2=bar_index - startpoint, y2=source31 == 'Close' ? close[startpoint] : y % 2 == 0 ? low[startpoint] : high[startpoint], color=array.get(div_colors, y), style=y < 2 ? reg_div_l_style : hid_div_l_style, width=y < 2 ? reg_div_l_width : hid_div_l_width) : na
                if y % 2 == 0
                    if old_pos_divs_can_be_removed
                        old_pos_divs_can_be_removed := false
                        if not showlast and remove_last_pos_divs
                            delete_last_pos_div_lines_label(last_pos_div_lines)
                            last_pos_div_lines := 0
                            last_pos_div_lines
                        if showlast
                            delete_old_pos_div_lines()
                    array.push(pos_div_lines, new_line)
                    last_pos_div_lines += 1
                    remove_last_pos_divs := true
                    remove_last_pos_divs

                if y % 2 == 1
                    if old_neg_divs_can_be_removed
                        old_neg_divs_can_be_removed := false
                        if not showlast and remove_last_neg_divs
                            delete_last_neg_div_lines_label(last_neg_div_lines)
                            last_neg_div_lines := 0
                            last_neg_div_lines
                        if showlast
                            delete_old_neg_div_lines()
                    array.push(neg_div_lines, new_line)
                    last_neg_div_lines += 1
                    remove_last_neg_divs := true
                    remove_last_neg_divs

            // set variables for alerts
            if y == 0
                pos_reg_div_detected := true
                pos_reg_div_detected
            if y == 1
                neg_reg_div_detected := true
                neg_reg_div_detected
            if y == 2
                pos_hid_div_detected := true
                pos_hid_div_detected
            if y == 3
                neg_hid_div_detected := true
                neg_hid_div_detected
    // get text for labels
    if div_type >= 0
        divergence_text_top += (div_type % 2 == 1 ? showindis != 'Don\'t Show' ? array.get(indicators_name, x) + '\n' : '' : '')
        divergence_text_bottom += (div_type % 2 == 0 ? showindis != 'Don\'t Show' ? array.get(indicators_name, x) + '\n' : '' : '')
        divergence_text_bottom


// draw labels
if showindis != 'Don\'t Show' or shownum
    if shownum and dnumdiv_top > 0
        divergence_text_top += str.tostring(dnumdiv_top)
        divergence_text_top
    if shownum and dnumdiv_bottom > 0
        divergence_text_bottom += str.tostring(dnumdiv_bottom)
        divergence_text_bottom
    if divergence_text_top != ''
        if showlast
            delete_old_neg_div_labels()
        array.push(neg_div_labels, label.new(x=bar_index, y=math.max(high, high[1]), text=divergence_text_top, color=top_label_col, textcolor=neg_div_text_col, style=label.style_label_down))

    if divergence_text_bottom != ''
        if showlast
            delete_old_pos_div_labels()
        array.push(pos_div_labels, label.new(x=bar_index, y=math.min(low, low[1]), text=divergence_text_bottom, color=bottom_label_col, textcolor=pos_div_text_col, style=label.style_label_up))


alertcondition(pos_reg_div_detected, title='Positive Regular Divergence Detected', message='Positive Regular Divergence Detected')
alertcondition(neg_reg_div_detected, title='Negative Regular Divergence Detected', message='Negative Regular Divergence Detected')
alertcondition(pos_hid_div_detected, title='Positive Hidden Divergence Detected', message='Positive Hidden Divergence Detected')
alertcondition(neg_hid_div_detected, title='Negative Hidden Divergence Detected', message='Negative Hidden Divergence Detected')

alertcondition(pos_reg_div_detected or pos_hid_div_detected, title='Positive Divergence Detected', message='Positive Divergence Detected')
alertcondition(neg_reg_div_detected or neg_hid_div_detected, title='Negative Divergence Detected', message='Negative Divergence Detected')

//uyumsuzluk = input(true, title="tepe dip", group="Teyit")

long = pos_reg_div_detected or pos_hid_div_detected
short = neg_reg_div_detected or neg_hid_div_detected



//plotshape( uyumsuzluk    and long and  barstate.isconfirmed ? close : na, color=color.rgb(26, 243, 6), style=shape.labelup, location=location.belowbar, size=size.normal, text="!HH!")
//plotshape(  uyumsuzluk   and short and barstate.isconfirmed ? close : na, color=color.rgb(255, 6, 6), style=shape.labeldown, location=location.abovebar, size=size.normal, text="!LL!")
//
//////// /////////
//////////////////////
////////////////////////////

uyumsuzlukkk = long or short


al =       bull_ibos_alert or bull_ichoch_alert or bull_bos_alert or bull_choch_alert
sat =      bear_ibos_alert or bear_ichoch_alert or bear_bos_alert or bear_choch_alert

var bool lastTriggerAl = false
var bool lastTriggerSat = false
if (al)
    lastTriggerAl := true
    lastTriggerSat := false
    
if (sat)
    lastTriggerAl := false
    lastTriggerSat := true
    
    
    


test12 = input(true, title=" (Analiz Yapmayı Unutmayın)🚀 💀️ ",group="Teyit",tooltip = " Piyasa Yükeselişe Yada Düşüş Başladıktan sonra  incelenen Zaman Diliminde'ki İlk kırılımı Sinyali Gösterir.::''''!!Sinyalden Sonra Gerekli TEYİT'LER Yapılmasında Fayda Vardır'''Tavsiyem TRENDLİNE KIRILIMLARI KONTROL ETMEKTE FAYDA VARDIR")
var bool boyamaYesil = false
var bool boyamaMor = false  

if (sat)
    boyamaYesil := true
alChoch = (boyamaYesil  and al  )
plotshape(series=test12 and alChoch,color=color.rgb(2, 255, 57), style=shape.labelup, location=location.belowbar, size=size.tiny , text="🚀")
if (alChoch )
    boyamaYesil := false


if (al)
    boyamaMor := true
satChoch = ( boyamaMor and sat  ) 
plotshape(series=test12 and satChoch, color=color.rgb(253, 0, 0), style=shape.labeldown, location=location.abovebar , size=size.tiny, text="💀️")
if (satChoch)  
    boyamaMor := false




//volum hacimli mumalrı ölçer
coefffff = 3//input.int(3, title = "Hacim Çarpan", minval = 1, step = 1, group="hacimli,Mumlar")

alvol = ta.crossover(volume, coefffff * ta.sma(volume, 21)) and close > open
satvol = ta.crossover(volume, coefffff * ta.sma(volume, 21)) and close < open









/////////////////
c1 = input.symbol(title='1', defval='BINANCE:BTCUSDT.P',group = "1. Grup Hisseleri")
c2 = input.symbol(title='2', defval='BINANCE:ETHUSDT.P')
c3 = input.symbol(title='3', defval='BINANCE:BCHUSDT.P')
c4 = input.symbol(title='4', defval='BINANCE:XRPUSDT.P')
c5 = input.symbol(title='5', defval='BINANCE:EOSUSDT.P')
c6 = input.symbol(title='6', defval='BINANCE:LTCUSDT.P')
c7 = input.symbol(title='7', defval='BINANCE:TRXUSDT.P')
c8 = input.symbol(title='8', defval='BINANCE:ETCUSDT.P')
c9 = input.symbol(title='9', defval='BINANCE:LINKUSDT.P')
c10 = input.symbol(title='10', defval='BINANCE:XLMUSDT.P')
c11 = input.symbol(title='11', defval='BINANCE:ADAUSDT.P')
c12 = input.symbol(title='12', defval='BINANCE:XMRUSDT.P')
c13 = input.symbol(title='13', defval='BINANCE:DASHUSDT.P')
c14 = input.symbol(title='14', defval='BINANCE:ZECUSDT.P')
c15 = input.symbol(title='15', defval='BINANCE:XTZUSDT.P')
c16 = input.symbol(title='16', defval='BINANCE:BNBUSDT.P')
c17 = input.symbol(title='17', defval='BINANCE:ATOMUSDT.P')
c18 = input.symbol(title='18', defval='BINANCE:ONTUSDT.P')
c19 = input.symbol(title='19', defval='BINANCE:IOTAUSDT.P')
c20 = input.symbol(title='20', defval='BINANCE:BATUSDT.P')
c21 = input.symbol(title='21', defval='BINANCE:VETUSDT.P')
c22 = input.symbol(title='22', defval='BINANCE:NEOUSDT.P')
c23 = input.symbol(title='23', defval='BINANCE:QTUMUSDT.P')
c24 = input.symbol(title='24', defval='BINANCE:JASMYUSDT.P')
c25 = input.symbol(title='25', defval='BINANCE:IOSTUSDT.P')
c26 = input.symbol(title='26', defval='BINANCE:THETAUSDT.P')
c27 = input.symbol(title='27', defval='BINANCE:ALGOUSDT.P')
c28 = input.symbol(title='28', defval='BINANCE:ZILUSDT.P')
c29 = input.symbol(title='29', defval='BINANCE:KNCUSDT.P')
c30 = input.symbol(title='30', defval='BINANCE:BAKEUSDT.P')
c31 = input.symbol(title='31', defval='BINANCE:ZRXUSDT.P')
c32 = input.symbol(title='32', defval='BINANCE:COMPUSDT.P')
c33 = input.symbol(title='33', defval='BINANCE:OMGUSDT.P')
c34 = input.symbol(title='34', defval='BINANCE:DOGEUSDT.P')
c35 = input.symbol(title='35', defval='BINANCE:SXPUSDT.P')
c36 = input.symbol(title='31', defval='BINANCE:KAVAUSDT.P')
c37 = input.symbol(title='32', defval='BINANCE:BANDUSDT.P')
c38 = input.symbol(title='33', defval='BINANCE:RLCUSDT.P')
c39 = input.symbol(title='34', defval='BINANCE:WAVESUSDT.P')
c40 = input.symbol(title='35', defval='BINANCE:MKRUSDT.P')







sinyal = alChoch  ? close : satChoch  ? -1 * close : 0

strateji = "TeyitSinyal"
TELEGRAMID = input.string(defval = "@", title ="TELEGRAM CHAT ID")
grafikId = input.string(defval = "", title = "GRAFİK ID")
alarmTetikle(sembol,sinyal)=>
    durum = request.security(sembol,timeframe.period,sinyal)
    mesaj = durum > 0 ? "AL" : durum < 0 ? "SAT" : ""
    if durum != 0 and str.length(sembol) > 1 // herhangi bir sinyal var ise yani
        alarmMesajiJSON = "<strong>"+ syminfo.ticker(sembol)+"</strong>" +" => "+mesaj +"\\n" + "PERİYOT : " + str.tostring(timeframe.period) +"\\n"+ "STRATEJİ : " + strateji + "\\n" + "FİYAT : " + str.tostring(math.round(math.abs(durum),2))
        reply = ',"reply_markup":{"inline_keyboard":[[{"text":"📉 Tradingview","url":"https://tr.tradingview.com/chart/'+grafikId+'/?symbol='+sembol+"&interval="+str.tostring(timeframe.period)+'"}]]}'
        
        alert(message='{"chat_id":"'+TELEGRAMID+'","text":"'+alarmMesajiJSON+'","parse_mode":"html"'+reply+'}',freq =  alert.freq_once_per_bar_close)




////

alarmTetikle(c1,sinyal)
alarmTetikle(c2,sinyal)
alarmTetikle(c3,sinyal)
alarmTetikle(c4,sinyal)
alarmTetikle(c5,sinyal)
alarmTetikle(c6,sinyal)
alarmTetikle(c7,sinyal)
alarmTetikle(c8,sinyal)
alarmTetikle(c9,sinyal)
alarmTetikle(c10,sinyal)
alarmTetikle(c11,sinyal)
alarmTetikle(c12,sinyal)
alarmTetikle(c13,sinyal)
alarmTetikle(c14,sinyal)
alarmTetikle(c15,sinyal)
alarmTetikle(c16,sinyal)
alarmTetikle(c17,sinyal)
alarmTetikle(c18,sinyal)
alarmTetikle(c19,sinyal)
alarmTetikle(c20,sinyal)
alarmTetikle(c21,sinyal)
alarmTetikle(c22,sinyal)
alarmTetikle(c23,sinyal)
alarmTetikle(c24,sinyal)
alarmTetikle(c25,sinyal)
alarmTetikle(c26,sinyal)
alarmTetikle(c27,sinyal)
alarmTetikle(c28,sinyal)
alarmTetikle(c29,sinyal)
alarmTetikle(c30,sinyal)
alarmTetikle(c31,sinyal)
alarmTetikle(c32,sinyal)
alarmTetikle(c33,sinyal)
alarmTetikle(c34,sinyal)
alarmTetikle(c35,sinyal)
alarmTetikle(c36,sinyal)
alarmTetikle(c37,sinyal)
alarmTetikle(c38,sinyal)
alarmTetikle(c39,sinyal)
alarmTetikle(c40,sinyal)



kur2=input(title="bot ile /sendMessage arasına telegram botunun tokeni yerleştir ve hepsini kopyala alram wephook yapıştır örnek teki gibi ==>", defval="https://api.telegram.org/bot.................../sendMessage",inline="xd65")

Leave a Comment