indicator · on price · open source
Fibonacci Extension
Running…
Loading chart…
About
Auto Fibonacci extension from the last confirmed swing: projects the 0.382, 0.618, 1.0, 1.618 and 2.618 multiples of the swing's range above the swing high for target placement.
- Useful for profit targets once price breaks a swing high.
- 1.618 is the classic 'measured move'; 2.618 is the stretch target.
Source code
//@version=5
indicator("Fibonacci Extension", overlay=true)
swing = input.int(10, "Swing length", minval=2, maxval=50)
h = ta.valuewhen(not na(ta.pivothigh(high, swing, swing)), high[swing], 0)
l = ta.valuewhen(not na(ta.pivotlow(low, swing, swing)), low[swing], 0)
r = h - l
e038 = h + r * 0.382
e062 = h + r * 0.618
e100 = h + r * 1.0
e162 = h + r * 1.618
e262 = h + r * 2.618
p_Ext_0_382 = plot(e038, "Ext 0.382", color=color.purple, style=plot.style_linebr)
p_Ext_0_618 = plot(e062, "Ext 0.618", color=color.purple, style=plot.style_linebr)
p_Ext_1_0 = plot(e100, "Ext 1.0", color=color.purple, style=plot.style_linebr, linewidth=2)
p_Ext_1_618 = plot(e162, "Ext 1.618", color=color.purple, style=plot.style_linebr)
p_Ext_2_618 = plot(e262, "Ext 2.618", color=color.purple, style=plot.style_linebr)
alertcondition(ta.crossover(close, e162), "Hit 1.618", "Close reached the 1.618 extension")
alertcondition(ta.crossover(close, e262), "Hit 2.618", "Close reached the 2.618 extension")
No comments yet.
Sign in to comment.