RicardoSantos

Nth Fibonacci Number

Binet's Formula to find Nth Fibonacci Number.
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?
//@version=2
study("Nth Fibonacci Number")
//-----------------
//Binet's Formula to solve the Nth Fibonacci Number
f_n_fib(_step) =>
    _phi = 1.618
    _n_phi = 1/_phi
    _return = round(_step >= 0 ? pow(_phi, _step) / sqrt(5) : pow(-_n_phi, _step) / sqrt(5))
//-----------------
step = na(step[1]) ? 1 : n >= f_n_fib(step[1]) ? step[1]+1 : step[1]
current_fib = f_n_fib(step)
plot(title='Fib Time Number', series=current_fib, color=black)