Cloud Ribbon ++ by [JohnnySnow]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jmgneves
// Yet Another Ribbon
// Inspired by my favorite EMA  ribbon - "EMA Ribbon [Krypt]" by fskrypt.
// This Ribbon ADD the option to choose the avarage algorithm of the ribbon [ "EMA", "SMA", "VWMA", "WMA", "HMA" ].
// Created also to be more friendly to read along with trendlines and Fibonacci retracements.
// For those like me that NOT use this ribbon to find exact price action but instead, to have a grasp of possible Support/Resistance straight ahead.
// High transparency lines and a configurable color palette for filling the background give the ribbon a look of support/ Resistance cloud Strenght.
// Each MA length, line, and background color can be easily configured.
// Enjoy

//@version=5
indicator(title = "Cloud Ribbon ++ by [JohnnySnow]" , shorttitle = "Cloud Ribbon ++", overlay = true)

algorithm = input.string(defval = "EMA" , title = "Choose an avarage algorithm to apply", options = [ "EMA", "SMA", "VWMA", "WMA", "HMA" ], group =  "🟠 Moving Avarage Type 🟠" )

length_0 = input.int(20, title="EMA 0 length", minval=1,  group =  "🟠 Ribbon's EMA Lengths 🟠")
length_1 = input.int(25, title="EMA 1 length", minval=1,  group =  "🟠 Ribbon's EMA Lengths 🟠")
length_2 = input.int(30, title="EMA 2 length", minval=1,  group =  "🟠 Ribbon's EMA Lengths 🟠")
length_3 = input.int(35, title="EMA 3 length", minval=1,  group =  "🟠 Ribbon's EMA Lengths 🟠")
length_4 = input.int(40, title="EMA 4 length", minval=1,  group =  "🟠 Ribbon's EMA Lengths 🟠")
length_5 = input.int(45, title="EMA 5 length", minval=1,  group =  "🟠 Ribbon's EMA Lengths 🟠")
length_6 = input.int(50, title="EMA 6 length", minval=1,  group =  "🟠 Ribbon's EMA Lengths 🟠")
length_7 = input.int(55, title="EMA 7 length", minval=1,  group =  "🟠 Ribbon's EMA Lengths 🟠")

color_0 = input.color(defval = #90caf9, title = "Color EMA 0",  group =  "🟠 Ribbon's Palette 🟠"  )
color_1 = input.color(defval = #64b5f6, title = "Color EMA 1",  group =  "🟠 Ribbon's Palette 🟠"  ) 
color_2 = input.color(defval = #42a5f5, title = "Color EMA 2",  group =  "🟠 Ribbon's Palette 🟠"  ) 
color_3 = input.color(defval = #2196f3, title = "Color EMA 3",  group =  "🟠 Ribbon's Palette 🟠"  ) 
color_4 = input.color(defval = #1e88e5, title = "Color EMA 4",  group =  "🟠 Ribbon's Palette 🟠"  ) 
color_5 = input.color(defval = #1976d2, title = "Color EMA 5",  group =  "🟠 Ribbon's Palette 🟠"  ) 
color_6 = input.color(defval = #1565c0, title = "Color EMA 6",  group =  "🟠 Ribbon's Palette 🟠"  ) 
color_7 = input.color(defval = #0d47a1, title = "Color EMA 7",  group =  "🟠 Ribbon's Palette 🟠"  ) 

lines_transparency= input.int(100, title="LenesTransparency", minval=0, maxval=100,  group =  "🟠 Ribbon's EMA color Transparency 🟠")
fill_transparency_0 = input.int(85, title="background 0 Transparency", minval=0, maxval=100,  group =  "🟠 Ribbon's EMA color Transparency 🟠")
fill_transparency_1 = input.int(85, title="background 1 Transparency", minval=0, maxval=100,  group =  "🟠 Ribbon's EMA color Transparency 🟠")
fill_transparency_2 = input.int(85, title="background 2 Transparency", minval=0, maxval=100,  group =  "🟠 Ribbon's EMA color Transparency 🟠")
fill_transparency_3 = input.int(85, title="background 3 Transparency", minval=0, maxval=100,  group =  "🟠 Ribbon's EMA color Transparency 🟠")
fill_transparency_4 = input.int(85, title="background 4 Transparency", minval=0, maxval=100,  group =  "🟠 Ribbon's EMA color Transparency 🟠")
fill_transparency_5 = input.int(85, title="background 5 Transparency", minval=0, maxval=100,  group =  "🟠 Ribbon's EMA color Transparency 🟠")
fill_transparency_6 = input.int(85, title="background 6 Transparency", minval=0, maxval=100,  group =  "🟠 Ribbon's EMA color Transparency 🟠")

lines_width = input.int(1, title="Line Width", minval=1,  group =  "🟠 Lines Width 🟠")
last_line_width = input.int(1, title="Line Width", minval=1,  group =  "🟠 Lines Width 🟠")


dropn(src, n) =>
    na(src[n]) ? na : src
src = input(close, "Source", group = "🟠 Source 🟠")
dropCandles = input.int(1, minval=0, title="Drop first N candles")
price = dropn(src, dropCandles)

ta_exec(price, length, ma) => 
    def = switch ma
        "EMA" => ta.ema(price, length )
        "SMA" => ta.sma(price, length )
        "VWMA" => ta.vwma(price, length )
        "WMA" => ta.wma(price, length )
        "HMA" => ta.hma(price, length ) 
        => ta.ema(price, length )

line_plot_0 =plot(ta_exec(price, length_0, algorithm), title="Avarage Length 0", color=color_0, transp=lines_transparency, linewidth=lines_width)
line_plot_1 =plot(ta_exec(price, length_1, algorithm), title="Avarage Length 1", color=color_1, transp=lines_transparency, linewidth=lines_width)
line_plot_2 =plot(ta_exec(price, length_2, algorithm), title="Avarage Length 2", color=color_2, transp=lines_transparency, linewidth=lines_width)
line_plot_3 =plot(ta_exec(price, length_3, algorithm), title="Avarage Length 3", color=color_3, transp=lines_transparency, linewidth=lines_width)
line_plot_4 =plot(ta_exec(price, length_4, algorithm), title="Avarage Length 4", color=color_4, transp=lines_transparency, linewidth=lines_width)
line_plot_5 =plot(ta_exec(price, length_5, algorithm), title="Avarage Length 5", color=color_5, transp=lines_transparency, linewidth=lines_width)
line_plot_6 =plot(ta_exec(price, length_6, algorithm), title="Avarage Length 6", color=color_6, transp=lines_transparency, linewidth=lines_width)
line_plot_7 =plot(ta_exec(price, length_7, algorithm), title="Avarage Length 7", color=color_7, transp=lines_transparency, linewidth=last_line_width)



fill(line_plot_0, line_plot_1, color=color_0,transp=fill_transparency_0)
fill(line_plot_1, line_plot_2, color=color_1,transp=fill_transparency_1)
fill(line_plot_2, line_plot_3, color=color_2,transp=fill_transparency_2)
fill(line_plot_3, line_plot_4, color=color_3,transp=fill_transparency_3)
fill(line_plot_4, line_plot_5, color=color_4,transp=fill_transparency_4)
fill(line_plot_5, line_plot_6, color=color_5,transp=fill_transparency_5)
fill(line_plot_6, line_plot_7, color=color_6,transp=fill_transparency_6)

