OPEN-SOURCE SCRIPT
Fibonacci

//version=5
indicator("Fib", overlay = true)
// === INPUTS ===
lineLength = input.int(4, "Line Length (Bars)", minval = 1)
labelSize = input.string("large", "Label Size", options = ["small", "normal", "large"])
// === Session Start (9:30 AM NY time) ===
sessionStart = timestamp("America/New_York", year(time), month(time), dayofmonth(time), 9, 30)
isNewDay = ta.change(time("D")) != 0
inSession = time >= sessionStart
// === Track High/Low from session start ===
var float dayHigh = na
var float dayLow = na
if isNewDay
dayHigh := na
dayLow := na
if inSession
dayHigh := na(dayHigh) ? high : math.max(dayHigh, high)
dayLow := na(dayLow) ? low : math.min(dayLow, low)
// === Fibonacci Levels ===
range1 = dayHigh - dayLow
fib_0 = dayHigh
fib_236 = dayHigh - 0.236 * range1
fib_382 = dayHigh - 0.382 * range1
fib_500 = dayHigh - 0.500 * range1
fib_618 = dayHigh - 0.618 * range1
fib_764 = dayHigh - 0.764 * range1
fib_100 = dayLow
// === Line and Label Handles ===
var line line_0 = na
var line line_236 = na
var line line_382 = na
var line line_500 = na
var line line_618 = na
var line line_764 = na
var line line_100 = na
var label label_0 = na
var label label_236 = na
var label label_382 = na
var label label_500 = na
var label label_618 = na
var label label_764 = na
var label label_100 = na
// === Redraw Conditions ===
justEnteredSession = inSession and na(dayHigh[1])
redrawInterval = 2 // ← Redraw every 2 candles
shouldDraw = inSession and not na(dayHigh) and not na(dayLow) and (justEnteredSession or bar_index % redrawInterval == 0)
if shouldDraw
// Delete old lines and labels
line.delete(line_0)
line.delete(line_236)
line.delete(line_382)
line.delete(line_500)
line.delete(line_618)
line.delete(line_764)
line.delete(line_100)
label.delete(label_0)
label.delete(label_236)
label.delete(label_382)
label.delete(label_500)
label.delete(label_618)
label.delete(label_764)
label.delete(label_100)
// Calculate midpoint of line
int midX = bar_index + lineLength / 1
// Label size
labelSizeEnum = labelSize == "large" ? size.large : labelSize == "normal" ? size.normal : size.small
// === Draw lines and % labels ===
// Uncomment the levels you want to show
// line_0 := line.new(bar_index, fib_0, bar_index + lineLength, fib_0, color = color.white, width = 1)
// label_0 := label.new(midX, fib_0, text = str.tostring(fib_0, format.mintick), xloc = xloc.bar_index, yloc = yloc.price, size = labelSizeEnum, style = label.style_label_left, textcolor = color.white, color = color.new(color.white, 85))
// line_236 := line.new(bar_index, fib_236, bar_index + lineLength, fib_236, color = color.green, width = 1)
// label_236 := label.new(midX, fib_236, text = str.tostring(fib_236, format.mintick), xloc = xloc.bar_index, yloc = yloc.price, size = labelSizeEnum, style = label.style_label_left, textcolor = color.green, color = color.new(color.green, 85))
// line_382 := line.new(bar_index, fib_382, bar_index + lineLength, fib_382, color = color.green, width = 1)
// label_382 := label.new(midX, fib_382, text = str.tostring(fib_382, format.mintick), xloc = xloc.bar_index, yloc = yloc.price, size = labelSizeEnum, style = label.style_label_left, textcolor = color.green, color = color.new(color.green, 85))
line_500 := line.new(bar_index, fib_500, bar_index + lineLength, fib_500, color = color.white, width = 1)
label_500 := label.new(midX, fib_500, text = str.tostring(fib_500, format.mintick), xloc = xloc.bar_index, yloc = yloc.price, size = labelSizeEnum, style = label.style_label_left, textcolor = color.white, color = color.new(color.white, 85))
// line_618 := line.new(bar_index, fib_618, bar_index + lineLength, fib_618, color = color.green, width = 1)
// label_618 := label.new(midX, fib_618, text = str.tostring(fib_618, format.mintick), xloc = xloc.bar_index, yloc = yloc.price, size = labelSizeEnum, style = label.style_label_left, textcolor = color.green, color = color.new(color.green, 85))
// line_764 := line.new(bar_index, fib_764, bar_index + lineLength, fib_764, color = color.green, width = 1)
// label_764 := label.new(midX, fib_764, text = str.tostring(fib_764, format.mintick), xloc = xloc.bar_index, yloc = yloc.price, size = labelSizeEnum, style = label.style_label_left, textcolor = color.green, color = color.new(color.green, 85))
// line_100 := line.new(bar_index, fib_100, bar_index + lineLength, fib_100, color = color.white, width = 1)
// label_100 := label.new(midX, fib_100, text = str.tostring(fib_100, format.mintick), xloc = xloc.bar_index, yloc = yloc.price, size = labelSizeEnum, style = label.style_label_left, textcolor = color.white, color = color.new(color.white, 85))
indicator("Fib", overlay = true)
// === INPUTS ===
lineLength = input.int(4, "Line Length (Bars)", minval = 1)
labelSize = input.string("large", "Label Size", options = ["small", "normal", "large"])
// === Session Start (9:30 AM NY time) ===
sessionStart = timestamp("America/New_York", year(time), month(time), dayofmonth(time), 9, 30)
isNewDay = ta.change(time("D")) != 0
inSession = time >= sessionStart
// === Track High/Low from session start ===
var float dayHigh = na
var float dayLow = na
if isNewDay
dayHigh := na
dayLow := na
if inSession
dayHigh := na(dayHigh) ? high : math.max(dayHigh, high)
dayLow := na(dayLow) ? low : math.min(dayLow, low)
// === Fibonacci Levels ===
range1 = dayHigh - dayLow
fib_0 = dayHigh
fib_236 = dayHigh - 0.236 * range1
fib_382 = dayHigh - 0.382 * range1
fib_500 = dayHigh - 0.500 * range1
fib_618 = dayHigh - 0.618 * range1
fib_764 = dayHigh - 0.764 * range1
fib_100 = dayLow
// === Line and Label Handles ===
var line line_0 = na
var line line_236 = na
var line line_382 = na
var line line_500 = na
var line line_618 = na
var line line_764 = na
var line line_100 = na
var label label_0 = na
var label label_236 = na
var label label_382 = na
var label label_500 = na
var label label_618 = na
var label label_764 = na
var label label_100 = na
// === Redraw Conditions ===
justEnteredSession = inSession and na(dayHigh[1])
redrawInterval = 2 // ← Redraw every 2 candles
shouldDraw = inSession and not na(dayHigh) and not na(dayLow) and (justEnteredSession or bar_index % redrawInterval == 0)
if shouldDraw
// Delete old lines and labels
line.delete(line_0)
line.delete(line_236)
line.delete(line_382)
line.delete(line_500)
line.delete(line_618)
line.delete(line_764)
line.delete(line_100)
label.delete(label_0)
label.delete(label_236)
label.delete(label_382)
label.delete(label_500)
label.delete(label_618)
label.delete(label_764)
label.delete(label_100)
// Calculate midpoint of line
int midX = bar_index + lineLength / 1
// Label size
labelSizeEnum = labelSize == "large" ? size.large : labelSize == "normal" ? size.normal : size.small
// === Draw lines and % labels ===
// Uncomment the levels you want to show
// line_0 := line.new(bar_index, fib_0, bar_index + lineLength, fib_0, color = color.white, width = 1)
// label_0 := label.new(midX, fib_0, text = str.tostring(fib_0, format.mintick), xloc = xloc.bar_index, yloc = yloc.price, size = labelSizeEnum, style = label.style_label_left, textcolor = color.white, color = color.new(color.white, 85))
// line_236 := line.new(bar_index, fib_236, bar_index + lineLength, fib_236, color = color.green, width = 1)
// label_236 := label.new(midX, fib_236, text = str.tostring(fib_236, format.mintick), xloc = xloc.bar_index, yloc = yloc.price, size = labelSizeEnum, style = label.style_label_left, textcolor = color.green, color = color.new(color.green, 85))
// line_382 := line.new(bar_index, fib_382, bar_index + lineLength, fib_382, color = color.green, width = 1)
// label_382 := label.new(midX, fib_382, text = str.tostring(fib_382, format.mintick), xloc = xloc.bar_index, yloc = yloc.price, size = labelSizeEnum, style = label.style_label_left, textcolor = color.green, color = color.new(color.green, 85))
line_500 := line.new(bar_index, fib_500, bar_index + lineLength, fib_500, color = color.white, width = 1)
label_500 := label.new(midX, fib_500, text = str.tostring(fib_500, format.mintick), xloc = xloc.bar_index, yloc = yloc.price, size = labelSizeEnum, style = label.style_label_left, textcolor = color.white, color = color.new(color.white, 85))
// line_618 := line.new(bar_index, fib_618, bar_index + lineLength, fib_618, color = color.green, width = 1)
// label_618 := label.new(midX, fib_618, text = str.tostring(fib_618, format.mintick), xloc = xloc.bar_index, yloc = yloc.price, size = labelSizeEnum, style = label.style_label_left, textcolor = color.green, color = color.new(color.green, 85))
// line_764 := line.new(bar_index, fib_764, bar_index + lineLength, fib_764, color = color.green, width = 1)
// label_764 := label.new(midX, fib_764, text = str.tostring(fib_764, format.mintick), xloc = xloc.bar_index, yloc = yloc.price, size = labelSizeEnum, style = label.style_label_left, textcolor = color.green, color = color.new(color.green, 85))
// line_100 := line.new(bar_index, fib_100, bar_index + lineLength, fib_100, color = color.white, width = 1)
// label_100 := label.new(midX, fib_100, text = str.tostring(fib_100, format.mintick), xloc = xloc.bar_index, yloc = yloc.price, size = labelSizeEnum, style = label.style_label_left, textcolor = color.white, color = color.new(color.white, 85))
오픈 소스 스크립트
진정한 트레이딩뷰 정신에 따라 이 스크립트 작성자는 트레이더가 기능을 검토하고 검증할 수 있도록 오픈소스로 공개했습니다. 작성자에게 찬사를 보냅니다! 무료로 사용할 수 있지만 코드를 다시 게시할 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.
오픈 소스 스크립트
진정한 트레이딩뷰 정신에 따라 이 스크립트 작성자는 트레이더가 기능을 검토하고 검증할 수 있도록 오픈소스로 공개했습니다. 작성자에게 찬사를 보냅니다! 무료로 사용할 수 있지만 코드를 다시 게시할 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.