Untitled

 avatar
unknown
plain_text
18 days ago
4.5 kB
4
Indexable
// © mehmetonatt
//@version=6

indicator('Konsolidasyon Bölgeleri', overlay = true, max_bars_back = 300, max_boxes_count = 500, max_lines_count = 500, max_labels_count = 500)

showConsolidation = input(true, title = 'Konsolidasyon Bölgeleri', group = 'Konsolidasyon Bölgeleri')
ConsolOption = input.string(defval = 'İğneler', title = 'Konsolidasyon Şekli', group = 'Konsolidasyon Bölgeleri', options = ['İğneler', 'Gövde'])
prd = input.int(defval = 9, title = 'Kontrol Periodu', minval = 2, maxval = 50,tooltip= "Bölgelerin belirlenmesi için hangi zaman aralığına tekrar kontrol edileceğini gösterir", group = 'Konsolidasyon Bölgeleri') 
conslen = input.int(defval = 9, title = 'Min Konsolidasyon Periyodu', minval = 2, maxval = 20, tooltip= "Bölge belirlenirken bakılacak min. mum sayısı", group = 'Konsolidasyon Bölgeleri')
TopLineColor = input.color(defval = color.white, title = 'Üst Çizgi Rengi', group = 'Konsolidasyon Bölgeleri')
TopLineStyles = input.string(defval = 'Solid', title = 'Üst Çizgi Şekli', group = 'Konsolidasyon Bölgeleri', options = ['Solid', 'Dashed', 'Dotted'])
TopLineLength = input.int(defval = 2, title = 'Üst Çizgi Kalınlığı', group = 'Konsolidasyon Bölgeleri')
BottomLineColor = input.color(defval = color.white, title = 'Alt Çİzgi Rengi', group = 'Konsolidasyon Bölgeleri')
BottomLineStyles = input.string(defval = 'Solid', title = 'Alt Çizgi Şekli', group = 'Konsolidasyon Bölgeleri', options = ['Solid', 'Dashed', 'Dotted'])
BottomLineLength = input.int(defval = 2, title = 'Alt Çizgi Kalınlığı', group = 'Konsolidasyon Bölgeleri')

var float highSource = na
var float lowSource = na

if ConsolOption == 'İğneler'
    highSource := high
    lowSource := low
    lowSource
else
    highSource := math.max(open, close)
    lowSource := math.min(open, close)
    lowSource

float hb_ = ta.highestbars(highSource, prd) == 0 ? highSource : na
float lb_ = ta.lowestbars(lowSource, prd) == 0 ? lowSource : na
var int dir = 0
float zz = na
float pp = na

dir := not na(hb_) and na(lb_) ? 1 : not na(lb_) and na(hb_) ? -1 : dir

if not na(hb_) and not na(lb_)
    if dir == 1
        zz := hb_
        zz
    else
        zz := lb_
        zz
else
    zz := not na(hb_) ? hb_ : lb_
    zz

for x = 0 to 1000 by 1
    if na(close) or dir != dir[x]
        break
    if not na(zz[x])
        if na(pp)
            pp := zz[x]
            pp
        else
            if dir[x] == 1 and zz[x] > pp
                pp := zz[x]
                pp
            if dir[x] == -1 and zz[x] < pp
                pp := zz[x]
                pp

var int conscnt = 0
var float condhigh = na
var float condlow = na
float H_ = ta.highest(highSource, conslen)
float L_ = ta.lowest(lowSource, conslen)
var line upline = na
var line dnline = na
bool breakoutup = false
bool breakoutdown = false

if ta.change(pp) != 0
    if conscnt > conslen
        if pp > condhigh
            breakoutup := true
            breakoutup
        if pp < condlow
            breakoutdown := true
            breakoutdown
    if conscnt > 0 and pp <= condhigh and pp >= condlow
        conscnt := conscnt + 1
        conscnt
    else
        conscnt := 0
        conscnt
else
    conscnt := conscnt + 1
    conscnt

if showConsolidation // Only execute if showConsolidation is true
    if conscnt >= conslen
        if conscnt == conslen
            condhigh := H_
            condlow := L_
            condlow
        else
            line.delete(upline)
            line.delete(dnline)
            condhigh := math.max(condhigh, highSource)
            condlow := math.min(condlow, lowSource)
            condlow

        upline := line.new(bar_index, condhigh, bar_index - conscnt, condhigh, color = TopLineColor, style = TopLineStyles == 'Solid' ? line.style_solid : TopLineStyles == 'Dashed' ? line.style_dashed : line.style_dotted, width = TopLineLength)
        dnline := line.new(bar_index, condlow, bar_index - conscnt, condlow, color = BottomLineColor, style = BottomLineStyles == 'Solid' ? line.style_solid : BottomLineStyles == 'Dashed' ? line.style_dashed : line.style_dotted, width = BottomLineLength)
        dnline

alertcondition(breakoutup, title = 'Yukarı Kırılım', message = 'Konsolidasyon Yukarı Kırılım')
alertcondition(breakoutdown, title = 'Aşağı Kırılım', message = 'Konsolidasyon Yukarı Kırılım')


Editor is loading...
Leave a Comment