Auto Fib (Fibonacci) Levels Indicator for ThinkorSwim

Hi all. Asking for help in placing Labels at the end of the Fib retracements. I got the code online, but was only able to place 0% and 100% chart bubbles. If anyone can assist with inserting the 23.6%, 38.2%,50%, 61.8% and the 78.6% I'll really appreciate it. Thanks.

Code:
#########################
# autofib - show fib-retracements between chart high/low

input sideline = no;


def f11 = 0.236;
def f12 = 0.382;
def f13 = 0.50;
def f14 = 0.618;
def f15 = 0.786;
def hh = HighestAll(high);
def ll = LowestAll(low);
plot H =
  if IsNaN(close) && sideline then
    hh
  else if !IsNaN(close) && !sideline then
    hh
  else
    Double.NaN
;
plot L =
  if IsNaN(close) && sideline then
    ll 
  else if !IsNaN(close) && !sideline then
    ll
  else
    Double.NaN
;



plot P236 =
  if IsNaN(close) && sideline then
    hh - ((hh - ll) * f11)
  else if !IsNaN(close) && !sideline then
    hh - ((hh - ll) * f11)
  else
    Double.NaN;


plot P382 =
  if IsNaN(close) && sideline then
    hh - ((hh - ll) * f12)
  else if !IsNaN(close) && !sideline then
    hh - ((hh - ll) * f12)
  else
    Double.NaN
;
plot P50 =
  if IsNaN(close) && sideline then
    hh - ((hh - ll) * f13)
  else if !IsNaN(close) && !sideline then
    hh - ((hh - ll) * f13)
  else
    Double.NaN
;
plot P618 =
  if IsNaN(close) && sideline then
    hh - ((hh - ll) * f14)
  else if !IsNaN(close) && !sideline then
    hh - ((hh - ll) * f14)
  else
    Double.NaN
;
plot P781 =
  if IsNaN(close) && sideline then
    hh - ((hh - ll) * f15)
  else if !IsNaN(close) && !sideline then
    hh - ((hh - ll) * f15)
  else
    Double.NaN
;
P236.SetDefaultColor(Color.LIGHT_GRAY);
P382.SetDefaultColor(Color.LIGHT_GRAY);
P50.SetDefaultColor(Color.ORANGE);
P618.SetDefaultColor(Color.LIGHT_GRAY);
P781.SetDefaultColor(Color.LIGHT_GRAY);
H.SetDefaultColor(Color.MAGENTA);
L.SetDefaultColor(Color.MAGENTA);
P236.SetStyle(Curve.LONG_DASH);
P382.SetStyle(Curve.LONG_DASH);
P50.SetStyle(Curve.LONG_DASH);
P618.SetStyle(Curve.LONG_DASH);
P781.SetStyle(Curve.LONG_DASH);
H.SetStyle(Curve.SHORT_DASH);
L.SetStyle(Curve.SHORT_DASH);
H.SetLineWeight(2);
L.SetLineWeight(2);
P50.SetLineWeight(2);
###############################################
input showchart_bubbles = yes;
input bubblemover       = 5; #used to move the bubble left and right
def n   = bubblemover;
def n1  = n + 1;


AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), hh[n], " 100%", Color.YELLOW, yes);

AddChartBubble(showchart_bubbles and !IsNaN(close[n1]) and IsNaN(close[n]), ll[n], " 0%", Color.YELLOW, yes);
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Can anyone convert this tradingview script of Auto Fibonacci Retracement?. It is has proved to be very useful. Searching similar to this one on thinkorswim but had no luck. If anyone can convert will be helpful.

Code:
//@version=4
study("Auto Fib Retracement", overlay=true)

// pivots threshold
threshold_multiplier = input(title="Deviation", type=input.float, defval=3, minval=0)
dev_threshold = atr(10) / close * 100 * threshold_multiplier

depth = input(title="Depth", type=input.integer, defval=10, minval=1)
var extendLeft = input(false, "Extend Lines Left")
var extendRight = input(true, "Extend Lines Right")

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

reverse = input(false, "Reverse")
prices = input(true, "Prices")
levels = input(true, "Levels")
levelsFormat = input("Values", "Levels Format", options = ["Values", "Percent"])
labelsPosition = input("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 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) =>
    "(" + tostring(txt, "#.##") + ")"

_label_txt(level, price) =>
    l = levelsFormat == "Values" ? tostring(level) : 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) * abs(startPrice - endPrice)

