Fibonacci Bollinger Band Cluster
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © PlantFi

//@version=5

indicator(shorttitle="FIB BB Cluster", title="Fibonacci Bollinger Band Cluster", overlay=true, timeframe="", timeframe_gaps=true)
length = input.int(20, minval=1)
src = input(ohlc4, title="Source")

// Fib MA
hfib_ma_3 = ta.ema(high, 3)
hfib_ma_5 = ta.ema(high, 5)
hfib_ma_8 = ta.ema(high, 8)
hfib_ma_13 = ta.ema(high, 13)
hfib_ma_21 = ta.ema(high, 21)
hfib_ma_34 = ta.ema(high, 34)
hfib_ma_55 = ta.ema(high, 55)
hfib_ma_89 = ta.ema(high, 89)
hfib_ma_144 = ta.ema(high, 144)
hfib_ma_233 = ta.ema(high, 233)

fib_high = (hfib_ma_3 + hfib_ma_5 + hfib_ma_8 + hfib_ma_13 + hfib_ma_21 + hfib_ma_34 + hfib_ma_55 + hfib_ma_89 + hfib_ma_144 + hfib_ma_233) / 10
plot(fib_high, linewidth=3, color = (fib_high < close) ? color.green : color.red)

lfib_ma_3 = ta.ema(low, 3)
lfib_ma_5 = ta.ema(low, 5)
lfib_ma_8 = ta.ema(low, 8)
lfib_ma_13 = ta.ema(low, 13)
lfib_ma_21 = ta.ema(low, 21)
lfib_ma_34 = ta.ema(low, 34)
lfib_ma_55 = ta.ema(low, 55)
lfib_ma_89 = ta.ema(low, 89)
lfib_ma_144 = ta.ema(low, 144)
lfib_ma_233 = ta.ema(low, 233)


fib_low = (lfib_ma_3 + lfib_ma_5 + lfib_ma_8 + lfib_ma_13 + lfib_ma_21 + lfib_ma_34 + lfib_ma_55 + lfib_ma_89 + lfib_ma_144 + lfib_ma_233) / 10
plot(fib_low, linewidth=3, color = (fib_low < close) ? color.lime : color.orange)

cfib_ma_3 = ta.ema(ohlc4, 3)
cfib_ma_5 = ta.ema(ohlc4, 5)
cfib_ma_8 = ta.ema(ohlc4, 8)
cfib_ma_13 = ta.ema(ohlc4, 13)
cfib_ma_21 = ta.ema(ohlc4, 21)
cfib_ma_34 = ta.ema(ohlc4, 34)
cfib_ma_55 = ta.ema(ohlc4, 55)
cfib_ma_89 = ta.ema(ohlc4, 89)
cfib_ma_144 = ta.ema(ohlc4, 144)
cfib_ma_233 = ta.ema(ohlc4, 233)

fib_ohlc4 = (cfib_ma_3 + cfib_ma_5 + cfib_ma_8 + cfib_ma_13 + cfib_ma_21 + cfib_ma_34 + cfib_ma_55 + cfib_ma_89 + cfib_ma_144 + cfib_ma_233) / 10
plot(fib_ohlc4, 'FIB_OHLC4', color=color.white, linewidth=4)
// Bands
basis = fib_ohlc4

dev_1 = 1 * ta.stdev(src, length)
dev_2 = 2 * ta.stdev(src, length)
dev_3 = 3 * ta.stdev(src, length)
dev_5 = 5 * ta.stdev(src, length)
dev_8 = 8 * ta.stdev(src, length)

upper_1 = basis + dev_1
upper_2 = basis + dev_2
upper_3 = basis + dev_3
upper_5 = basis + dev_5
upper_8 = basis + dev_8

f_upper = (upper_1 + upper_2 + upper_3 + upper_5 + upper_8) / 5
p_f_upper = plot(f_upper, "Upper", color=color.white, linewidth=4)
plot(upper_1, 'Upper_1', color=color.lime)
plot(upper_2, 'Upper_2', color=color.lime)
plot(upper_3, 'Upper_3', color=color.lime)

lower_1 = basis - dev_1
lower_2 = basis - dev_2
lower_3 = basis - dev_3
lower_5 = basis - dev_5
lower_8 = basis - dev_8

f_lower = (lower_1 + lower_2 + lower_3 + lower_5 + lower_8) / 5
p_f_lower = plot(f_lower, "Lower", color=color.white, linewidth=4)
plot(lower_1, 'Lower_1', color=color.red)
plot(lower_2, 'Lower_2', color=color.red)
plot(lower_3, 'Lower_3', color=color.red)

fill(p_f_upper, p_f_lower, title = "Background", color=color.rgb(33, 150, 243, 95))