//@version=5 indicator("Fibonacci Retracement Strategy", overlay
2024-09-28

//@version=5
indicator("Fibonacci Retracement Strategy", overlay=true)

// Input Parameters
emaShort = ta.ema(close, 9)
emaLong = ta.ema(close, 21)
rsi = ta.rsi(close, 14)

// Fibonacci Levels
var float fibLevel1 = na
var float fibLevel2 = na
var float fibLevel3 = na

// Identify recent high and low
highLevel = ta.highest(high, 50)
lowLevel = ta.lowest(low, 50)

// Calculate Fibonacci Levels
fibLevel1 := lowLevel + (highLevel - lowLevel) * 0.618
fibLevel2 := lowLevel + (highLevel - lowLevel) * 0.5
fibLevel3 := lowLevel + (highLevel - lowLevel) * 0.382

// Plot Fibonacci Levels
plot(fibLevel1, color=color.green, title="Fib 61.8%")
plot(fibLevel2, color=color.blue, title="Fib 50%")
plot(fibLevel3, color=color.red, title="Fib 38.2%")

// Buy/Sell conditions based on Fib levels
buyCondition = close < fibLevel1 and rsi < 30
sellCondition = close > fibLevel3 and rsi > 70

// Plot Buy/Sell Signals
plotchar(buyCondition, title="Buy", char='B', location=location.belowbar, color=color.green, size=size.small)
plotchar(sellCondition, title="Sell", char='S', location=location.abovebar, color=color.red, size=size.small)