level_0 = input(true, "0")
color_0 = input(#787b86, "0 Level Color")
float m = 0
r = startPrice + diff * m
if level_0
    _draw_line(r, color_0)
    _draw_label(r, _label_txt(m, r), color_0)
alertcondition(_crossing_level(close, r), "Autofib 0 crossing!", "Autofib: {{ticker}} crossing level 0.")

level_0236 = input(true, "0.236")
color_0236 = input(#f44336, "0.236 Level Color")
m := 0.236
r := startPrice + diff * m
if level_0236
    _draw_line(r, color_0236)
    _draw_label(r, _label_txt(m, r), color_0236)
alertcondition(_crossing_level(close, r), "Autofib 0.236 crossing!", "Autofib: {{ticker}} crossing level 0.236.")

level_0382 = input(true, "0.382")
color_0382 = input(#81c784, "0.382 Level Color")
m := 0.382
r := startPrice + diff * m
if level_0382
    _draw_line(r, color_0382)
    _draw_label(r, _label_txt(m, r), color_0382)
alertcondition(_crossing_level(close, r), "Autofib 0.382 crossing!", "Autofib: {{ticker}} crossing level 0.382.")

level_05 = input(true, "0.5")
color_05 = input(#4caf50, "0.5 Level Color")
m := 0.5
r := startPrice + diff * m
if level_05
    _draw_line(r, color_05)
    _draw_label(r, _label_txt(m, r), color_05)
alertcondition(_crossing_level(close, r), "Autofib 0.5 crossing!", "Autofib: {{ticker}} crossing level 0.5.")

level_0618 = input(true, "0.618")
color_0618 = input(#009688, "0.618 Level Color")
m := 0.618
r := startPrice + diff * m
if level_0618
    _draw_line(r, color_0618)
    _draw_label(r, _label_txt(m, r), color_0618)
alertcondition(_crossing_level(close, r), "Autofib 0.618 crossing!", "Autofib: {{ticker}} crossing level 0.618.")

level_065 = input(false, "0.65")
color_065 = input(#009688, "0.65 Level Color")
m := 0.65
r := startPrice + diff * m
if level_065
    _draw_line(r, color_065)
    _draw_label(r, _label_txt(m, r), color_065)
alertcondition(_crossing_level(close, r), "Autofib 0.65 crossing!", "Autofib: {{ticker}} crossing level 0.65.")

level_0786 = input(true, "0.786")
color_0786 = input(#64b5f6, "0.786 Level Color")
m := 0.786
r := startPrice + diff * m
if level_0786
    _draw_line(r, color_0786)
    _draw_label(r, _label_txt(m, r), color_0786)
alertcondition(_crossing_level(close, r), "Autofib 0.786 crossing!", "Autofib: {{ticker}} crossing level 0.786.")

level_1 = input(true, "1")
color_1 = input(#787b86, "1 Level Color")
m := 1
r := startPrice + diff * m
if level_1
    _draw_line(r, color_1)
    _draw_label(r, _label_txt(m, r), color_1)
alertcondition(_crossing_level(close, r), "Autofib 1 crossing!", "Autofib: {{ticker}} crossing level 1.")

level_1272 = input(true, "1.272")
color_1272 = input(#81c784, "1.272 Level Color")
m := 1.272
r := startPrice + diff * m
if level_1272
    _draw_line(r, color_1272)
    _draw_label(r, _label_txt(m, r), color_1272)
alertcondition(_crossing_level(close, r), "Autofib 1.272 crossing!", "Autofib: {{ticker}} crossing level 1.272.")

level_1414 = input(true, "1.414")
color_1414 = input(#f44336, "1.414 Level Color")
m := 1.414
r := startPrice + diff * m
if level_1414
    _draw_line(r, color_1414)
    _draw_label(r, _label_txt(m, r), color_1414)
alertcondition(_crossing_level(close, r), "Autofib 1.414 crossing!", "Autofib: {{ticker}} crossing level 1.414.")

level_1618 = input(true, "1.618")
color_1618 = input(#2196f3, "1.618 Level Color")
m := 1.618
r := startPrice + diff * m
if level_1618
    _draw_line(r, color_1618)
    _draw_label(r, _label_txt(m, r), color_1618)
alertcondition(_crossing_level(close, r), "Autofib 1.618 crossing!", "Autofib: {{ticker}} crossing level 1.618.")

level_165 = input(false, "1.65")
color_165 = input(#2196f3, "1.65 Level Color")
m := 1.65
r := startPrice + diff * m
if level_165
    _draw_line(r, color_165)
    _draw_label(r, _label_txt(m, r), color_165)
alertcondition(_crossing_level(close, r), "Autofib 1.65 crossing!", "Autofib: {{ticker}} crossing level 1.65.")

level_2618 = input(false, "2.618")
color_2618 = input(#f44336, "2.618 Level Color")
m := 2.618
r := startPrice + diff * m
if level_2618
    _draw_line(r, color_2618)
    _draw_label(r, _label_txt(m, r), color_2618)
alertcondition(_crossing_level(close, r), "Autofib 2.618 crossing!", "Autofib: {{ticker}} crossing level 2.618.")

level_265 = input(false, "2.65")
color_265 = input(#f44336, "2.65 Level Color")
m := 2.65
r := startPrice + diff * m
if level_265
    _draw_line(r, color_265)
    _draw_label(r, _label_txt(m, r), color_265)
alertcondition(_crossing_level(close, r), "Autofib 2.65 crossing!", "Autofib: {{ticker}} crossing level 2.65.")

level_3618 = input(false, "3.618")
color_3618 = input(#9c27b0, "3.618 Level Color")
m := 3.618
r := startPrice + diff * m
if level_3618
    _draw_line(r, color_3618)
    _draw_label(r, _label_txt(m, r), color_3618)
alertcondition(_crossing_level(close, r), "Autofib 3.618 crossing!", "Autofib: {{ticker}} crossing level 3.618.")

level_365 = input(false, "3.65")
color_365 = input(#9c27b0, "3.65 Level Color")
m := 3.65
r := startPrice + diff * m
if level_365
    _draw_line(r, color_365)
    _draw_label(r, _label_txt(m, r), color_365)
alertcondition(_crossing_level(close, r), "Autofib 3.65 crossing!", "Autofib: {{ticker}} crossing level 3.65.")

level_4236 = input(false, "4.236")
color_4236 = input(#e91e63, "4.236 Level Color")
m := 4.236
r := startPrice + diff * m
if level_4236
    _draw_line(r, color_4236)
    _draw_label(r, _label_txt(m, r), color_4236)
alertcondition(_crossing_level(close, r), "Autofib 4.236 crossing!", "Autofib: {{ticker}} crossing level 4.236.")

level_n0236 = input(false, "-0.236")
color_n0236 = input(#f44336, "-0.236 Level Color")
m := -0.236
r := startPrice + diff * m
if level_n0236
    _draw_line(r, color_n0236)
    _draw_label(r, _label_txt(m, r), color_n0236)
alertcondition(_crossing_level(close, r), "Autofib -0.236 crossing!", "Autofib: {{ticker}} crossing level -0.236.")

level_n0382 = input(false, "-0.382")
color_n0382 = input(#81c784, "-0.382 Level Color")
m := -0.382
r := startPrice + diff * m
if level_n0382
    _draw_line(r, color_n0382)
    _draw_label(r, _label_txt(m, r), color_n0382)
alertcondition(_crossing_level(close, r), "Autofib -0.382 crossing!", "Autofib: {{ticker}} crossing level -0.382.")

level_n0618 = input(false, "-0.618")
color_n0618 = input(#009688, "-0.618 Level Color")
m := -0.618
r := startPrice + diff * m
if level_n0618
    _draw_line(r, color_n0618)
    _draw_label(r, _label_txt(m, r), color_n0618)
alertcondition(_crossing_level(close, r), "Autofib -0.618 crossing!", "Autofib: {{ticker}} crossing level -0.618.")

level_n065 = input(false, "-0.65")
color_n065 = input(#009688, "-0.65 Level Color")
m := -0.65
r := startPrice + diff * m
if level_n065
    _draw_line(r, color_n065)
    _draw_label(r, _label_txt(m, r), color_n065)
alertcondition(_crossing_level(close, r), "Autofib -0.65 crossing!", "Autofib: {{ticker}} crossing level -0.65.")[/i][/i]
 
Can anyone convert this tradingview script of Auto Fibonacci Retracement?. It is has proved to be very useful. Searching similar to this one on thinkorswim but had no luck. If anyone can convert will be helpful.

Code:
//@version=4
study("Auto Fib Retracement", overlay=true)

// pivots threshold
threshold_multiplier = input(title="Deviation", type=input.float, defval=3, minval=0)
dev_threshold = atr(10) / close * 100 * threshold_multiplier

depth = input(title="Depth", type=input.integer, defval=10, minval=1)
var extendLeft = input(false, "Extend Lines Left")
var extendRight = input(true, "Extend Lines Right")

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

reverse = input(false, "Reverse")
prices = input(true, "Prices")
levels = input(true, "Levels")
levelsFormat = input("Values", "Levels Format", options = ["Values", "Percent"])
labelsPosition = input("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 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) =>
    "(" + tostring(txt, "#.##") + ")"

_label_txt(level, price) =>
    l = levelsFormat == "Values" ? tostring(level) : 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) * abs(startPrice - endPrice)

level_0 = input(true, "0")
color_0 = input(#787b86, "0 Level Color")
float m = 0
r = startPrice + diff * m
if level_0
    _draw_line(r, color_0)
    _draw_label(r, _label_txt(m, r), color_0)
alertcondition(_crossing_level(close, r), "Autofib 0 crossing!", "Autofib: {{ticker}} crossing level 0.")

level_0236 = input(true, "0.236")
color_0236 = input(#f44336, "0.236 Level Color")
m := 0.236
r := startPrice + diff * m
if level_0236
    _draw_line(r, color_0236)
    _draw_label(r, _label_txt(m, r), color_0236)
alertcondition(_crossing_level(close, r), "Autofib 0.236 crossing!", "Autofib: {{ticker}} crossing level 0.236.")

level_0382 = input(true, "0.382")
color_0382 = input(#81c784, "0.382 Level Color")
m := 0.382
r := startPrice + diff * m
if level_0382
    _draw_line(r, color_0382)
    _draw_label(r, _label_txt(m, r), color_0382)
alertcondition(_crossing_level(close, r), "Autofib 0.382 crossing!", "Autofib: {{ticker}} crossing level 0.382.")

level_05 = input(true, "0.5")
color_05 = input(#4caf50, "0.5 Level Color")
m := 0.5
r := startPrice + diff * m
if level_05
    _draw_line(r, color_05)
    _draw_label(r, _label_txt(m, r), color_05)
alertcondition(_crossing_level(close, r), "Autofib 0.5 crossing!", "Autofib: {{ticker}} crossing level 0.5.")

level_0618 = input(true, "0.618")
color_0618 = input(#009688, "0.618 Level Color")
m := 0.618
r := startPrice + diff * m
if level_0618
    _draw_line(r, color_0618)
    _draw_label(r, _label_txt(m, r), color_0618)
alertcondition(_crossing_level(close, r), "Autofib 0.618 crossing!", "Autofib: {{ticker}} crossing level 0.618.")

level_065 = input(false, "0.65")
color_065 = input(#009688, "0.65 Level Color")
m := 0.65
r := startPrice + diff * m
if level_065
    _draw_line(r, color_065)
    _draw_label(r, _label_txt(m, r), color_065)
alertcondition(_crossing_level(close, r), "Autofib 0.65 crossing!", "Autofib: {{ticker}} crossing level 0.65.")

level_0786 = input(true, "0.786")
color_0786 = input(#64b5f6, "0.786 Level Color")
m := 0.786
r := startPrice + diff * m
if level_0786
    _draw_line(r, color_0786)
    _draw_label(r, _label_txt(m, r), color_0786)
alertcondition(_crossing_level(close, r), "Autofib 0.786 crossing!", "Autofib: {{ticker}} crossing level 0.786.")

level_1 = input(true, "1")
color_1 = input(#787b86, "1 Level Color")
m := 1
r := startPrice + diff * m
if level_1
    _draw_line(r, color_1)
    _draw_label(r, _label_txt(m, r), color_1)
alertcondition(_crossing_level(close, r), "Autofib 1 crossing!", "Autofib: {{ticker}} crossing level 1.")

level_1272 = input(true, "1.272")
color_1272 = input(#81c784, "1.272 Level Color")
m := 1.272
r := startPrice + diff * m
if level_1272
    _draw_line(r, color_1272)
    _draw_label(r, _label_txt(m, r), color_1272)
alertcondition(_crossing_level(close, r), "Autofib 1.272 crossing!", "Autofib: {{ticker}} crossing level 1.272.")

level_1414 = input(true, "1.414")
color_1414 = input(#f44336, "1.414 Level Color")
m := 1.414
r := startPrice + diff * m
if level_1414
    _draw_line(r, color_1414)
    _draw_label(r, _label_txt(m, r), color_1414)
alertcondition(_crossing_level(close, r), "Autofib 1.414 crossing!", "Autofib: {{ticker}} crossing level 1.414.")

level_1618 = input(true, "1.618")
color_1618 = input(#2196f3, "1.618 Level Color")
m := 1.618
r := startPrice + diff * m
if level_1618
    _draw_line(r, color_1618)
    _draw_label(r, _label_txt(m, r), color_1618)
alertcondition(_crossing_level(close, r), "Autofib 1.618 crossing!", "Autofib: {{ticker}} crossing level 1.618.")

level_165 = input(false, "1.65")
color_165 = input(#2196f3, "1.65 Level Color")
m := 1.65
r := startPrice + diff * m
if level_165
    _draw_line(r, color_165)
    _draw_label(r, _label_txt(m, r), color_165)
alertcondition(_crossing_level(close, r), "Autofib 1.65 crossing!", "Autofib: {{ticker}} crossing level 1.65.")

level_2618 = input(false, "2.618")
color_2618 = input(#f44336, "2.618 Level Color")
m := 2.618
r := startPrice + diff * m
if level_2618
    _draw_line(r, color_2618)
    _draw_label(r, _label_txt(m, r), color_2618)
alertcondition(_crossing_level(close, r), "Autofib 2.618 crossing!", "Autofib: {{ticker}} crossing level 2.618.")

level_265 = input(false, "2.65")
color_265 = input(#f44336, "2.65 Level Color")
m := 2.65
r := startPrice + diff * m
if level_265
    _draw_line(r, color_265)
    _draw_label(r, _label_txt(m, r), color_265)
alertcondition(_crossing_level(close, r), "Autofib 2.65 crossing!", "Autofib: {{ticker}} crossing level 2.65.")

level_3618 = input(false, "3.618")
color_3618 = input(#9c27b0, "3.618 Level Color")
m := 3.618
r := startPrice + diff * m
if level_3618
    _draw_line(r, color_3618)
    _draw_label(r, _label_txt(m, r), color_3618)
alertcondition(_crossing_level(close, r), "Autofib 3.618 crossing!", "Autofib: {{ticker}} crossing level 3.618.")

level_365 = input(false, "3.65")
color_365 = input(#9c27b0, "3.65 Level Color")
m := 3.65
r := startPrice + diff * m
if level_365
    _draw_line(r, color_365)
    _draw_label(r, _label_txt(m, r), color_365)
alertcondition(_crossing_level(close, r), "Autofib 3.65 crossing!", "Autofib: {{ticker}} crossing level 3.65.")

level_4236 = input(false, "4.236")
color_4236 = input(#e91e63, "4.236 Level Color")
m := 4.236
r := startPrice + diff * m
if level_4236
    _draw_line(r, color_4236)
    _draw_label(r, _label_txt(m, r), color_4236)
alertcondition(_crossing_level(close, r), "Autofib 4.236 crossing!", "Autofib: {{ticker}} crossing level 4.236.")

level_n0236 = input(false, "-0.236")
color_n0236 = input(#f44336, "-0.236 Level Color")
m := -0.236
r := startPrice + diff * m
if level_n0236
    _draw_line(r, color_n0236)
    _draw_label(r, _label_txt(m, r), color_n0236)
alertcondition(_crossing_level(close, r), "Autofib -0.236 crossing!", "Autofib: {{ticker}} crossing level -0.236.")

level_n0382 = input(false, "-0.382")
color_n0382 = input(#81c784, "-0.382 Level Color")
m := -0.382
r := startPrice + diff * m
if level_n0382
    _draw_line(r, color_n0382)
    _draw_label(r, _label_txt(m, r), color_n0382)
alertcondition(_crossing_level(close, r), "Autofib -0.382 crossing!", "Autofib: {{ticker}} crossing level -0.382.")

level_n0618 = input(false, "-0.618")
color_n0618 = input(#009688, "-0.618 Level Color")
m := -0.618
r := startPrice + diff * m
if level_n0618
    _draw_line(r, color_n0618)
    _draw_label(r, _label_txt(m, r), color_n0618)
alertcondition(_crossing_level(close, r), "Autofib -0.618 crossing!", "Autofib: {{ticker}} crossing level -0.618.")

level_n065 = input(false, "-0.65")
color_n065 = input(#009688, "-0.65 Level Color")
m := -0.65
r := startPrice + diff * m
if level_n065
    _draw_line(r, color_n065)
    _draw_label(r, _label_txt(m, r), color_n065)
alertcondition(_crossing_level(close, r), "Autofib -0.65 crossing!", "Autofib: {{ticker}} crossing level -0.65.")[/i][/i]
what are you trying to convert it to?
 
Excellent modifications by @theelderwand on the auto fib study. I made one more enhancement to his version, by introducing an input selector for the colors of the label. You can select from any of the colors listed - red, orange, green, etc and bubbles for all the fib retracements will utilize that color.

Code:
#hint Price: Price used in the alerts on crossing retracement lines. <b>(Default is Close)</b>

#hint coefficient_0: Retracement Line 0: Retracement from the highest high to the lowest low.<b>(Default is 0%)</b>
#hint Coefficient_1: Retracement Line 1: Retracement from the highest high to the lowest low.<b>(Default is 23.6%)</b>
#hint Coefficient_2: Retracement Line 2: Retracement from the highest high to the lowest low.<b>(Default is 38.2%)</b>
#hint Coefficient_3: Retracement Line 3: Retracement from the highest high to the lowest low.<b>(Default is 50%)</b>
#hint Coefficient_4: Retracement Line 4: Retracement from the highest high to the lowest low.<b>(Default is 61.8%)</b>
#hint Coefficient_5: Retracement Line 5: Retracement from the highest high to the lowest low.<b>(Default is 78.6%)</b>
#hint Coefficient_6: Retracement Line 6: Retracement from the highest high to the lowest low.<b>(Default is 100%)</b>

#wizard input: Price
#wizard text: Inputs: Price:
#wizard input: coefficient_0
#wizard text: coefficient_0:
#wizard input: Coefficient_1
#wizard text: Coefficient_1:
#wizard input: Coefficient_2
#wizard text: Coefficient_2:
#wizard input: Coefficient_3
#wizard text: Coefficient_3:
#wizard input: Coefficient_4
#wizard text: Coefficient_4:
#wizard input: Coefficient_5
#wizard text: Coefficient_5:
#wizard input: Coefficient_6
#wizard text: Coefficient_6:

input price = close;
input high = high;
input low = low;
input coefficient_0 = 0.000;
input coefficient_1 = .236;
input Coefficient_2 = .382;
input Coefficient_3 = .500;
input Coefficient_4 = .618;
Input Coefficient_5 = .786;
input Coefficient_6 = 1.000;

input LabelColor = {default "MAGENTA", "CYAN", "PINK", "LIGHT_GRAY", "ORANGE", "RED", "GREEN", "GRAY", "WHITE"};

def a = HighestAll(high);
def b = LowestAll(low);
def barnumber = barNumber();
def c = if high == a then barnumber else double.nan;
def d = if low == b then barnumber else double.nan;
rec highnumber = compoundValue(1, if IsNaN(c) then highnumber[1] else c, c);
def highnumberall = HighestAll(highnumber);
rec lownumber = compoundValue(1, if IsNaN(d) then lownumber[1] else d, d);
def lownumberall = LowestAll(lownumber);

def upward = highnumberall > lownumberall;
def downward = highnumberall < lownumberall;

def x = AbsValue(lownumberall - highnumberall );

def slope = (a - b) / x;
def slopelow = (b - a) / x;

def day = getDay();
def month = getMonth();
def year = getYear();
def lastDay = getLastDay();
def lastmonth = getLastMonth();
def lastyear = getLastYear();
def isToday = if(day == lastDay and month == lastmonth and year == lastyear, 1, 0);
def istodaybarnumber = HighestAll(if isToday then barnumber else double.nan);
def line = b + (slope * (barnumber - lownumber));
def linelow = a + (slopelow * (barnumber - highnumber));
def currentlinelow = if barnumber <= lownumberall then linelow else double.nan;
def currentline = if barnumber <= highnumberall then line else double.nan;

Plot FibFan =  if  downward then currentlinelow else if upward then currentline else double.nan;
FibFan.SetStyle(Curve.SHORT_DASH);
FibFan.AssignValueColor(color.red);
fibfan.hidebubble();

def range =  a - b;

def value0 = range * coefficient_0;
def value1 = range * coefficient_1;
def value2 = range * coefficient_2;
def value3 = range * coefficient_3;
def value4 = range * coefficient_4;
def value5 = range * coefficient_5;
def value6 = range * coefficient_6;

def condition1 = downward and barnumber >= highnumberall;
def condition2 = upward and barnumber >= lownumberall;

Plot Retracement0 = if condition1 then highestall(b + value0) else if condition2 then highestall(a - value0) else double.nan;
Plot Retracement1 = if condition1 then highestall(b + value1) else if condition2 then highestall(a - value1) else double.nan;
Plot Retracement2 = if condition1 then highestall(b + value2) else if condition2 then highestall(a - value2) else double.nan;
Plot Retracement3 = if condition1 then highestall(b + value3) else if condition2 then highestall(a - value3) else double.nan;
Plot Retracement4 = if condition1 then highestall(b + value4) else if condition2 then highestall(a - value4) else double.nan;
Plot Retracement5 = if condition1 then highestall(b + value5) else if condition2 then highestall(a - value5) else double.nan;
Plot Retracement6 = if condition1 then highestall(b + value6) else if condition2 then highestall(a - value6) else double.nan;

Retracement0.assignvaluecolor(CreateColor(255,255,255));
Retracement0.setLineWeight(4);
retracement0.hidebubble();
#AddChartBubble((barnumber == istodaybarnumber +10), retracement0, concat( "$", round(retracement0, 2)), GetColor(LabelColor), yes);
AddChartBubble((downward and barnumber == highnumberall), retracement0, concat( (coefficient_0 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and barnumber == lownumberall), retracement0, concat( (coefficient_0 * 100), "%"), GetColor(LabelColor), yes);

Retracement1.assignvaluecolor(CreateColor(173,216,230));
Retracement1.setLineWeight(2);
retracement1.hidebubble();
#AddChartBubble((barnumber == istodaybarnumber+10), retracement1, concat( "$", round(retracement1, 2)), GetColor(LabelColor), yes);
AddChartBubble((downward and barnumber == highnumberall), retracement1, concat( (coefficient_1 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and barnumber == lownumberall), retracement1, concat( (coefficient_1 * 100), "%"), GetColor(LabelColor), yes);

Retracement2.assignvaluecolor(CreateColor(0,197,49));
Retracement2.setLineWeight(2);
retracement2.hidebubble();
#AddChartBubble((barnumber == istodaybarnumber+10), retracement2, concat( "$", round(retracement2, 2)), GetColor(LabelColor), yes);
AddChartBubble((downward and barnumber == highnumberall), retracement2, concat( (coefficient_2 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and barnumber == lownumberall), retracement2, concat( (coefficient_2 * 100), "%"), GetColor(LabelColor), yes);

Retracement3.assignvaluecolor(CreateColor(255,64,64));
Retracement3.setLineWeight(3);
retracement3.hidebubble();
#AddChartBubble((barnumber == istodaybarnumber+10), retracement3, concat( "$", round(retracement3, 2)), GetColor(LabelColor), yes);
AddChartBubble((downward and barnumber == highnumberall), retracement3, concat( (coefficient_3 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and barnumber == lownumberall), retracement3, concat( (coefficient_3 * 100), "%"), GetColor(LabelColor), yes);

Retracement4.assignvaluecolor(CreateColor(255,215,0));
Retracement4.setLineWeight(5);
retracement4.hidebubble();
#AddChartBubble((barnumber == istodaybarnumber+10), retracement4, concat( "$", round(retracement4, 2)), GetColor(LabelColor), yes);
AddChartBubble((downward and barnumber == highnumberall), retracement4, concat( (coefficient_4 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and barnumber == lownumberall), retracement4, concat( (coefficient_4 * 100), "%"), GetColor(LabelColor), yes);

Retracement5.assignvaluecolor(CreateColor(0,255,255));
Retracement5.setLineWeight(2);
retracement5.hidebubble();
#AddChartBubble((barnumber == istodaybarnumber+10), retracement5, concat( "$", round(retracement5, 2)), GetColor(LabelColor), yes);
AddChartBubble((downward and barnumber == highnumberall), retracement5, concat( (coefficient_5 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and barnumber == lownumberall), retracement5, concat( (coefficient_5 * 100), "%"), GetColor(LabelColor), yes);

Retracement6.assignvaluecolor(CreateColor(255,255,255));
Retracement6.setLineWeight(4);
Retracement6.hidebubble();
#AddChartBubble((barnumber == istodaybarnumber+10), retracement6, concat( "$", round(retracement6, 2)), GetColor(LabelColor), yes);
AddChartBubble((downward and barnumber == highnumberall), retracement6, concat( (coefficient_6 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and barnumber == lownumberall), retracement6, concat( (coefficient_6 * 100), "%"), GetColor(LabelColor), yes);

alert((price crosses below Retracement0) , "Price crosses below Retracement Line 0");
alert((price crosses above Retracement0) , "Price crosses above Retracement Line 0");
alert((price crosses below Retracement1) , "Price crosses below Retracement Line 1");
alert((price crosses above Retracement1) , "Price crosses above Retracement Line 1");
alert((price crosses below Retracement2) , "Price crosses below Retracement Line 2");
alert((price crosses above Retracement2) , "Price crosses above Retracement Line 2");
alert((price crosses below Retracement3) , "Price crosses below Retracement Line 3");
alert((price crosses above Retracement3) , "Price crosses above Retracement Line 3");
alert((price crosses below Retracement4) , "Price crosses below Retracement Line 4");
alert((price crosses above Retracement4) , "Price crosses above Retracement Line 4");
alert((price crosses below Retracement5) , "Price crosses below Retracement Line 5");
alert((price crosses above Retracement5) , "Price crosses above Retracement Line 5");
alert((price crosses below Retracement6) , "Price crosses below Retracement Line 6");
alert((price crosses above Retracement6) , "Price crosses above Retracement Line 6");
# END CODE
Hello can someone tell how to get this based on the previous day?
 
Anyone to help, I would like to add 88.6% and 128%. I tried but unfortunately I missed up the code .

And if there is any option to reverse it. For example for uptrend will go from 100% to 0. I would like to reverse it for uptrend from 0 to 100% ( so I have an option for that ) .

Thank you so much
 
@iSultan you didn't reference what code you are using that you are trying to add, no need to post whole code, you can just say code from post#XYZ. If you want to inverse you can inverse it by multiplying -1
 
you didnt reference what code you are using that you are trying to add, no need to post whole code, you can just say code from post#XYZ
if you want to inverse you can inverse it by multiplying -1
Code:
# Auto Fib V1.3
# tomsk
# 11.19.2019

# Automatically draws fibonacci retracements using the highest price and lowest price
# from the current view and timeframe.
#
# Fibonacci retracements use horizontal lines to indicate areas of support or resistance
# at the key Fibonacci levels before it continues in the original direction. These levels
# are created by drawing a trendline between two extreme points and then dividing the
# vertical distance by the key Fibonacci ratios of: 23.6%, 38.2%, 50%, 61.8%, 78.6%, and 100%.

# CHANGE LOG
#
# V1.0 - 12.18.2018 - BenTen       - Initial release of Auto Fib, created by Ryan Hendricks
# V1.1 - 11.15.2019 - theelderwand - As script was difficult to read, made the following enhancements
#                                    Expands to right
#                                    Doesn't expand to left
#                                    Custom colors for Fibonacci bars (0.618 is GOLD color)
#                                    Custom line weights
#                                    Code is modularized so you can add extra plots as needed
# V1.2 - 11.15.2019 - tomsk        - Added an input selector for the colors of the label. You
#                                    can select from any of the colors listed - red, orange,
#                                    green, etc and bubbles for all the fib retracements will
#                                    utilize that color.
# V1.3 - 11.19.2019 - tomsk        - Modified the AddChartBubbles to be displayed on the right
#                                    side of the chart. Please ensure that you increase the
#                                    expansion area to that the bubbles have room to be displayed
#                                    Chart Settings > Time Axis > Expansion Area

#hint Price: Price used in the alerts on crossing retracement lines. <b>(Default is Close)</b>

#hint coefficient_0: Retracement Line 0: Retracement from the highest high to the lowest low.<b>(Default is 0%)</b>
#hint Coefficient_1: Retracement Line 1: Retracement from the highest high to the lowest low.<b>(Default is 23.6%)</b>
#hint Coefficient_2: Retracement Line 2: Retracement from the highest high to the lowest low.<b>(Default is 38.2%)</b>
#hint Coefficient_3: Retracement Line 3: Retracement from the highest high to the lowest low.<b>(Default is 50%)</b>
#hint Coefficient_4: Retracement Line 4: Retracement from the highest high to the lowest low.<b>(Default is 61.8%)</b>
#hint Coefficient_5: Retracement Line 5: Retracement from the highest high to the lowest low.<b>(Default is 78.6%)</b>
#hint Coefficient_6: Retracement Line 6: Retracement from the highest high to the lowest low.<b>(Default is 100%)</b>

#wizard input: Price
#wizard text: Inputs: Price:
#wizard input: coefficient_0
#wizard text: coefficient_0:
#wizard input: Coefficient_1
#wizard text: Coefficient_1:
#wizard input: Coefficient_2
#wizard text: Coefficient_2:
#wizard input: Coefficient_3
#wizard text: Coefficient_3:
#wizard input: Coefficient_4
#wizard text: Coefficient_4:
#wizard input: Coefficient_5
#wizard text: Coefficient_5:
#wizard input: Coefficient_6
#wizard text: Coefficient_6:

input price = close;
input high = high;
input low = low;
input coefficient_0 = 0.000;
input coefficient_1 = .236;
input Coefficient_2 = .382;
input Coefficient_3 = .500;
input Coefficient_4 = .618;
Input Coefficient_5 = .786;
input Coefficient_6 = 1.000;

input LabelColor = {default "MAGENTA", "CYAN", "PINK", "LIGHT_GRAY", "ORANGE", "RED", "GREEN", "GRAY", "WHITE"};
input n = 3;

def n1  = n + 1;
def a = HighestAll(high);
def b = LowestAll(low);
def barnumber = barNumber();
def c = if high == a then barnumber else double.nan;
def d = if low == b then barnumber else double.nan;
rec highnumber = compoundValue(1, if IsNaN(c) then highnumber[1] else c, c);
def highnumberall = HighestAll(highnumber);
rec lownumber = compoundValue(1, if IsNaN(d) then lownumber[1] else d, d);
def lownumberall = LowestAll(lownumber);

def upward = highnumberall > lownumberall;
def downward = highnumberall < lownumberall;

def x = AbsValue(lownumberall - highnumberall );

def slope = (a - b) / x;
def slopelow = (b - a) / x;

def day = getDay();
def month = getMonth();
def year = getYear();
def lastDay = getLastDay();
def lastmonth = getLastMonth();
def lastyear = getLastYear();
def isToday = if(day == lastDay and month == lastmonth and year == lastyear, 1, 0);
def istodaybarnumber = HighestAll(if isToday then barnumber else double.nan);
def line = b + (slope * (barnumber - lownumber));
def linelow = a + (slopelow * (barnumber - highnumber));
def currentlinelow = if barnumber <= lownumberall then linelow else double.nan;
def currentline = if barnumber <= highnumberall then line else double.nan;

Plot FibFan =  if  downward then currentlinelow else if upward then currentline else double.nan;
FibFan.SetStyle(Curve.SHORT_DASH);
FibFan.AssignValueColor(color.red);
fibfan.hidebubble();

def range =  a - b;

def value0 = range * coefficient_0;
def value1 = range * coefficient_1;
def value2 = range * coefficient_2;
def value3 = range * coefficient_3;
def value4 = range * coefficient_4;
def value5 = range * coefficient_5;
def value6 = range * coefficient_6;

def condition1 = downward and barnumber >= highnumberall;
def condition2 = upward and barnumber >= lownumberall;

Plot Retracement0 = if condition1 then highestall(b + value0) else if condition2 then highestall(a - value0) else double.nan;
Plot Retracement1 = if condition1 then highestall(b + value1) else if condition2 then highestall(a - value1) else double.nan;
Plot Retracement2 = if condition1 then highestall(b + value2) else if condition2 then highestall(a - value2) else double.nan;
Plot Retracement3 = if condition1 then highestall(b + value3) else if condition2 then highestall(a - value3) else double.nan;
Plot Retracement4 = if condition1 then highestall(b + value4) else if condition2 then highestall(a - value4) else double.nan;
Plot Retracement5 = if condition1 then highestall(b + value5) else if condition2 then highestall(a - value5) else double.nan;
Plot Retracement6 = if condition1 then highestall(b + value6) else if condition2 then highestall(a - value6) else double.nan;

Retracement0.assignvaluecolor(CreateColor(255,255,255));
Retracement0.setLineWeight(4);
retracement0.hidebubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), retracement0, concat( (coefficient_0 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), retracement0, concat( (coefficient_0 * 100), "%"), GetColor(LabelColor), yes);

Retracement1.assignvaluecolor(CreateColor(173,216,230));
Retracement1.setLineWeight(2);
retracement1.hidebubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), retracement1, concat( (coefficient_1 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), retracement1, concat( (coefficient_1 * 100), "%"), GetColor(LabelColor), yes);

Retracement2.assignvaluecolor(CreateColor(0,197,49));
Retracement2.setLineWeight(2);
retracement2.hidebubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), retracement2, concat( (coefficient_2 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), retracement2, concat( (coefficient_2 * 100), "%"), GetColor(LabelColor), yes);

Retracement3.assignvaluecolor(CreateColor(255,64,64));
Retracement3.setLineWeight(3);
retracement3.hidebubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), retracement3, concat( (coefficient_3 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), retracement3, concat( (coefficient_3 * 100), "%"), GetColor(LabelColor), yes);

Retracement4.assignvaluecolor(CreateColor(255,215,0));
Retracement4.setLineWeight(5);
retracement4.hidebubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), retracement4, concat( (coefficient_4 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), retracement4, concat( (coefficient_4 * 100), "%"), GetColor(LabelColor), yes);

Retracement5.assignvaluecolor(CreateColor(0,255,255));
Retracement5.setLineWeight(2);
retracement5.hidebubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), retracement5, concat( (coefficient_5 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), retracement5, concat( (coefficient_5 * 100), "%"), GetColor(LabelColor), yes);

Retracement6.assignvaluecolor(CreateColor(255,255,255));
Retracement6.setLineWeight(4);
Retracement6.hidebubble();
AddChartBubble((downward and close[n1]) and IsNaN(close[n]), retracement6, concat( (coefficient_6 * 100), "%"), GetColor(LabelColor), yes);
AddChartBubble((upward and close[n1]) and IsNaN(close[n]), retracement6, concat( (coefficient_6 * 100), "%"), GetColor(LabelColor), yes);

alert((price crosses below Retracement0) , "Price crosses below Retracement Line 0");
alert((price crosses above Retracement0) , "Price crosses above Retracement Line 0");
alert((price crosses below Retracement1) , "Price crosses below Retracement Line 1");
alert((price crosses above Retracement1) , "Price crosses above Retracement Line 1");
alert((price crosses below Retracement2) , "Price crosses below Retracement Line 2");
alert((price crosses above Retracement2) , "Price crosses above Retracement Line 2");
alert((price crosses below Retracement3) , "Price crosses below Retracement Line 3");
alert((price crosses above Retracement3) , "Price crosses above Retracement Line 3");
alert((price crosses below Retracement4) , "Price crosses below Retracement Line 4");
alert((price crosses above Retracement4) , "Price crosses above Retracement Line 4");
alert((price crosses below Retracement5) , "Price crosses below Retracement Line 5");
alert((price crosses above Retracement5) , "Price crosses above Retracement Line 5");
alert((price crosses below Retracement6) , "Price crosses below Retracement Line 6");
alert((price crosses above Retracement6) , "Price crosses above Retracement Line 6");
# End Auto Fib v1.3
 
there are six retracements you find out which ones are the ones you want to add and do the following
example:
Code:
plot scan = Retracement2 + Retracement3;
 
@iSultan This has 86% and also has slope.

Code:
input slope_adjust_multiplier = 0.00;
input price = close;
input high = high;
input low = low;
input coefficient_0 = 0.000;
input coefficient_1 = .236;
input Coefficient_2 = .382;
input Coefficient_3 = .500;
input Coefficient_4 = .618;
Input Coefficient_5 = .786;
input Coefficient_6 = .866;
input Coefficient_7 = 1.0;

def slope_adj = slope_adjust_multiplier;
def a = HighestAll(high);
def b = LowestAll(low);
def barnumber = barNumber();
def c = if high == a then barnumber else double.nan;
def d = if low == b then barnumber else double.nan;
rec highnumber = compoundValue(1, if IsNaN(c) then highnumber[1] else c, c);
def highnumberall = HighestAll(highnumber);
rec lownumber = compoundValue(1, if IsNaN(d) then lownumber[1] else d, d);
def lownumberall = LowestAll(lownumber);

def upward = highnumberall > lownumberall;
def downward = highnumberall < lownumberall;
def range =  a - b;
def value0 = range * coefficient_0;
def value1 = range * coefficient_1;
def value2 = range * coefficient_2;
def value3 = range * coefficient_3;
def value4 = range * coefficient_4;
def value5 = range * coefficient_5;
def value6 = range * coefficient_6;
def value7 = range * coefficient_7;


def condition1 = downward and barnumber >= highnumberall;
def condition2 = upward and barnumber >= lownumberall;

Plot Retracement0 = if condition1 then highestall(b + value0) else if condition2 then highestall(a - value0) else double.nan;
Plot Retracement1 = if condition1 then highestall(b + value1) else if condition2 then highestall(a - value1) else double.nan;
Plot Retracement2 = if condition1 then highestall(b + value2) else if condition2 then highestall(a - value2) else double.nan;
Plot Retracement3 = if condition1 then highestall(b + value3) else if condition2 then highestall(a - value3) else double.nan;
Plot Retracement4 = if condition1 then highestall(b + value4) else if condition2 then highestall(a - value4) else double.nan;
Plot Retracement5 = if condition1 then highestall(b + value5) else if condition2 then highestall(a - value5) else double.nan;
Plot Retracement6 = if condition1 then highestall(b + value6) else if condition2 then highestall(a - value6) else double.nan;
Plot Retracement7 = if condition1 then highestall(b + value7) else if condition2 then highestall(a - value7) else double.nan;



def x = AbsValue(lownumberall - highnumberall );

def slope = (a - b) / x;
def slopelow = (b - a) / x;

def day = getDay();
def month = getMonth();
def year = getYear();
def lastDay = getLastDay();
def lastmonth = getLastMonth();
def lastyear = getLastYear();
def isToday = if(day == lastDay and month == lastmonth and year == lastyear, 1, 0);
def istodaybarnumber = HighestAll(if isToday then barnumber else double.nan);


def line = b + (slope * (barnumber - lownumber));
def linelow = a + (slopelow * (barnumber - highnumber));
def currentlinelow = if barnumber <= lownumberall then linelow else double.nan;
def currentline = if barnumber <= highnumberall then line else double.nan;

Plot FibFan =  if  downward then currentlinelow else if upward then currentline else double.nan;
FibFan.SetStyle(Curve.SHORT_DASH);
FibFan.AssignValueColor(color.red);
fibfan.hidebubble();


def xx = if condition1 then (barnumber - highnumberall) else (barnumber - lownumberall);
def mm = if condition1 then highestall((ohlc4 - retracement7) / xx) else lowestall((ohlc4 - retracement7) / xx);

#PLOT FIBS with slope
# Y = MX + B
#y = end value, m = slope = x is time b = beg value
plot r7 = mm*slope_adj*xx + retracement7;
plot r6 = mm*slope_adj*xx + retracement6;
plot r5 = mm*slope_adj*xx + retracement5;
plot r4 = mm*slope_adj*xx + retracement4;
plot r3 = mm*slope_adj*xx + retracement3;
plot r2 = mm*slope_adj*xx + retracement2;
plot r1 = mm*slope_adj*xx + retracement1;
plot r0 = mm*slope_adj*xx + retracement0;

#VISUALS AND ALERTS
Retracement0.assignvaluecolor(CreateColor(255,255,255));
Retracement0.setLineWeight(4);
retracement0.hidebubble();
#AddChartBubble((barnumber == istodaybarnumber +10), retracement0, concat( "$", round(retracement0, 2)), color.red, yes);
AddChartBubble((downward and barnumber == highnumberall), retracement0, concat( (coefficient_0 * 100), "%"), color.red, yes);
AddChartBubble((upward and barnumber == lownumberall), retracement0, concat( (coefficient_0 * 100), "%"), color.red, yes);

Retracement1.assignvaluecolor(CreateColor(173,216,230));
Retracement1.setLineWeight(2);
retracement1.hidebubble();
#AddChartBubble((barnumber == istodaybarnumber+10), retracement1, concat( "$", round(retracement1, 2)), color.red, yes);
AddChartBubble((downward and barnumber == highnumberall), retracement1, concat( (coefficient_1 * 100), "%"), color.red, yes);
AddChartBubble((upward and barnumber == lownumberall), retracement1, concat( (coefficient_1 * 100), "%"), color.red, yes);

Retracement2.assignvaluecolor(CreateColor(0,197,49));
Retracement2.setLineWeight(2);
retracement2.hidebubble();
#AddChartBubble((barnumber == istodaybarnumber+10), retracement2, concat( "$", round(retracement2, 2)), color.red, yes);
AddChartBubble((downward and barnumber == highnumberall), retracement2, concat( (coefficient_2 * 100), "%"), color.red, yes);
AddChartBubble((upward and barnumber == lownumberall), retracement2, concat( (coefficient_2 * 100), "%"), color.red, yes);

Retracement3.assignvaluecolor(CreateColor(255,64,64));
Retracement3.setLineWeight(3);
retracement3.hidebubble();
#AddChartBubble((barnumber == istodaybarnumber+10), retracement3, concat( "$", round(retracement3, 2)), color.red, yes);
AddChartBubble((downward and barnumber == highnumberall), retracement3, concat( (coefficient_3 * 100), "%"), color.red, yes);
AddChartBubble((upward and barnumber == lownumberall), retracement3, concat( (coefficient_3 * 100), "%"), color.red, yes);

Retracement4.assignvaluecolor(CreateColor(255,215,0));
Retracement4.setLineWeight(5);
retracement4.hidebubble();
#AddChartBubble((barnumber == istodaybarnumber+10), retracement4, concat( "$", round(retracement4, 2)), color.red, yes);
AddChartBubble((downward and barnumber == highnumberall), retracement4, concat( (coefficient_4 * 100), "%"), color.red, yes);
AddChartBubble((upward and barnumber == lownumberall), retracement4, concat( (coefficient_4 * 100), "%"), color.red, yes);

Retracement5.assignvaluecolor(CreateColor(0,255,255));
Retracement5.setLineWeight(2);
retracement5.hidebubble();
#AddChartBubble((barnumber == istodaybarnumber+10), retracement5, concat( "$", round(retracement5, 2)), color.red, yes);
AddChartBubble((downward and barnumber == highnumberall), retracement5, concat( (coefficient_5 * 100), "%"), color.red, yes);
AddChartBubble((upward and barnumber == lownumberall), retracement5, concat( (coefficient_5 * 100), "%"), color.red, yes);

Retracement6.assignvaluecolor(CreateColor(255,255,255));
Retracement6.setLineWeight(4);
Retracement6.hidebubble();
#AddChartBubble((barnumber == istodaybarnumber+10), retracement6, concat( "$", round(retracement6, 2)), color.red, yes);
AddChartBubble((downward and barnumber == highnumberall), retracement6, concat( (coefficient_6 * 100), "%"), color.red, yes);
AddChartBubble((upward and barnumber == lownumberall), retracement6, concat( (coefficient_6 * 100), "%"), color.red, yes);

Retracement7.assignvaluecolor(CreateColor(255,255,255));
Retracement7.setLineWeight(4);
Retracement7.hidebubble();
#AddChartBubble((barnumber == istodaybarnumber+10), retracement6, concat( "$", round(retracement6, 2)), color.red, yes);
AddChartBubble((downward and barnumber == highnumberall), retracement7, concat( (coefficient_7 * 100), "%"), color.red, yes);
AddChartBubble((upward and barnumber == lownumberall), retracement7, concat( (coefficient_7 * 100), "%"), color.red, yes);

r0.setlineWeight(2);
r1.setlineWeight(2);
r2.setlineWeight(2);
r3.setlineWeight(2);
r4.setlineWeight(2);
r5.setlineWeight(2);
r6.setlineWeight(2);


r7.Hide();
r6.Hide();
r5.Hide();
r4.Hide();
r3.Hide();
r2.Hide();
r1.Hide();
r0.Hide();
 
Last edited:
How do I get my fib numbers on the right side of the chart. When I had the auto fib I can see the numbers on the lines. The numbers are all the way to the left.
 
@9inemill Here's the modified script with Fib numbers displaying on the right side of the line instead of the left.

Code:
#hint Price: Price used in the alerts on crossing retracement lines. <b>(Default is Close)</b>
#hint onExpansion: Determines if the retracement lines are projected past the current bar into the right side expansion <b>(Default is Yes)</b>
#hint Extend_to_left: Determines if the retracement lines are extended to the left side of the chart. <b>(Default is No)</b>

#hint Coefficient0: Retracement Line 0: Retracement from the highest high to the lowest low.<b>(Default is 0%)</b>
#hint Coefficient_1: Retracement Line 1: Retracement from the highest high to the lowest low.<b>(Default is 23.6%)</b>
#hint Coefficient_2: Retracement Line 2: Retracement from the highest high to the lowest low.<b>(Default is 38.2%)</b>
#hint Coefficient_3: Retracement Line 3: Retracement from the highest high to the lowest low.<b>(Default is 50%)</b>
#hint Coefficient_4: Retracement Line 4: Retracement from the highest high to the lowest low.<b>(Default is 61.8%)</b>
#hint Coefficient_5: Retracement Line 5: Retracement from the highest high to the lowest low.<b>(Default is 78.6%)</b>
#hint Coefficient_6: Retracement Line 6: Retracement from the highest high to the lowest low.<b>(Default is 100%)</b>

#wizard input: Price
#wizard text: Inputs: Price:
#wizard input: onExpansion
#wizard text: onExpansion:
#wizard input: Extend_to_left
#wizard text: Extend_to_left:
#wizard input: Coefficient0
#wizard text: Coefficient0:
#wizard input: Coefficient_1
#wizard text: Coefficient_1:
#wizard input: Coefficient_2
#wizard text: Coefficient_2:
#wizard input: Coefficient_3
#wizard text: Coefficient_3:
#wizard input: Coefficient_4
#wizard text: Coefficient_4:
#wizard input: Coefficient_5
#wizard text: Coefficient_5:
#wizard input: Coefficient_6
#wizard text: Coefficient_6:

input price = close;
input high = high;
input low = low;
input onExpansion = Yes;
input Extend_to_left = no;
input Coefficient0 = 0.000;
input coefficient_1 = .236;
input Coefficient_2 = .382;
input Coefficient_3 = .500;
input Coefficient_4 = .618;
Input Coefficient_5 = .786;
input Coefficient_6 = 1.000;

def a = HighestAll(high);
def b = LowestAll(low);
def barnumber = barNumber();
def c = if high == a then barnumber else double.nan;
def d = if low == b then barnumber else double.nan;
rec highnumber = compoundValue(1, if IsNaN(c) then highnumber[1] else c, c);
def highnumberall = HighestAll(highnumber);
rec lownumber = compoundValue(1, if IsNaN(d) then lownumber[1] else d, d);
def lownumberall = LowestAll(lownumber);

def upward = highnumberall > lownumberall;
def downward = highnumberall < lownumberall;

def x = AbsValue(lownumberall - highnumberall );

def slope = (a - b) / x;
def slopelow = (b - a) / x;

def day = getDay();
def month = getMonth();
def year = getYear();
def lastDay = getLastDay();
def lastmonth = getLastMonth();
def lastyear = getLastYear();
def isToday = if(day == lastDay and month == lastmonth and year == lastyear, 1, 0);
def istodaybarnumber = HighestAll(if isToday then barnumber else double.nan);
def line = b + (slope * (barnumber - lownumber));
def linelow = a + (slopelow * (barnumber - highnumber));
def currentlinelow = if barnumber <= lownumberall then linelow else double.nan;
def currentline = if barnumber <= highnumberall then line else double.nan;

Plot FibFan =  if  downward then currentlinelow else if upward then currentline else double.nan;
FibFan.SetStyle(Curve.SHORT_DASH);
FibFan.AssignValueColor(color.red);
fibfan.hidebubble();

def range =  a - b;

Plot Retracement0 = if downward and !onexpansion and !extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient0))) else if upward and !extend_to_left and !onexpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then highestall(a - (range * coefficient0)) else if downward and onexpansion and !extend_to_left and barnumber >= highnumberall then highestall((b + (range *  coefficient0))) else if upward and onexpansion and barnumber >= lownumberall and !extend_to_left then highestall(a - (range * coefficient0)) else if downward and !onexpansion and extend_to_left and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient0))) else if upward and extend_to_left and !onexpansion and barnumber <= istodaybarnumber then highestall(a - (range * coefficient0)) else if downward and onexpansion and extend_to_left then highestall((b + (range *  coefficient0))) else if upward and onexpansion and extend_to_left then highestall(a - (range * coefficient0)) else double.nan;
Retracement0.assignvaluecolor(color.red);
retracement0.hidebubble();
##AddChartBubble((barnumber == istodaybarnumber +10), retracement0, concat( "$", round(retracement0, 2)), color.red, yes);
#AddChartBubble((downward and barnumber == highnumberall), retracement0, concat( (coefficient0 * 100), "%"), color.red, yes);
#AddChartBubble((upward and barnumber == lownumberall), retracement0, concat( (coefficient0 * 100), "%"), color.red, yes);

Plot Retracement1 =  if downward and !onexpansion and !extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_1))) else if upward and !extend_to_left and !onexpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_1)) else if downward and onexpansion and !extend_to_left and barnumber >= highnumberall then highestall((b + (range *  coefficient_1))) else if upward and onexpansion and barnumber >= lownumberall and !extend_to_left then highestall(a - (range * coefficient_1)) else if downward and !onexpansion and extend_to_left and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_1))) else if upward and extend_to_left and !onexpansion and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_1)) else if downward and onexpansion and extend_to_left then highestall((b + (range *  coefficient_1))) else if upward and onexpansion and extend_to_left then highestall(a - (range * coefficient_1)) else double.nan;
Retracement1.assignvaluecolor(color.red);
retracement1.hidebubble();
##AddChartBubble((barnumber == istodaybarnumber+10), retracement1, concat( "$", round(retracement1, 2)), color.red, yes);
#AddChartBubble((downward and barnumber == highnumberall), retracement1, concat( (coefficient_1 * 100), "%"), color.red, yes);
#AddChartBubble((upward and barnumber == lownumberall), retracement1, concat( (coefficient_1 * 100), "%"), color.red, yes);

Plot Retracement2 =if downward and !onexpansion and !extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_2))) else if upward and !extend_to_left and !onexpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_2)) else if downward and onexpansion and !extend_to_left and barnumber >= highnumberall then highestall((b + (range *  coefficient_2))) else if upward and onexpansion and barnumber >= lownumberall and !extend_to_left then highestall(a - (range * coefficient_2)) else if downward and !onexpansion and extend_to_left and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_2))) else if upward and extend_to_left and !onexpansion and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_2)) else if downward and onexpansion and extend_to_left then highestall((b + (range *  coefficient_2))) else if upward and onexpansion and extend_to_left then highestall(a - (range * coefficient_2)) else double.nan;
Retracement2.assignvaluecolor(color.red);
retracement2.hidebubble();
##AddChartBubble((barnumber == istodaybarnumber+10), retracement2, concat( "$", round(retracement2, 2)), color.red, yes);
#AddChartBubble((downward and barnumber == highnumberall), retracement2, concat( (coefficient_2 * 100), "%"), color.red, yes);
#AddChartBubble((upward and barnumber == lownumberall), retracement2, concat( (coefficient_2 * 100), "%"), color.red, yes);

Plot Retracement3 = if downward and !onexpansion and !extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_3))) else if upward and !extend_to_left and !onexpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_3)) else if downward and onexpansion and !extend_to_left and barnumber >= highnumberall then highestall((b + (range *  coefficient_3))) else if upward and onexpansion and barnumber >= lownumberall and !extend_to_left then highestall(a - (range * coefficient_3)) else if downward and !onexpansion and extend_to_left and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_3))) else if upward and extend_to_left and !onexpansion and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_3)) else if downward and onexpansion and extend_to_left then highestall((b + (range *  coefficient_3))) else if upward and onexpansion and extend_to_left then highestall(a - (range * coefficient_3)) else double.nan;
Retracement3.assignvaluecolor(color.red);
retracement3.hidebubble();
##AddChartBubble((barnumber == istodaybarnumber+10), retracement3, concat( "$", round(retracement3, 2)), color.red, yes);
#AddChartBubble((upward and barnumber == lownumberall), retracement3, concat( (coefficient_3 * 100), "%"), color.red, yes);
#AddChartBubble((downward and barnumber == highnumberall), retracement3, concat( (coefficient_3 * 100), "%"), color.red, yes);
#AddChartBubble((upward and barnumber == lownumberall), retracement3, concat( (coefficient_3 * 100), "%"), color.red, yes);

Plot Retracement4 = if downward and !onexpansion and !extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_4))) else if upward and !extend_to_left and !onexpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_4)) else if downward and onexpansion and !extend_to_left and barnumber >= highnumberall then highestall((b + (range *  coefficient_4))) else if upward and onexpansion and barnumber >= lownumberall and !extend_to_left then highestall(a - (range * coefficient_4)) else if downward and !onexpansion and extend_to_left and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_4))) else if upward and extend_to_left and !onexpansion and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_4)) else if downward and onexpansion and extend_to_left then highestall((b + (range *  coefficient_4))) else if upward and onexpansion and extend_to_left then highestall(a - (range * coefficient_4)) else double.nan;
Retracement4.assignvaluecolor(color.red);
retracement4.hidebubble();
##AddChartBubble((barnumber == istodaybarnumber+10), retracement4, concat( "$", round(retracement4, 2)), color.red, yes);
#AddChartBubble((downward and barnumber == highnumberall), retracement4, concat( (coefficient_4 * 100), "%"), color.red, yes);
#AddChartBubble((upward and barnumber == lownumberall), retracement4, concat( (coefficient_4 * 100), "%"), color.red, yes);

