indicator · on price · open source

Fibonacci Retracement

Deepwick · @deepwickv1Updated 2 Oct 2026▲ 0 users
Running…
Loading chart…

About

Auto Fibonacci retracement drawn from the last confirmed swing high to the last confirmed swing low, with the 0.236, 0.382, 0.5, 0.618 and 0.786 levels plotted as horizontal lines.

  • Updates only when a new swing prints (no repaint).
  • The 0.618 and 0.786 levels are the highest-probability reversal zones for trend retracements.

Source code

//@version=5
indicator("Fibonacci Retracement", overlay=true)
swing = input.int(10, "Swing length", minval=2, maxval=50)
high1 = ta.valuewhen(not na(ta.pivothigh(high, swing, swing)), high[swing], 0)
low1 = ta.valuewhen(not na(ta.pivotlow(low, swing, swing)), low[swing], 0)
range_ = high1 - low1
f236 = low1 + range_ * 0.236
f382 = low1 + range_ * 0.382
f500 = low1 + range_ * 0.5
f618 = low1 + range_ * 0.618
f786 = low1 + range_ * 0.786
p_0_236 = plot(f236, "0.236", color=color.orange, style=plot.style_linebr)
p_0_382 = plot(f382, "0.382", color=color.orange, style=plot.style_linebr)
p_0_5 = plot(f500, "0.5", color=color.yellow, style=plot.style_linebr)
p_0_618 = plot(f618, "0.618", color=color.orange, style=plot.style_linebr)
p_0_786 = plot(f786, "0.786", color=color.orange, style=plot.style_linebr)
alertcondition(ta.crossover(close, f618), "Above 0.618", "Close crossed above the 0.618 fib")
alertcondition(ta.crossunder(close, f382), "Below 0.382", "Close crossed below the 0.382 fib")

Comments

No comments yet.

Sign in to comment.