Code Library / Fibonacci
Pine Script Auto Fibonacci
Auto Fibonacci levels from recent swing.
Language: Pine Script · Category: Fibonacci · Tags: Fibonacci, auto, Pine Script, retracement, TradingView
Source code
//@version=5
indicator("Auto Fib",overlay=true)
lb=input.int(50,"Lookback")
hi=ta.highest(high,lb); lo=ta.lowest(low,lb); r=hi-lo
f382=hi-r*0.382; f500=hi-r*0.5; f618=hi-r*0.618
plot(hi,"0%%",color.red,1,plot.style_stepline)
plot(f382,"38.2%%",color.yellow,1,plot.style_stepline)
plot(f500,"50%%",color.gray,2,plot.style_stepline)
plot(f618,"61.8%%",color.green,2,plot.style_stepline)
plot(lo,"100%%",color.blue,1,plot.style_stepline)
p1=plot(f382,display=display.none); p2=plot(f618,display=display.none)
fill(p1,p2,color.new(color.yellow,90),"Golden Zone")How to use this snippet
This is a building block, not a finished trading system. Paste it into your own Pine Script project, compile it, and test it on a demo account with your broker's real spreads before relying on it. You can convert it to MQL4 or MQL5 with the Pine Script converter.