Plot Retracement5 = if downward and !onexpansion and !extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_5))) else if upward and !extend_to_left and !onexpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_5)) else if downward and onexpansion and !extend_to_left and barnumber >= highnumberall then highestall((b + (range *  coefficient_5))) else if upward and onexpansion and barnumber >= lownumberall and !extend_to_left then highestall(a - (range * coefficient_5)) else if downward and !onexpansion and extend_to_left and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_5))) else if upward and extend_to_left and !onexpansion and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_5)) else if downward and onexpansion and extend_to_left then highestall((b + (range *  coefficient_5))) else if upward and onexpansion and extend_to_left then highestall(a - (range * coefficient_5)) else double.nan;
Retracement5.assignvaluecolor(color.red);
retracement5.hidebubble();
##AddChartBubble((barnumber == istodaybarnumber+10), retracement5, concat( "$", round(retracement5, 2)), color.red, yes);
#AddChartBubble((downward and barnumber == highnumberall), retracement5, concat( (coefficient_5 * 100), "%"), color.red, yes);
#AddChartBubble((upward and barnumber == lownumberall), retracement5, concat( (coefficient_5 * 100), "%"), color.red, yes);

Plot Retracement6 = if downward and !onexpansion and !extend_to_left and barnumber >= highnumberall and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_6))) else if upward and !extend_to_left and !onexpansion and barnumber >= lownumberall and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_6)) else if downward and onexpansion and !extend_to_left and barnumber >= highnumberall then highestall((b + (range *  coefficient_6))) else if upward and onexpansion and barnumber >= lownumberall and !extend_to_left then highestall(a - (range * coefficient_6)) else if downward and !onexpansion and extend_to_left and barnumber <= istodaybarnumber then highestall((b + (range *  coefficient_6))) else if upward and extend_to_left and !onexpansion and barnumber <= istodaybarnumber then highestall(a - (range * coefficient_6)) else if downward and onexpansion and extend_to_left then highestall((b + (range *  coefficient_6))) else if upward and onexpansion and extend_to_left then highestall(a - (range * coefficient_6)) else double.nan;
Retracement6.assignvaluecolor(color.red);
retracement6.hidebubble();
##AddChartBubble((barnumber == istodaybarnumber+10), retracement6, concat( "$", round(retracement6, 2)), color.red, yes);

