//version=5
strategy("Bollinger Bands with Fibonacci Strategy", overlay=true)

// Bollinger Bands settings
length = input(20, title="Bollinger Bands Length")
stdDev = input(2.0, title="Standard Deviation")

basis = ta.sma(close, length)
dev = stdDev * ta.stdev(close, length)
upperBB = basis + dev
lowerBB = basis - dev

// Plot Bollinger Bands
plot(basis, color=color.blue, title="Basis")
plot(upperBB, color=color.red, title="Upper BB")
plot(lowerBB, color=color.green, title="Lower BB")

// Fibonacci Retracement levels
var float fib0 = na
var float fib1 = na
var float fib2 = na
var float fib3 = na
var float fib4 = na

if (bar_index == 0 or close[1] > upperBB) // Adjust to reset on new conditions
fib0 := high
fib1 := high - (high - low) * 0.236
fib2 := high - (high - low) * 0.382
fib3 := high - (high - low) * 0.618
fib4 := low

// Plot Fibonacci levels
line.new(bar_index[1], fib0, bar_index, fib0, color=color.gray)
line.new(bar_index[1], fib1, bar_index, fib1, color=color.gray)
line.new(bar_index[1], fib2, bar_index, fib2, color=color.gray)
line.new(bar_index[1], fib3, bar_index, fib3, color=color.gray)
line.new(bar_index[1], fib4, bar_index, fib4, color=color.gray)

// Buy signal: Price crosses below the lower BB and touches the 0.618 level
longCondition = ta.crossover(close, lowerBB) and close <= fib3
if (longCondition)
strategy.entry("Long", strategy.long)

// Sell signal: Price crosses above the upper BB and touches the 0.236 level
shortCondition = ta.crossunder(close, upperBB) and close >= fib1
if (shortCondition)
strategy.entry("Short", strategy.short)

// Alerts
alertcondition(longCondition, title="Long Alert", message="Long signal triggered")
alertcondition(shortCondition, title="Short Alert", message="Short signal triggered")
Chart Patterns

Penafian