.236 FIB Extension Tool
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jordanfray

//@version=5
indicator(".236 FIB Extension Tool", shorttitle=".236 FIB EXT", overlay=true)

// Colors - - - - - - - - - - - - - - - - - - - - 
white       =   color.new(#ffffff, 0)
red         =   color.new(#E02A4A, 0)
green       =   color.new(#2DBD85, 0)

// Tooltip - - - - - - - - - - - - - - - - - - - - 
start_tooltip = "Select the start of the price wave where you want to extend the fib levels from."
extension_tooltip = "Select the end of the first wave to extend fib levels beyond it."


// Indicator Settings - - - - - - - - - - - - - - - - - - - - 
start       =   input.price(defval=0, title="Starting Price", confirm=true, group = "Fib Extension Settings", tooltip=start_tooltip)
extension   =   input.price(defval=0, title=".236 Extension", confirm=true, group = "Fib Extension Settings", tooltip=extension_tooltip)
support_color      =   input.color(defval=green, title="Support Color", group = "Fib Extension Settings")
resistance_color      =   input.color(defval=red, title="Reistance Color", group = "Fib Extension Settings")

// Calulate FIB Levels - - - - - - - - - - - - - - - - - - - - 
level_100 = ((extension - start) / .236) + start
level_786 = ((level_100 - start) * .786) + start
level_650 = ((level_100 - start) * .650) + start
level_618 = ((level_100 - start) * .618) + start
level_500 = ((level_100 - start) * .500) + start
level_382 = ((level_100 - start) * .382) + start
level_236 = extension
level_000 = start

level_1236 = ((level_100 - start) * 1.236) + start
level_1328 = ((level_100 - start) * 1.328) + start
level_1500 = ((level_100 - start) * 1.500) + start
level_1618 = ((level_100 - start) * 1.618) + start
level_1786 = ((level_100 - start) * 1.786) + start

inner_level_236 = level_236 - ((level_236 - start) * .236)
inner_level_328 = level_236 - ((level_236 - start) * .382)
inner_level_500 = level_236 - ((level_236 - start) * .500)
inner_level_618 = level_236 - ((level_236 - start) * .618)
inner_level_650 = level_236 - ((level_236 - start) * .650)
inner_level_786 = level_236 - ((level_236 - start) * .786)

// Plot Lines - - - - - - - - - - - - - - - - - - - - 
line_100 = line.new(x1=time[10], y1=level_100, x2=time, y2=level_100, color=close > level_100 ? support_color : resistance_color, width=1, extend=extend.both, xloc=xloc.bar_time)
line_786 = line.new(x1=time[10], y1=level_786, x2=time, y2=level_786, color=close > level_786 ? support_color : resistance_color, width=1, extend=extend.both, xloc=xloc.bar_time)
line_650 = line.new(x1=time[10], y1=level_650, x2=time, y2=level_650, color=close > level_650 ? support_color : resistance_color, width=1, extend=extend.both, xloc=xloc.bar_time)
line_618 = line.new(x1=time[10], y1=level_618, x2=time, y2=level_618, color=close > level_618 ? support_color : resistance_color, width=1, extend=extend.both, xloc=xloc.bar_time)
line_500 = line.new(x1=time[10], y1=level_500, x2=time, y2=level_500, color=close > level_500 ? support_color : resistance_color, width=1, extend=extend.both, xloc=xloc.bar_time)
line_328 = line.new(x1=time[10], y1=level_382, x2=time, y2=level_382, color=close > level_382 ? support_color : resistance_color, width=1, extend=extend.both, xloc=xloc.bar_time)
line_236 = line.new(x1=time[10], y1=level_236, x2=time, y2=level_236, color=close > level_236 ? support_color : resistance_color, width=1, extend=extend.both, xloc=xloc.bar_time, style=line.style_dashed)
line_000 = line.new(x1=time[10], y1=level_000, x2=time, y2=level_000, color=close > level_000 ? support_color : resistance_color, width=1, extend=extend.both, xloc=xloc.bar_time, style=line.style_dashed)

line_1236 = line.new(x1=time[10], y1=level_1236, x2=time, y2=level_1236, color=close > level_1236 ? support_color : resistance_color, width=1, extend=extend.both, xloc=xloc.bar_time)
line_1328 = line.new(x1=time[10], y1=level_1328, x2=time, y2=level_1328, color=close > level_1328 ? support_color : resistance_color, width=1, extend=extend.both, xloc=xloc.bar_time)
line_1500 = line.new(x1=time[10], y1=level_1500, x2=time, y2=level_1500, color=close > level_1500 ? support_color : resistance_color, width=1, extend=extend.both, xloc=xloc.bar_time)
line_1618 = line.new(x1=time[10], y1=level_1618, x2=time, y2=level_1618, color=close > level_1618 ? support_color : resistance_color, width=1, extend=extend.both, xloc=xloc.bar_time)
line_1786 = line.new(x1=time[10], y1=level_1786, x2=time, y2=level_1786, color=close > level_1786 ? support_color : resistance_color, width=1, extend=extend.both, xloc=xloc.bar_time)

inner_line_236 = line.new(x1=time[10], y1=inner_level_236, x2=time, y2=inner_level_236, color=close > inner_level_236 ? support_color : resistance_color, width=1, extend=extend.both, xloc=xloc.bar_time)
inner_line_328 = line.new(x1=time[10], y1=inner_level_328, x2=time, y2=inner_level_328, color=close > inner_level_328 ? support_color : resistance_color, width=1, extend=extend.both, xloc=xloc.bar_time)
inner_line_500 = line.new(x1=time[10], y1=inner_level_500, x2=time, y2=inner_level_500, color=close > inner_level_500 ? support_color : resistance_color, width=1, extend=extend.both, xloc=xloc.bar_time)
inner_line_618 = line.new(x1=time[10], y1=inner_level_618, x2=time, y2=inner_level_618, color=close > inner_level_618 ? support_color : resistance_color, width=1, extend=extend.both, xloc=xloc.bar_time)
inner_line_650 = line.new(x1=time[10], y1=inner_level_650, x2=time, y2=inner_level_650, color=close > inner_level_650 ? support_color : resistance_color, width=1, extend=extend.both, xloc=xloc.bar_time)
inner_line_786 = line.new(x1=time[10], y1=inner_level_786, x2=time, y2=inner_level_786, color=close > inner_level_786 ? support_color : resistance_color, width=1, extend=extend.both, xloc=xloc.bar_time)

// Label Lines - - - - - - - - - - - - - - - - - - - - 
var label label_100 = na
var label label_786 = na
var label label_650 = na
var label label_618 = na
var label label_500 = na
var label label_382 = na
var label label_236 = na
var label label_000 = na

var label label_1236 = na
var label label_1328 = na
var label label_1500 = na
var label label_1618 = na
var label label_1786 = na

var label inner_label_236 = na
var label inner_label_328 = na
var label inner_label_500 = na
var label inner_label_618 = na
var label inner_label_650 = na
var label inner_label_786 = na

label.delete(label_100)
label.delete(label_786)
label.delete(label_650)
label.delete(label_618)
label.delete(label_500)
label.delete(label_382)
label.delete(label_236)
label.delete(label_000)

label.delete(label_1236)
label.delete(label_1328)
label.delete(label_1500)
label.delete(label_1618)
label.delete(label_1786)

label.delete(inner_label_236)
label.delete(inner_label_328)
label.delete(inner_label_500)
label.delete(inner_label_618)
label.delete(inner_label_650)
label.delete(inner_label_786)

label_100 := label.new(x=bar_index + 20, y=level_100, style=label.style_none, size=size.normal, color=close > level_100 ? support_color : resistance_color, textcolor=close > level_100 ? support_color : resistance_color, text="1.00 | " + str.format("{0,number,currency}", level_100))
label_786 := label.new(x=bar_index + 20, y=level_786, style=label.style_none, size=size.normal, color=close > level_786 ? support_color : resistance_color, textcolor=close > level_786 ? support_color : resistance_color, text=".786 | " + str.format("{0,number,currency}", level_786))
label_650 := label.new(x=bar_index + 20, y=level_650, style=label.style_none, size=size.normal, color=close > level_650 ? support_color : resistance_color, textcolor=close > level_650 ? support_color : resistance_color, text=".650 | " + str.format("{0,number,currency}", level_650))
label_618 := label.new(x=bar_index + 20, y=level_618, style=label.style_none, size=size.normal, color=close > level_618 ? support_color : resistance_color, textcolor=close > level_618 ? support_color : resistance_color, text=".618 | " + str.format("{0,number,currency}", level_618))
label_500 := label.new(x=bar_index + 20, y=level_500, style=label.style_none, size=size.normal, color=close > level_500 ? support_color : resistance_color, textcolor=close > level_500 ? support_color : resistance_color, text=".500 | " + str.format("{0,number,currency}", level_500))
label_382 := label.new(x=bar_index + 20, y=level_382, style=label.style_none, size=size.normal, color=close > level_382 ? support_color : resistance_color, textcolor=close > level_382 ? support_color : resistance_color, text=".382 | " + str.format("{0,number,currency}", level_382))
label_236 := label.new(x=bar_index + 20, y=level_236, style=label.style_none, size=size.normal, color=close > level_236 ? support_color : resistance_color, textcolor=close > level_236 ? support_color : resistance_color, text=".236 | " + str.format("{0,number,currency}", level_236))
label_000 := label.new(x=bar_index + 20, y=level_000, style=label.style_none, size=size.normal, color=close > level_000 ? support_color : resistance_color, textcolor=close > level_000 ? support_color : resistance_color, text="0.00 | " + str.format("{0,number,currency}", level_000))

label_1236 := label.new(x=bar_index + 20, y=level_1236, style=label.style_none, size=size.normal, color=close > level_1236 ? support_color : resistance_color, textcolor=close > level_1236 ? support_color : resistance_color, text="1.236 | " + str.format("{0,number,currency}", level_1236))
label_1328 := label.new(x=bar_index + 20, y=level_1328, style=label.style_none, size=size.normal, color=close > level_1328 ? support_color : resistance_color, textcolor=close > level_1328 ? support_color : resistance_color, text="1.328 | " + str.format("{0,number,currency}", level_1328))
label_1500 := label.new(x=bar_index + 20, y=level_1500, style=label.style_none, size=size.normal, color=close > level_1500 ? support_color : resistance_color, textcolor=close > level_1500 ? support_color : resistance_color, text="1.500 | " + str.format("{0,number,currency}", level_1500))
label_1618 := label.new(x=bar_index + 20, y=level_1618, style=label.style_none, size=size.normal, color=close > level_1618 ? support_color : resistance_color, textcolor=close > level_1618 ? support_color : resistance_color, text="1.618 | " + str.format("{0,number,currency}", level_1618))
label_1786 := label.new(x=bar_index + 20, y=level_1786, style=label.style_none, size=size.normal, color=close > level_1786 ? support_color : resistance_color, textcolor=close > level_1786 ? support_color : resistance_color, text="1.786 | " + str.format("{0,number,currency}", level_1786))

inner_label_236 := label.new(x=bar_index + 20, y=inner_level_236, style=label.style_none, size=size.normal, color=close > inner_level_236 ? support_color : resistance_color, textcolor=close > inner_level_236 ? support_color : resistance_color, text=".236 | " + str.format("{0,number,currency}", inner_level_236))
inner_label_328 := label.new(x=bar_index + 20, y=inner_level_328, style=label.style_none, size=size.normal, color=close > inner_level_328 ? support_color : resistance_color, textcolor=close > inner_level_328 ? support_color : resistance_color, text=".328 | " + str.format("{0,number,currency}", inner_level_328))
inner_label_500 := label.new(x=bar_index + 20, y=inner_level_500, style=label.style_none, size=size.normal, color=close > inner_level_500 ? support_color : resistance_color, textcolor=close > inner_level_500 ? support_color : resistance_color, text=".500 | " + str.format("{0,number,currency}", inner_level_500))
inner_label_618 := label.new(x=bar_index + 20, y=inner_level_618, style=label.style_none, size=size.normal, color=close > inner_level_618 ? support_color : resistance_color, textcolor=close > inner_level_618 ? support_color : resistance_color, text=".618 | " + str.format("{0,number,currency}", inner_level_618))
inner_label_650 := label.new(x=bar_index + 20, y=inner_level_650, style=label.style_none, size=size.normal, color=close > inner_level_650 ? support_color : resistance_color, textcolor=close > inner_level_650 ? support_color : resistance_color, text=".650 | " + str.format("{0,number,currency}", inner_level_650))
inner_label_786 := label.new(x=bar_index + 20, y=inner_level_786, style=label.style_none, size=size.normal, color=close > inner_level_786 ? support_color : resistance_color, textcolor=close > inner_level_786 ? support_color : resistance_color, text=".786 | " + str.format("{0,number,currency}", inner_level_786))