alert((price crosses below Retracement0) , "Price crosses below Retracement Line 0");
alert((price crosses above Retracement0) , "Price crosses above Retracement Line 0");
alert((price crosses below Retracement1) , "Price crosses below Retracement Line 1");
alert((price crosses above Retracement1) , "Price crosses above Retracement Line 1");
alert((price crosses below Retracement2) , "Price crosses below Retracement Line 2");
alert((price crosses above Retracement2) , "Price crosses above Retracement Line 2");
alert((price crosses below Retracement3) , "Price crosses below Retracement Line 3");
alert((price crosses above Retracement3) , "Price crosses above Retracement Line 3");
alert((price crosses below Retracement4) , "Price crosses below Retracement Line 4");
alert((price crosses above Retracement4) , "Price crosses above Retracement Line 4");
alert((price crosses below Retracement5) , "Price crosses below Retracement Line 5");
alert((price crosses above Retracement5) , "Price crosses above Retracement Line 5");
alert((price crosses below Retracement6) , "Price crosses below Retracement Line 6");
alert((price crosses above Retracement6) , "Price crosses above Retracement Line 6");

def limit = !IsNaN(close) and IsNaN(close [-1] ) && HighestAll(BarNumber());
AddChartBubble(limit, retracement6, concat( (coefficient_6 * 100), "%"), Color.RED);
AddChartBubble(limit, retracement5, concat( (coefficient_5 * 100), "%"), Color.RED);
AddChartBubble(limit, retracement4, concat( (coefficient_4 * 100), "%"), Color.RED);
AddChartBubble(limit, retracement3, concat( (coefficient_3 * 100), "%"), Color.RED);
AddChartBubble(limit, retracement2, concat( (coefficient_2 * 100), "%"), Color.RED);
AddChartBubble(limit, retracement1, concat( (coefficient_1 * 100), "%"), Color.RED);
AddChartBubble(limit, retracement0, concat( (coefficient0 * 100), "%"), Color.RED);
 
