Yes sir, you can definitely do that.
Instead of selecting a timeframe or a time range, we can allow the user to enter the exact candle time. The script can then identify that candle, take its High and Low, and calculate the Fibonacci levels from that range.
For example, if the user enters 09:20:
-Candle Time:
09:20
=> The 09:20 candle’s High and Low will be used as the Fibonacci range.
You can create it using:
//@version=6
indicator("Candle Fibonacci", overlay=true)
candleHour = input.int(9, "Candle Hour")
candleMinute = input.int(20, "Candle Minute")
newDay = ta.change(time("D")) != 0
var float fib0 = na
var float fib236 = na
var float fib382 = na
var float fib500 = na
var float fib618 = na
var float fib786 = na
var float fib100 = na
if newDay
fib0 := na
fib236 := na
fib382 := na
fib500 := na
fib618 := na
fib786 := na
fib100 := na
isTargetCandle = hour == candleHour and minute == candleMinute
if isTargetCandle
rangeHigh = high
rangeLow = low
fibRange = rangeHigh - rangeLow
fib0 := rangeLow
fib236 := rangeLow + fibRange * 0.236
fib382 := rangeLow + fibRange * 0.382
fib500 := rangeLow + fibRange * 0.500
fib618 := rangeLow + fibRange * 0.618
fib786 := rangeLow + fibRange * 0.786
fib100 := rangeHigh
plot(fib0, "0%", color=color.gray)
plot(fib236, "23.6%", color=color.yellow)
plot(fib382, "38.2%", color=color.orange)
plot(fib500, "50%", color=color.blue)
plot(fib618, "61.8%", color=color.green)
plot(fib786, "78.6%", color=color.red)
plot(fib100, "100%", color=color.gray)
-> The user only needs to enter the candle hour and minute.
-> The script identifies that specific candle on the current chart timeframe.
-> The candle’s High and Low become the Fibonacci range.
-> The Fibonacci levels are then plotted for the rest of the day.
=> For example, on a 5-minute chart with the time set to 09:20, the 09:20 candle will be used to calculate the Fibonacci levels.
So thatβs how you can create Fibonacci levels from a specific candle in Pine Script.