İçeriğe geç

TradingView Üçlü İndikatör Paketi: Ichimoku Cloud, Auto Fib Extension ve HO

TradingView’da indikatör kullanım limiti olduğu için birden fazla indikatörü tek bir indikatöre çevirerek daha fazla indikatöre sahip olabilirsiniz. Bu sayfada Ichimoku Cloud, Auto Fib Extension ve SMA/EMA vardır.

Hareketli ortalamaların (sma/ema) ayarlarını ve değerlerini dilediğiniz gibi indikatör ayarları kısmından kodlara müdahale etmeden kolay bir şekilde yapabilirsiniz.

İndikatörler güncel sürüm versiyon=5 ile kodlanmıştır.

@ohantekten

Son güncelleme: 17 Aralık 2021

CW

Tradingview üçlü indikatör paketi

// © ohantekten
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © orhantekten.com/kategori/indikator
// Bu dökümanda Ichimoku bulutu, auto fib extension ve 9 adet hareketli ortalama vardır. 
//@version=5

indicator(title='ichimoku+oto fib', shorttitle='ich+fib', overlay=true)
conversionPeriods = input.int(9, minval=1, title="ICH Conversion Line Length")
basePeriods = input.int(26, minval=1, title="ICH Base Line Length")
laggingSpan2Periods = input.int(52, minval=1, title="ICH Leading Span B Length")
displacement = input.int(26, minval=1, title="ICH Displacement")
donchian(len) => math.avg(ta.lowest(len), ta.highest(len))
conversionLine = donchian(conversionPeriods)
baseLine = donchian(basePeriods)
leadLine1 = math.avg(conversionLine, baseLine)
leadLine2 = donchian(laggingSpan2Periods)
plot(conversionLine, color=#2962FF, title="ICH Dönüş Çizgisi")
plot(baseLine, color=#B71C1C, title="ICH Temel Çizgi")
plot(close, offset = -displacement + 1, color=#43A047, title="ICH Gecikme Aralığı")
p1 = plot(leadLine1, offset = displacement - 1, color=#A5D6A7,
	 title="ICH Leading Span A")
p2 = plot(leadLine2, offset = displacement - 1, color=#EF9A9A,
	 title="ICH Leading Span B")
fill(p1, p2, color = leadLine1 > leadLine2 ? color.rgb(67, 160, 71, 90) : color.rgb(244, 67, 54, 90))




src = input(title='Source', defval=close)

length1 = input(5, 'MA 1')
plot(ta.sma(src, length1), color=color.new(color.red, 0), linewidth=1, title='MA 1')

length2 = input(10, 'MA 2')
plot(ta.sma(src, length2), color=color.new(color.blue, 0), linewidth=2, title='MA 2')

length3 = input(20, 'MA 3')
plot(ta.sma(src, length3), color=color.new(color.orange, 0), linewidth=3, title='MA 3')

length4 = input(50, 'MA 4')
plot(ta.sma(src, length4), color=color.new(color.black, 0), linewidth=2, title='MA 4')


length5 = input(8, 'EMA 1')
plot(ta.ema(src, length5), color=color.new(color.white, 0), linewidth=2, title='EMA 1')

length6 = input(13, 'EMA 2')
plot(ta.ema(src, length6), color=color.new(color.yellow, 0), linewidth=2, title='EMA 2')

length7 = input(21, 'EMA 3')
plot(ta.ema(src, length7), color=color.new(color.red, 0), linewidth=2, title='EMA 3')

length8 = input(30, 'EMA 4')
plot(ta.ema(src, length8), color=color.new(color.blue, 0), linewidth=2, title='EMA 4')

length9 = input(50, 'EMA 5')
plot(ta.ema(src, length9), color=color.new(color.blue, 0), linewidth=2, title='EMA 5')


depthTooltip = "The minimum number of bars that will be taken into account when calculating the indicator."
depth = input.int(title="Depth", defval=10, minval=1, inline = "Pivots", tooltip=depthTooltip)
reverse = input(false, "Reverse")
var extendLeft = input(false, "Extend Left    |    Extend Right", inline = "Extend Lines")
var extendRight = input(true, "", inline = "Extend Lines")
var extending = extend.none
if extendLeft and extendRight
    extending := extend.both
if extendLeft and not extendRight
    extending := extend.left
if not extendLeft and extendRight
    extending := extend.right
prices = input(true, "Show Prices")
levels = input(true, "Show Levels", inline = "Levels")
levelsFormat = input.string("Values", "", options = ["Values", "Percent"], inline = "Levels")
labelsPosition = input.string("Left", "Labels Position", options = ["Left", "Right"])

var float upperThreshold = 0.236
var float lowerThreshold = 1.0

var line lineLastHL = na
var line lineLastLH = na
var line lineLast = na

var float iLastH = 0
var float iLastL = 0
var float pLastH = 0
var float pLastL = 0

var float[] iPivotsH = array.new_float()
var float[] iPivotsL = array.new_float()
var float[] pPivotsH = array.new_float()
var float[] pPivotsL = array.new_float()

var isHighLast = false
var float startPrice = na
var float endPrice = na
var float diff = na

pivots(src, length, isHigh) =>
    l2 = length * 2
    c = nz(src[length])
    ok = true
    for i = 0 to l2
        if isHigh and src[i] > c
            ok := false

        if not isHigh and src[i] < c
            ok := false
    if ok
        [bar_index[length], c]
    else
        [int(na), float(na)]
[iH, pH] = pivots(high, depth / 2, true)
[iL, pL] = pivots(low, depth / 2, false)

countPivotsH = array.size(iPivotsH)
countPivotsL = array.size(iPivotsL)

if countPivotsH > 0 and countPivotsL > 0
    iLastH := array.get(iPivotsH, countPivotsH-1)
    iLastL := array.get(iPivotsL, countPivotsL-1)
    isHighLast := iLastH > iLastL
    iLastH := 1
    if isHighLast
        if not na(iH)
            pLastH := array.get(pPivotsH, countPivotsH-1)
            if pH > pLastH
                array.set(iPivotsH, countPivotsH-1, iH)
                array.set(pPivotsH, countPivotsH-1, pH)
            iH := na
    else
        if not na(iL)
            pLastL := array.get(pPivotsL, countPivotsL-1)
            if pL < pLastL
                array.set(iPivotsL, countPivotsL-1, iL)
                array.set(pPivotsL, countPivotsL-1, pL)
            iL := na

if not na(iH)
    array.push(iPivotsH, iH)
    array.push(pPivotsH, pH)

if not na(iL)
    array.push(iPivotsL, iL)
    array.push(pPivotsL, pL)

pPivotsHCopy = array.copy(pPivotsH)
pPivotsLCopy = array.copy(pPivotsL)
iPivotsHCopy = array.copy(iPivotsH)
iPivotsLCopy = array.copy(iPivotsL)

if barstate.islast
    for j = bar_index to 0
        if array.size(iPivotsHCopy) == 0 or array.size(iPivotsLCopy) == 0
            break

        iLastH := array.pop(iPivotsHCopy)
        iLastL := array.pop(iPivotsLCopy)

        pLastH := array.pop(pPivotsHCopy)
        pLastL := array.pop(pPivotsLCopy)

        iPrevPivot = 0.0
        pPrevPivot = 0.0

        isHighLast := iLastH > iLastL

        if isHighLast
            for i = array.size(iPivotsHCopy)-1 to 0
                if i < 0
                    break
                else if array.get(iPivotsHCopy, i) < iLastL
                    break
                if array.get(pPivotsHCopy, i) > pLastH
                    iLastH := array.pop(iPivotsHCopy)
                    pLastH := array.pop(pPivotsHCopy)
                else
                    array.remove(iPivotsHCopy, i)
                    array.remove(pPivotsHCopy, i)
        else
            for i = array.size(iPivotsLCopy)-1 to 0
                if i < 0
                    break
                else if array.get(iPivotsLCopy, i) < iLastH
                    break
                if array.get(pPivotsLCopy, i) < pLastL
                    iLastL := array.pop(iPivotsLCopy)
                    pLastL := array.pop(pPivotsLCopy)
                else
                    array.remove(iPivotsLCopy, i)
                    array.remove(pPivotsLCopy, i)

        if array.size(iPivotsHCopy) == 0 or array.size(iPivotsLCopy) == 0
            break

        isHighLast := iLastH > iLastL

        if isHighLast
            iPrevPivot := array.get(iPivotsHCopy, array.size(iPivotsHCopy)-1)
            pPrevPivot := array.get(pPivotsHCopy, array.size(iPivotsHCopy)-1)
        else
            iPrevPivot := array.get(iPivotsLCopy, array.size(iPivotsLCopy)-1)
            pPrevPivot := array.get(pPivotsLCopy, array.size(iPivotsLCopy)-1)

        if isHighLast
            startPrice := pPrevPivot
            endPrice := pLastL
            diff := math.abs(startPrice - endPrice)
            if pLastH > endPrice + diff * lowerThreshold or pLastH < endPrice + diff * upperThreshold
                array.push(iPivotsLCopy, iLastL)
                array.push(pPivotsLCopy, pLastL)
                continue
            line.delete(lineLastHL)
            line.delete(lineLastLH)
            line.delete(lineLast)
            lineLastHL := line.new(int(iPrevPivot), pPrevPivot, int(iLastL), pLastL, color=color.red, width=1, style=line.style_dashed)
            lineLastLH := line.new(int(iLastL), pLastL, int(iLastH), pLastH, color=color.green, width=1, style=line.style_dashed)
            lineLast := lineLastLH
        else
            startPrice := pPrevPivot
            endPrice := pLastH
            diff := math.abs(startPrice - endPrice)
            if pLastL < endPrice - diff * lowerThreshold or pLastL > endPrice - diff * upperThreshold
                array.push(iPivotsHCopy, iLastH)
                array.push(pPivotsHCopy, pLastH)
                continue
            line.delete(lineLastHL)
            line.delete(lineLastLH)
            line.delete(lineLast)
            lineLastLH := line.new(int(iPrevPivot), pPrevPivot, int(iLastH), pLastH, color=color.red, width=1, style=line.style_dashed)
            lineLastHL := line.new(int(iLastH), pLastH, int(iLastL), pLastL, color=color.green, width=1, style=line.style_dashed)
            lineLast := lineLastHL
        break

_draw_line(price, col) =>
    var id = line.new(0, price, 0, price, color=col, width=1, extend=extending)
    if not na(lineLast)
        line.set_xy1(id, line.get_x1(lineLast), price)
        line.set_xy2(id, line.get_x2(lineLast), price)

_draw_label(price, txt, txtColor) =>
    if not na(price)
        x = labelsPosition == "Left" ? line.get_x1(lineLast) : not extendRight ? line.get_x2(lineLast) : bar_index
        labelStyle = labelsPosition == "Left" ? label.style_label_right : label.style_label_left
        align = labelsPosition == "Left" ? text.align_right : text.align_left
        labelsAlignStrLeft = txt + '\n ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏ \n'
        labelsAlignStrRight = '       ' + txt + '\n ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏ \n'
        labelsAlignStr = labelsPosition == "Left" ? labelsAlignStrLeft : labelsAlignStrRight
        var id = label.new(x=x, y=price, text=labelsAlignStr, textcolor=txtColor, style=labelStyle, textalign=align, color=#00000000)
        label.set_xy(id, x, price)
        label.set_text(id, labelsAlignStr)
        label.set_textcolor(id, txtColor)

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

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

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

diff := (isHighLast ? -1 : 1) * math.abs(startPrice - endPrice)
offset = isHighLast ? line.get_y1(lineLastLH) - line.get_y2(lineLastLH) : line.get_y1(lineLastHL) - line.get_y2(lineLastHL)
offset := (isHighLast ? -1 : 1) * math.abs(offset)

processLevel(show, value, colorL) =>
    float m = value
    r = (endPrice - offset) + ((reverse ? -1 : 1) * diff * m)
    if show
        _draw_line(r, colorL)
        _draw_label(r, _label_txt(m, r), colorL)
        if _crossing_level(close, r)
            alert("Autofib: " + syminfo.ticker + " crossing level " + str.tostring(value))

show_0 = input(true, "", inline = "Level0")
value_0 = input(0, "", inline = "Level0")
color_0 = input(#787b86, "", inline = "Level0")
processLevel(show_0, value_0, color_0)

show_0_236 = input(true, "", inline = "Level0")
value_0_236 = input(0.236, "", inline = "Level0")
color_0_236 = input(#f44336, "", inline = "Level0")
processLevel(show_0_236, value_0_236, color_0_236)

show_0_382 = input(true, "", inline = "Level1")
value_0_382 = input(0.382, "", inline = "Level1")
color_0_382 = input(#81c784, "", inline = "Level1")
processLevel(show_0_382, value_0_382, color_0_382)

show_0_5 = input(true, "", inline = "Level1")
value_0_5 = input(0.5, "", inline = "Level1")
color_0_5 = input(#4caf50, "", inline = "Level1")
processLevel(show_0_5, value_0_5, color_0_5)

show_0_618 = input(true, "", inline = "Level2")
value_0_618 = input(0.618, "", inline = "Level2")
color_0_618 = input(#009688, "", inline = "Level2")
processLevel(show_0_618, value_0_618, color_0_618)

show_0_65 = input(false, "", inline = "Level2")
value_0_65 = input(0.65, "", inline = "Level2")
color_0_65 = input(#009688, "", inline = "Level2")
processLevel(show_0_65, value_0_65, color_0_65)

show_0_786 = input(true, "", inline = "Level3")
value_0_786 = input(0.786, "", inline = "Level3")
color_0_786 = input(#64b5f6, "", inline = "Level3")
processLevel(show_0_786, value_0_786, color_0_786)

show_1 = input(true, "", inline = "Level3")
value_1 = input(1, "", inline = "Level3")
color_1 = input(#787b86, "", inline = "Level3")
processLevel(show_1, value_1, color_1)

show_1_272 = input(false, "", inline = "Level4")
value_1_272 = input(1.272, "", inline = "Level4")
color_1_272 = input(#81c784, "", inline = "Level4")
processLevel(show_1_272, value_1_272, color_1_272)

show_1_414 = input(false, "", inline = "Level4")
value_1_414 = input(1.414, "", inline = "Level4")
color_1_414 = input(#f44336, "", inline = "Level4")
processLevel(show_1_414, value_1_414, color_1_414)

show_1_618 = input(true, "", inline = "Level5")
value_1_618 = input(1.618, "", inline = "Level5")
color_1_618 = input(#2196f3, "", inline = "Level5")
processLevel(show_1_618, value_1_618, color_1_618)

show_1_65 = input(false, "", inline = "Level5")
value_1_65 = input(1.65, "", inline = "Level5")
color_1_65 = input(#2196f3, "", inline = "Level5")
processLevel(show_1_65, value_1_65, color_1_65)

show_2_618 = input(true, "", inline = "Level6")
value_2_618 = input(2.618, "", inline = "Level6")
color_2_618 = input(#f44336, "", inline = "Level6")
processLevel(show_2_618, value_2_618, color_2_618)

show_2_65 = input(false, "", inline = "Level6")
value_2_65 = input(2.65, "", inline = "Level6")
color_2_65 = input(#f44336, "", inline = "Level6")
processLevel(show_2_65, value_2_65, color_2_65)

show_3_618 = input(true, "", inline = "Level7")
value_3_618 = input(3.618, "", inline = "Level7")
color_3_618 = input(#9c27b0, "", inline = "Level7")
processLevel(show_3_618, value_3_618, color_3_618)

show_3_65 = input(false, "", inline = "Level7")
value_3_65 = input(3.65, "", inline = "Level7")
color_3_65 = input(#9c27b0, "", inline = "Level7")
processLevel(show_3_65, value_3_65, color_3_65)

show_4_236 = input(true, "", inline = "Level8")
value_4_236 = input(4.236, "", inline = "Level8")
color_4_236 = input(#e91e63, "", inline = "Level8")
processLevel(show_4_236, value_4_236, color_4_236)

show_4_618 = input(false, "", inline = "Level8")
value_4_618 = input(4.618, "", inline = "Level8")
color_4_618 = input(#81c784, "", inline = "Level8")
processLevel(show_4_618, value_4_618, color_4_618)

show_neg_0_236 = input(false, "", inline = "Level9")
value_neg_0_236 = input(-0.236, "", inline = "Level9")
color_neg_0_236 = input(#f44336, "", inline = "Level9")
processLevel(show_neg_0_236, value_neg_0_236, color_neg_0_236)

show_neg_0_382 = input(false, "", inline = "Level9")
value_neg_0_382 = input(-0.382, "", inline = "Level9")
color_neg_0_382 = input(#81c784, "", inline = "Level9")
processLevel(show_neg_0_382, value_neg_0_382, color_neg_0_382)

show_neg_0_618 = input(false, "", inline = "Level10")
value_neg_0_618 = input(-0.618, "", inline = "Level10")
color_neg_0_618 = input(#009688, "", inline = "Level10")
processLevel(show_neg_0_618, value_neg_0_618, color_neg_0_618)

show_neg_0_65 = input(false, "", inline = "Level10")
value_neg_0_65 = input(-0.65, "", inline = "Level10")
color_neg_0_65 = input(#009688, "", inline = "Level10")
processLevel(show_neg_0_65, value_neg_0_65, color_neg_0_65)

Fib Extension yerine Fib Retracement kullanmak isterseniz yukarıdaki kod yerine aşağıdakini kullanabilirsiniz.

Ichimoku Cloud, Auto Fib Retracement ve HO
// © ohantekten
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © orhantekten.com/kategori/indikator
// Bu dökümanda Ichimoku bulutu, auto fib extension ve 9 adet hareketli ortalama vardır. 
// @version=5
//ich
indicator(title='ichimoku+oto fib', shorttitle='ich+fib', overlay=true)
conversionPeriods = input.int(9, minval=1, title="ICH Conversion Line Length")
basePeriods = input.int(26, minval=1, title="ICH Base Line Length")
laggingSpan2Periods = input.int(52, minval=1, title="ICH Leading Span B Length")
displacement = input.int(26, minval=1, title="ICH Displacement")
donchian(len) => math.avg(ta.lowest(len), ta.highest(len))
conversionLine = donchian(conversionPeriods)
baseLine = donchian(basePeriods)
leadLine1 = math.avg(conversionLine, baseLine)
leadLine2 = donchian(laggingSpan2Periods)
plot(conversionLine, color=#2962FF, title="ICH Dönüş Çizgisi")
plot(baseLine, color=#B71C1C, title="ICH Temel Çizgi")
plot(close, offset = -displacement + 1, color=#43A047, title="ICH Gecikme Aralığı")
p1 = plot(leadLine1, offset = displacement - 1, color=#A5D6A7,
	 title="ICH Leading Span A")
p2 = plot(leadLine2, offset = displacement - 1, color=#EF9A9A,
	 title="ICH Leading Span B")
fill(p1, p2, color = leadLine1 > leadLine2 ? color.rgb(67, 160, 71, 90) : color.rgb(244, 67, 54, 90))


//HO
src = input(title='Source', defval=close)

length1 = input(5, 'MA 1')
plot(ta.sma(src, length1), color=color.new(color.red, 0), linewidth=1, title='MA 1')

length2 = input(10, 'MA 2')
plot(ta.sma(src, length2), color=color.new(color.blue, 0), linewidth=2, title='MA 2')

length3 = input(20, 'MA 3')
plot(ta.sma(src, length3), color=color.new(color.orange, 0), linewidth=3, title='MA 3')

length4 = input(50, 'MA 4')
plot(ta.sma(src, length4), color=color.new(color.black, 0), linewidth=2, title='MA 4')

length5 = input(8, 'EMA 1')
plot(ta.ema(src, length5), color=color.new(color.white, 0), linewidth=2, title='EMA 1')

length6 = input(13, 'EMA 2')
plot(ta.ema(src, length6), color=color.new(color.yellow, 0), linewidth=2, title='EMA 2')

length7 = input(21, 'EMA 3')
plot(ta.ema(src, length7), color=color.new(color.red, 0), linewidth=2, title='EMA 3')

length8 = input(30, 'EMA 4')
plot(ta.ema(src, length8), color=color.new(color.blue, 0), linewidth=2, title='EMA 4')

length9 = input(50, 'EMA 5')
plot(ta.ema(src, length9), color=color.new(color.blue, 0), linewidth=2, title='EMA 5')

//fib 
//indicator("Auto Fib Retracement", overlay=true)
devTooltip = "Deviation is a multiplier that affects how much the price should deviate from the previous pivot in order for the bar to become a new pivot."
depthTooltip = "The minimum number of bars that will be taken into account when calculating the indicator."
// pivots threshold
threshold_multiplier = input.float(title="Deviation", defval=3, minval=0, tooltip=devTooltip)
dev_threshold = ta.atr(10) / close * 100 * threshold_multiplier
depth = input.int(title="Depth", defval=10, minval=1, tooltip=depthTooltip)
reverse = input(false, "Reverse")
var extendLeft = input(false, "Extend Left    |    Extend Right", inline = "Extend Lines")
var extendRight = input(true, "", inline = "Extend Lines")
var extending = extend.none
if extendLeft and extendRight
    extending := extend.both
if extendLeft and not extendRight
    extending := extend.left
if not extendLeft and extendRight
    extending := extend.right
prices = input(true, "Show Prices")
levels = input(true, "Show Levels", inline = "Levels")
levelsFormat = input.string("Values", "", options = ["Values", "Percent"], inline = "Levels")
labelsPosition = input.string("Left", "Labels Position", options = ["Left", "Right"])

var line lineLast = na
var int iLast = 0
var int iPrev = 0
var float pLast = 0
var isHighLast = false // otherwise the last pivot is a low pivot

pivots(src, length, isHigh) =>
    l2 = length * 2
    c = nz(src[length])
    ok = true
    for i = 0 to l2
        if isHigh and src[i] > c
            ok := false

        if not isHigh and src[i] < c
            ok := false
    if ok
        [bar_index[length], c]
    else
        [int(na), float(na)]
[iH, pH] = pivots(high, depth / 2, true)
[iL, pL] = pivots(low, depth / 2, false)

calc_dev(base_price, price) =>
    100 * (price - base_price) / price

pivotFound(dev, isHigh, index, price) =>
    if isHighLast == isHigh and not na(lineLast)
        // same direction
        if isHighLast ? price > pLast : price < pLast
            line.set_xy2(lineLast, index, price)
            [lineLast, isHighLast]
        else
            [line(na), bool(na)]
    else // reverse the direction (or create the very first line)
        if math.abs(dev) > dev_threshold
            // price move is significant
            id = line.new(iLast, pLast, index, price, color=color.gray, width=1, style=line.style_dashed)
            [id, isHigh]
        else
            [line(na), bool(na)]

if not na(iH)
    dev = calc_dev(pLast, pH)
    [id, isHigh] = pivotFound(dev, true, iH, pH)
    if not na(id)
        if id != lineLast
            line.delete(lineLast)
        lineLast := id
        isHighLast := isHigh
        iPrev := iLast
        iLast := iH
        pLast := pH
else
    if not na(iL)
        dev = calc_dev(pLast, pL)
        [id, isHigh] = pivotFound(dev, false, iL, pL)
        if not na(id)
            if id != lineLast
                line.delete(lineLast)
            lineLast := id
            isHighLast := isHigh
            iPrev := iLast
            iLast := iL
            pLast := pL

_draw_line(price, col) =>
    var id = line.new(iLast, price, bar_index, price, color=col, width=1, extend=extending)
    if not na(lineLast)
        line.set_xy1(id, line.get_x1(lineLast), price)
        line.set_xy2(id, line.get_x2(lineLast), price)


_draw_label(price, txt, txtColor) =>
    x = labelsPosition == "Left" ? line.get_x1(lineLast) : not extendRight ? line.get_x2(lineLast) : bar_index
    labelStyle = labelsPosition == "Left" ? label.style_label_right : label.style_label_left
    align = labelsPosition == "Left" ? text.align_right : text.align_left
    labelsAlignStrLeft = txt + '\n ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏ \n'
    labelsAlignStrRight = '       ' + txt + '\n ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏  ‏ \n'
    labelsAlignStr = labelsPosition == "Left" ? labelsAlignStrLeft : labelsAlignStrRight
    var id = label.new(x=x, y=price, text=labelsAlignStr, textcolor=txtColor, style=labelStyle, textalign=align, color=#00000000)
    label.set_xy(id, x, price)
    label.set_text(id, labelsAlignStr)
    label.set_textcolor(id, txtColor)

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

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

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

startPrice = reverse ? line.get_y1(lineLast) : pLast
endPrice = reverse ? pLast : line.get_y1(lineLast)

iHL = startPrice > endPrice
diff = (iHL ? -1 : 1) * math.abs(startPrice - endPrice)

processLevel(show, value, colorL) =>
    float m = value
    r = startPrice + diff * m
    if show
        _draw_line(r, colorL)
        _draw_label(r, _label_txt(m, r), colorL)
        if _crossing_level(close, r)
            alert("Autofib: " + syminfo.ticker + " crossing level " + str.tostring(value))

show_0 = input(true, "", inline = "Level0")
value_0 = input(0, "", inline = "Level0")
color_0 = input(#787b86, "", inline = "Level0")
processLevel(show_0, value_0, color_0)

show_0_236 = input(true, "", inline = "Level0")
value_0_236 = input(0.236, "", inline = "Level0")
color_0_236 = input(#f44336, "", inline = "Level0")
processLevel(show_0_236, value_0_236, color_0_236)

show_0_382 = input(true, "", inline = "Level1")
value_0_382 = input(0.382, "", inline = "Level1")
color_0_382 = input(#81c784, "", inline = "Level1")
processLevel(show_0_382, value_0_382, color_0_382)

show_0_5 = input(true, "", inline = "Level1")
value_0_5 = input(0.5, "", inline = "Level1")
color_0_5 = input(#4caf50, "", inline = "Level1")
processLevel(show_0_5, value_0_5, color_0_5)

show_0_618 = input(true, "", inline = "Level2")
value_0_618 = input(0.618, "", inline = "Level2")
color_0_618 = input(#009688, "", inline = "Level2")
processLevel(show_0_618, value_0_618, color_0_618)

show_0_65 = input(false, "", inline = "Level2")
value_0_65 = input(0.65, "", inline = "Level2")
color_0_65 = input(#009688, "", inline = "Level2")
processLevel(show_0_65, value_0_65, color_0_65)

show_0_786 = input(true, "", inline = "Level3")
value_0_786 = input(0.786, "", inline = "Level3")
color_0_786 = input(#64b5f6, "", inline = "Level3")
processLevel(show_0_786, value_0_786, color_0_786)

show_1 = input(true, "", inline = "Level3")
value_1 = input(1, "", inline = "Level3")
color_1 = input(#787b86, "", inline = "Level3")
processLevel(show_1, value_1, color_1)

show_1_272 = input(false, "", inline = "Level4")
value_1_272 = input(1.272, "", inline = "Level4")
color_1_272 = input(#81c784, "", inline = "Level4")
processLevel(show_1_272, value_1_272, color_1_272)

show_1_414 = input(false, "", inline = "Level4")
value_1_414 = input(1.414, "", inline = "Level4")
color_1_414 = input(#f44336, "", inline = "Level4")
processLevel(show_1_414, value_1_414, color_1_414)

show_1_618 = input(true, "", inline = "Level5")
value_1_618 = input(1.618, "", inline = "Level5")
color_1_618 = input(#2196f3, "", inline = "Level5")
processLevel(show_1_618, value_1_618, color_1_618)

show_1_65 = input(false, "", inline = "Level5")
value_1_65 = input(1.65, "", inline = "Level5")
color_1_65 = input(#2196f3, "", inline = "Level5")
processLevel(show_1_65, value_1_65, color_1_65)

show_2_618 = input(true, "", inline = "Level6")
value_2_618 = input(2.618, "", inline = "Level6")
color_2_618 = input(#f44336, "", inline = "Level6")
processLevel(show_2_618, value_2_618, color_2_618)

show_2_65 = input(false, "", inline = "Level6")
value_2_65 = input(2.65, "", inline = "Level6")
color_2_65 = input(#f44336, "", inline = "Level6")
processLevel(show_2_65, value_2_65, color_2_65)

show_3_618 = input(true, "", inline = "Level7")
value_3_618 = input(3.618, "", inline = "Level7")
color_3_618 = input(#9c27b0, "", inline = "Level7")
processLevel(show_3_618, value_3_618, color_3_618)

show_3_65 = input(false, "", inline = "Level7")
value_3_65 = input(3.65, "", inline = "Level7")
color_3_65 = input(#9c27b0, "", inline = "Level7")
processLevel(show_3_65, value_3_65, color_3_65)

show_4_236 = input(true, "", inline = "Level8")
value_4_236 = input(4.236, "", inline = "Level8")
color_4_236 = input(#e91e63, "", inline = "Level8")
processLevel(show_4_236, value_4_236, color_4_236)

show_4_618 = input(false, "", inline = "Level8")
value_4_618 = input(4.618, "", inline = "Level8")
color_4_618 = input(#81c784, "", inline = "Level8")
processLevel(show_4_618, value_4_618, color_4_618)

show_neg_0_236 = input(false, "", inline = "Level9")
value_neg_0_236 = input(-0.236, "", inline = "Level9")
color_neg_0_236 = input(#f44336, "", inline = "Level9")
processLevel(show_neg_0_236, value_neg_0_236, color_neg_0_236)

show_neg_0_382 = input(false, "", inline = "Level9")
value_neg_0_382 = input(-0.382, "", inline = "Level9")
color_neg_0_382 = input(#81c784, "", inline = "Level9")
processLevel(show_neg_0_382, value_neg_0_382, color_neg_0_382)

show_neg_0_618 = input(false, "", inline = "Level10")
value_neg_0_618 = input(-0.618, "", inline = "Level10")
color_neg_0_618 = input(#009688, "", inline = "Level10")
processLevel(show_neg_0_618, value_neg_0_618, color_neg_0_618)

show_neg_0_65 = input(false, "", inline = "Level10")
value_neg_0_65 = input(-0.65, "", inline = "Level10")
color_neg_0_65 = input(#009688, "", inline = "Level10")
processLevel(show_neg_0_65, value_neg_0_65, color_neg_0_65)
Kategori:Console.WriteLineİndikatör

Bu yazı yorumlara kapalı.