@BenTen,

Thanks for the scripts , i have been trying to write one similar for some time, i am new to TOS. If i need to move the highest bar to a few days before the highest price for the period how would I do that?
 
@BenTen, Thanks for the scripts , i have been trying to write one similar for some time, i am new to TOS. If i need to move the highest bar to a few days before the highest price for the period how would I do that?
See if this might be what you are requesting. This will make the highest price's bar changed to show the high of a prior bar offset by the number of bars at the input.

Add the following code to the script:
input offset = 1;

Modify the following code in the script:

def a = if high == HighestAll(high) then high[offset] else a[1];

hcxkNfd.gif
 
Last edited:
Thanks @SleepyZ for the script, that is exactly what i want. I tried to modify as per your suggestion but the lines would not draw on the chart. I replaced the script as follows and am not sure what i am doing wrong. Appreciate your help again.

Code:
input offset = 1;
#def a = HighestAll(high);
def a = if high == HighestAll(high) then high[offset] else a[1];

UPDATE : If I keep the offset a a negative number then it works.
 
Last edited:
@mahesh-k Sorry, I forgot to include 'def c' also

Add the following code to the script:
Code:
input offset = 1;

Modify the following code in the script:

Code:
def a = if high == HighestAll(high) then high[offset] else a[1];
def c = if high[offset] == a then barnumber else Double.NaN;
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
427 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top