LE VAN DO® - Fibonacci Retracement
LE VAN DO® - Fibonacci Retracement
LE VAN DO® - Fibonacci Retracement
™
//Freemium indicators >> https://t.me/eyops
//@version=5
indicator("LE VAN DO® - Fibonacci Retracement 2.0.0. ™", overlay = true,
max_lines_count = 500, max_labels_count = 500)
// Table Style
tablePos = input.string("Hide", "RunUp Statistics Table Location ",
["Hide", "Top Right" , "Middle Right" , "Bottom Right" ,
"Top Center", "Middle Center" , "Bottom Center",
"Top Left" , "Middle Left" , "Bottom Left" ], inline = "1", group
= "Fibonacci Run-Up Historical Statistics Table")
// Line Style
linExt = input.string("None Extend", "Lines ",
["Hide", "Right Extend", "Left Extend", "Both Extend", "None Extend"],
group = "Line & Label Style", inline = "line")
linSty = input.string("________", "",
["________", "-----------", "..........."],
group = "Line & Label Style", inline = "line")
linSiz = input.int(2, "", 1, tooltip = "Line Extend | Line Style | Line Size",
group = "Line & Label Style", inline = "line")
// Label Style
lblPos = input.string("Right", "Labels", ["Hide", "Right"],
group = "Line & Label Style", inline = "label")
lblSty = input.string("Value & Price", "",
["Percent", "Value", "Price", "Percent & Price", "Value & Price"],
group = "Line & Label Style", inline = "label")
lblSiz = input.string("Small", "",
["Auto", "Huge", "Large", "Normal", "Small", "Tiny"],
group = "Line & Label Style", inline = "label",
tooltip = "Label Position | Label Style | Label Size")
// Fibonacci
lastSet = input.bool(true, "Apply Fibonacci Levels to ONLY Last Supertrend
Direction", group = "Fibonacci Levels")
confrim = input.bool(true, "Apply Fibonacci Levels After Confirmed Signal",
group = "Fibonacci Levels")
bgTrans = input.int(85, "Background Transparency", 0, 100, group = "Fibonacci
Levels")
lnTrans = input.int(50, "Line Transparency ", 0, 100, group =
"Fibonacci Levels")
if barstate.isfirst
usValFun(val01, col01, shw01), usValFun(val02, col02, shw02), usValFun(val03,
col03, shw03),
usValFun(val04, col04, shw04), usValFun(val05, col05, shw05), usValFun(val06,
col06, shw06),
usValFun(val07, col07, shw07), usValFun(val08, col08, shw08), usValFun(val09,
col09, shw09),
usValFun(val10, col10, shw10), usValFun(val11, col11, shw11), usValFun(val12,
col12, shw12),
usValFun(val13, col13, shw13), usValFun(val14, col14, shw14), usValFun(val15,
col15, shw15),
usValFun(val16, col16, shw16), usValFun(val17, col17, shw17), usValFun(val18,
col18, shw18),
usValFun(val19, col19, shw19), usValFun(val20, col20, shw20), usValFun(val21,
col21, shw21),
usValFun(val22, col22, shw22), usValFun(val23, col23, shw23), usValFun(val24,
col24, shw24),
inVal = array.new<float>(na)
for i = 0 to array.size(usVal) - 1
array.push(inVal, fibLev(array.get(usVal, i)))
array.sort(inVal, dirc < 1 ? order.ascending : order.descending)
styLine(s) =>
switch s
"..........." => line.style_dotted
"-----------" => line.style_dashed
"________" => line.style_solid
line trnd = na
var trndBr = 0
if array.size(inVal) > 0
if dirc != dirc[1]
if confrim ? barstate.isconfirmed : true
if lastSet
line.delete(trnd[trndBr])
if array.size(labArr) > 0
for i = 0 to array.size(labArr) - 1
label.set_style(array.get(labArr, i),
label.style_label_right)
array.clear(linArr)
array.clear(labArr)
array.unshift(runUp, levFib(close))
trndBr := 0
for i = 0 to array.size(inVal) - 1
if not na(array.get(inVal, i))
linCol = array.get(usCol, array.indexof(usVal,
levFib(array.get(inVal, i))))
// Line
if linExt != "Hide"
array.push(linArr, linFunc(bar_index, array.get(inVal, i),
bar_index, linCol))
if array.size(linArr) > 1
linefill.new(array.get(linArr, array.size(linArr)-2),
array.get(linArr, array.size(linArr)-1),
color.new(linCol, bgTrans))
if trndChk and trndBr == 0
trnd := line.new(bar_index, fibLev(1), bar_index,
super,
xloc.bar_index, extend.none, trndCol,
line.style_dashed, 1)
trndBr := 1
// Label
if lblPos != "Hide"
array.push(labArr, labFun(array.get(inVal, i), linCol))
else
if array.size(runUp) > 0
runUpLast = array.get(runUp, 0)
runUpSrc = dirc == -1 ? high : low
array.set(runUp, 0, runUpLast > levFib(runUpSrc) ? runUpLast :
levFib(runUpSrc))
if array.size(linArr) > 0
for i = 0 to array.size(linArr) - 1
line.set_x2(array.get(linArr, i), bar_index)
if array.size(labArr) > 0
for i = 0 to array.size(labArr) - 1
label.set_x(array.get(labArr, i), bar_index)
if trndChk
line.set_x2(trnd[trndBr], bar_index)
trndBr += 1
plotshape(pltChk and dirc < 0 and dirc != dirc[1] ? super : na, "▲+",
shape.labelup, location.absolute, upCol, 0, "▲+", color.white, display =
display.pane, size = size.small)
plotshape(pltChk and dirc > 0 and dirc != dirc[1] ? super : na, "▼-",
shape.labeldown, location.absolute, dnCol, 0, "▼-", color.white, display =
display.pane, size = size.small)
// Create Table
var tbl = table.new(tablePos != "Hide" ? locNsze(tablePos) : position.top_right, 2,
array.size(usVal) + 8,
frame_width = 1, frame_color = color.new(tBgCol, 100), border_width = 1,
border_color = color.new(tBgCol, 100))
perFib(x) =>
str.contains(lblSty, "Percent") ? str.tostring(x * 100, format.percent) :
str.tostring(x, "#.###")
// Cell Function
cell(col, row, txt, color) =>
table.cell(tbl, col, row, text = txt, text_color = txtCol, bgcolor = color,
text_size = size.small)
// Stats Cells
applyCell(row, des, val) =>
cell(0, row , des, tBgCol), table.merge_cells(tbl, 0, row, 1, row)
cell(0, row +1, val, cBgCol), table.merge_cells(tbl, 0, row +1, 1, row +1)
mtx = matrix.new<float>(array.size(fibVal), 2, 0)
matrix.add_col(mtx, 0, fibVal)
totRunUp = array.size(runUp)
for i = 0 to totRunUp - 1
runup = array.get(runUp, i)
for j = 0 to matrix.rows(mtx) - 1
if not(runup < matrix.get(mtx, j, 0))
matrix.set(mtx, j, 1, matrix.get(mtx, j, 1) + 1)
matrix.set(mtx, j, 2, math.round(matrix.get(mtx, j, 1)/totRunUp *
100, 2))
break
// Table
if array.size(fibVal) > 0
table.clear(tbl, 0, 0, 1, array.size(usVal)+7)
y = 0
cell(0, y, "Historical", tBgCol), table.merge_cells(tbl, 0, 0, 1, 0)
y += 1
for i = 0 to matrix.rows(mtx) - 1
fib = matrix.get(mtx, i, 0)
if fib >= 1
Col = array.get(usCol, array.indexof(usVal, fib))
cell(0, y, perFib(fib) , Col)
cell(1, y, str.tostring(matrix.get(mtx, i, 2), format.percent),
Col)
y+=1
// Separator
table.cell(tbl, 0, y, height = 2), table.merge_cells(tbl, 0, y, 1, y),
y += 1