MA Visualizer
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Satosaur
//@version=5

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>//
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<//
//>_________________________________________________________________________________>>>>>//
//<|\   ____\|\   __  \|\___   ___\\   __  \|\   ____\|\   __  \|\  \|\  \|\   __  \<<<<<//
//>\ \  \___|\ \  \|\  \|___ \  \_\ \  \|\  \ \  \___|\ \  \|\  \ \  \\\  \ \  \|\  \>>>>//
//<<\ \_____  \ \   __  \<<<\ \  \<\ \  \\\  \ \_____  \ \   __  \ \  \\\  \ \   _  _\<<<//
//>>>\|____|\  \ \  \ \  \>>>\ \  \>\ \  \\\  \|____|\  \ \  \ \  \ \  \\\  \ \  \\  \|>>//
//<<<<<____\_\  \ \__\ \__\<<<\ \__\<\ \_______\____\_\  \ \__\ \__\ \_______\ \__\\ _\<<//
//>>>>|\_________\|__|\|__|>>>>\|__|>>\|_______|\_________\|__|\|__|\|_______|\|__|\|__|>//
//<<<<\|_________|<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\|_________|<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<//
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>[@satosaur]>>>>//
//>>>>>>>>>>>>[Donate Bitcoin = bc1qq8r40efa7cqv2w6d0dkn8at3qcgc5gng3mxcda]>>>>>>>>>>>>>>//


//If you like my indicators or use any part of my code, please give credit and consider dontating bitcoin - bc1qq8r40efa7cqv2w6d0dkn8at3qcgc5gng3mxcda
//follow me on twitter @satosaur

indicator(title='MA Visualizer 🌈', overlay=true)

//--- MA Type Calculations ---
MA_Type(source, length, type) =>
     type == 'SMA' ? ta.sma(source, length) :
     type == 'EMA' ? ta.ema(source, length) :
     type == 'RMA' ? ta.rma(source, length) :
     type == 'HMA' ? ta.hma(source, length) :
     type == 'WMA' ? ta.wma(source, length) :
     type == 'VWMA' ? ta.vwma(source, length) :
     type == 'LSMA' ? ta.linreg(source, length, 0) :
     type == 'ALMA' ? ta.alma(source, length, 0.85, 6) : 
     type == 'MEDIAN' ? ta.median(source, length) : na

//--- Inputs ---
MA_Info = "SMA = Simple Moving Average \nEMA = Exponential Moving Average \nRMA = Relative Moving Average \nHMA = Hull Moving Average \nWMA = Weighted Moving Average \nVWMA = Volume-Weighted Moving Average \nLSMA = Least Square Moving Average \nALMA = Arnaud Legoux Moving Average \nMEDIAN = Median Moving Average"
ShowLines = input.bool(false, 'Show MA Lines', inline='options')
ShowVisualizer = input.bool(true, 'Show Visualizer', inline='options')
ShowMA_Labels = input.bool(true, 'Show MA Labels', inline='options')
AltCol = input.string('Green/Red', 'Color Selection', inline='options2', options=['Green/Red', 'Blue/Purple', 'Yellow/Pink', 'Pastel','Rainbow', 'Blue', 'Grey'], tooltip=MA_Info)
//MA 1 
showMA1 = input.bool(true, 'MA 1', inline='MA 1')
MA1_type = input.string('EMA', '', inline='MA 1', options=['SMA', 'EMA', 'RMA', 'HMA', 'WMA', 'VWMA', 'LSMA', 'ALMA', 'MEDIAN'])
len_MA1 = input.int(14, '', minval=1, inline='MA 1')
src_MA1 = input.source(close, '', inline='MA 1')
MA1 = MA_Type(src_MA1, len_MA1, MA1_type)
//MA 2
showMA2 = input.bool(true, 'MA 2', inline='MA 2')
MA2_type = input.string('EMA', '', inline='MA 2', options=['SMA', 'EMA', 'RMA', 'HMA', 'WMA', 'VWMA', 'LSMA', 'ALMA', 'MEDIAN'])
len_MA2 = input.int(21, '', minval=1, inline='MA 2')
src_MA2 = input.source(close, '', inline='MA 2')
MA2 = MA_Type(src_MA2, len_MA2, MA2_type)
//MA 3
showMA3 = input.bool(true, 'MA 3', inline='MA 3')
MA3_type = input.string('EMA', '', inline='MA 3', options=['SMA', 'EMA', 'RMA', 'HMA', 'WMA', 'VWMA', 'LSMA', 'ALMA', 'MEDIAN'])
len_MA3 = input.int(50, '', minval=1, inline='MA 3')
src_MA3 = input.source(close, '', inline='MA 3')
MA3 = MA_Type(src_MA3, len_MA3, MA3_type)
//MA 4
showMA4 = input.bool(true, 'MA 4', inline='MA 4')
MA4_type = input.string('EMA', '', inline='MA 4', options=['SMA', 'EMA', 'RMA', 'HMA', 'WMA', 'VWMA', 'LSMA', 'ALMA', 'MEDIAN'])
len_MA4 = input.int(100, '', minval=1, inline='MA 4')
src_MA4 = input.source(close, '', inline='MA 4')
MA4 = MA_Type(src_MA4, len_MA4, MA4_type)
//MA 5
showMA5 = input.bool(true, 'MA 5', inline='MA 5')
MA5_type = input.string('EMA', '', inline='MA 5', options=['SMA', 'EMA', 'RMA', 'HMA', 'WMA', 'VWMA', 'LSMA', 'ALMA', 'MEDIAN'])
len_MA5 = input.int(200, '', minval=1, inline='MA 5')
src_MA5 = input.source(close, '', inline='MA 5')
MA5 = MA_Type(src_MA5, len_MA5, MA5_type)
//--- Crosses
//MA Cross
CrossLabel = input.bool(true, title='Show MA Cross Labels', group="MA Cross Settings", inline='MAC1')
MAC1_type = input.string('EMA', 'MA Cross 1', group="MA Cross Settings", inline='MAC2', options=['SMA', 'EMA', 'RMA', 'HMA', 'WMA', 'VWMA', 'LSMA', 'ALMA', 'MEDIAN'])
len_MAC1 = input.int(50, '', group="MA Cross Settings", inline='MAC2')
src_MAC1 = input.source(close, '', group="MA Cross Settings", inline='MAC2')
MAC1 = MA_Type(src_MAC1, len_MAC1, MAC1_type)
MAC2_type = input.string('EMA', 'MA Cross 2', group="MA Cross Settings", inline='MAC3', options=['SMA', 'EMA', 'RMA', 'HMA', 'WMA', 'VWMA', 'LSMA', 'ALMA', 'MEDIAN'])
len_MAC2 = input.int(200, '', group="MA Cross Settings", inline='MAC3')
src_MAC2 = input.source(close, '', group="MA Cross Settings", inline='MAC3')
MAC2 = MA_Type(src_MAC2, len_MAC2, MAC2_type)
//Visualizer MA
MAV_type = 'EMA'
src_MAV = input(close, 'Visualizer Source', inline='Visualizer', tooltip="If you like this indicator follow me on twitter \n@satosaur \n\nConsider donating bitcoin bc1qq8r40efa7cqv2w6d0dkn8at3qcgc5gng3mxcda")
len_MAV = 1
MAV = MA_Type(src_MAV, len_MAV, MAV_type)

//--- Cross Settings ---
CrossO = ta.crossover(MAC1, MAC2)
CrossU = ta.crossunder(MAC1, MAC2)

//--- Color Palette  ---
WHITE = color.rgb(255,255,255,0)
DarkPigmentGREEN  = color.rgb(0,153,77,0)
MediumBLUE = color.rgb(0,119,179,0)
AwesomeRED = color.rgb(248,32,96,0)
ElectricPURPLE = color.rgb(191,0,230,0)
TurquoiseBLUE = color.rgb(38,198,218,0)
DarkPastelBLUE = color.rgb(119,158,203,0)
DarkPastelPURPLE = color.rgb(150,111,214,0)
PastelGREY = color.rgb(207,207,196,0)
DarkGREY = color.rgb(85,85,85,0)
SapphireBLUE = color.rgb(18,97,128,0)
FluroPINK = color.rgb(255,20,147,0)
ElectricYELLOW = color.rgb(255,255,0)
PaleMAGENTA = color.rgb(249,132,229,0)
CaribbeanGREEN = color.rgb(0,216,160,0)
DimPastelRED = color.rgb(194,59,34,0)

//--- Color Calculations  ---
//Line Colors
Color1 = 
     AltCol == 'Green/Red' ? color.new(DarkPigmentGREEN,60) :
     AltCol == 'Blue/Purple' ? color.new(MediumBLUE,60) : 
     AltCol == 'Yellow/Pink' ? color.new(ElectricYELLOW,60) :
     AltCol == 'Pastel' ? color.new(DarkPastelBLUE,60) : 
     AltCol == 'Blue' ? color.new(TurquoiseBLUE,60) :
     AltCol == 'Grey' ? color.new(PastelGREY,60) :
     color.new(DarkPigmentGREEN,60) 
     // Green Line

Color2 = 
     AltCol == 'Green/Red' ? color.new(AwesomeRED,60) :
     AltCol == 'Blue/Purple' ? color.new(ElectricPURPLE,60) : 
     AltCol == 'Yellow/Pink' ? color.new(FluroPINK,60) :
     AltCol == 'Pastel' ? color.new(DarkPastelPURPLE,60) : 
     AltCol == 'Blue' ? color.new(SapphireBLUE,60) :
     AltCol == 'Grey' ? color.new(DarkGREY,60) :
     color.new(AwesomeRED,60) 
     // Red Line

//Visualizer Colors
VColor1 = 
     AltCol == 'Green/Red' ? color.new(DarkPigmentGREEN,87) : 
     AltCol == 'Blue/Purple' ? color.new(MediumBLUE,87) : 
     AltCol == 'Yellow/Pink' ? color.new(ElectricYELLOW,87) :
     AltCol == 'Pastel' ? color.new(DarkPastelBLUE,87) :  
     AltCol == 'Blue' ? color.new(TurquoiseBLUE,87) :
     AltCol == 'Grey' ? color.new(PastelGREY,85) : na
     // Green Visualizer 

VColor2 = 
     AltCol == 'Green/Red' ? color.new(AwesomeRED,87) : 
     AltCol == 'Blue/Purple' ? color.new(ElectricPURPLE,87) : 
     AltCol == 'Yellow/Pink' ? color.new(FluroPINK,87) :
     AltCol == 'Pastel' ? color.new(DarkPastelPURPLE,87) :  
     AltCol == 'Blue' ? color.new(SapphireBLUE,87) :
     AltCol == 'Grey' ? color.new(DarkGREY,85) : na
     // Red Visualizer 

//Cross Colors
CrossColO =
     AltCol == 'Green/Red' ? color.new(DarkPigmentGREEN,20) :
     AltCol == 'Blue/Purple' ? color.new(MediumBLUE,20) : 
     AltCol == 'Yellow/Pink' ? color.new(ElectricYELLOW,20) :
     AltCol == 'Pastel' ? color.new(DarkPastelBLUE,20) : 
     AltCol == 'Blue' ? color.new(TurquoiseBLUE,20) : 
     AltCol == 'Grey' ? color.new(PastelGREY,20) :
     color.new(DarkPigmentGREEN,20)
     // CrossOver
CrossColU = 
     AltCol == 'Green/Red' ? color.new(AwesomeRED,20) : 
     AltCol == 'Blue/Purple' ? color.new(ElectricPURPLE,20) : 
     AltCol == 'Yellow/Pink' ? color.new(FluroPINK,20) :
     AltCol == 'Pastel' ? color.new(DarkPastelPURPLE,20) : 
     AltCol == 'Blue' ? color.new(SapphireBLUE,20) :
     AltCol == 'Grey' ? color.new(DarkGREY,20) : 
     color.new(AwesomeRED,20)
     // CrossUnder

//--- MA Color Calculations ---
//MA 1
colMA1 = MAV >= MA1 ? AltCol == 'Rainbow' ? color.new(DarkPastelBLUE,60) : Color1 : AltCol == 'Rainbow' ? color.new(DarkPastelPURPLE,60) : Color2
col_MAV1 = MAV >= MA1 ? AltCol == 'Rainbow' ? color.new(DarkPastelBLUE,87) : VColor1 : AltCol == 'Rainbow' ? color.new(DarkPastelPURPLE,87) : VColor2
//MA 2
colMA2 = MAV >= MA2 ? AltCol == 'Rainbow' ? color.new(CaribbeanGREEN,60) : Color1 : AltCol == 'Rainbow' ? color.new(ElectricPURPLE,60) : Color2
col_MAV2 = MAV >= MA2 ? AltCol == 'Rainbow' ? color.new(CaribbeanGREEN,87) : VColor1 : AltCol == 'Rainbow' ? color.new(ElectricPURPLE,87) : VColor2
//MA 3
colMA3 = MAV >= MA3 ? AltCol == 'Rainbow' ? color.new(DarkPigmentGREEN,60) : Color1 : AltCol == 'Rainbow' ? color.new(DimPastelRED,60) : Color2
col_MAV3 = MAV >= MA3 ? AltCol == 'Rainbow' ? color.new(DarkPigmentGREEN,87) : VColor1 : AltCol == 'Rainbow' ? color.new(DimPastelRED,87) : VColor2
//MA 4
colMA4 = MAV >= MA4 ? AltCol == 'Rainbow' ? color.new(SapphireBLUE,60) : Color1 : AltCol == 'Rainbow' ? color.new(AwesomeRED,60) : Color2
col_MAV4 = MAV >= MA4 ? AltCol == 'Rainbow' ? color.new(SapphireBLUE,87) : VColor1 : AltCol == 'Rainbow' ? color.new(AwesomeRED,87) : VColor2
//MA 5
colMA5 = MAV >= MA5 ? AltCol == 'Rainbow' ? color.new(TurquoiseBLUE,60) : Color1 : AltCol == 'Rainbow' ? color.new(PaleMAGENTA,60) : Color2
col_MAV5 = MAV >= MA5 ? AltCol == 'Rainbow' ? color.new(TurquoiseBLUE,87) : VColor1 : AltCol == 'Rainbow' ? color.new(PaleMAGENTA,87) : VColor2

//--- Plots ---
//MA Lines
fill_MAV = plot(ShowVisualizer ? MAV : na, title='Visualizer Line', color=color.new(color.yellow,100), style=plot.style_line, linewidth=1)
fill_MA1 = plot(showMA1 ? MA1 : na, title='MA 1 Line', color=ShowLines ? colMA1 : na, style=plot.style_line, linewidth=1)
fill_MA2 = plot(showMA2 ? MA2 : na, title='MA 2 Line', color=ShowLines ? colMA2 : na, style=plot.style_line, linewidth=1)
fill_MA3 = plot(showMA3 ? MA3 : na, title='MA 3 Line', color=ShowLines ? colMA3 : na, style=plot.style_line, linewidth=2)
fill_MA4 = plot(showMA4 ? MA4 : na, title='MA 4 Line', color=ShowLines ? colMA4 : na, style=plot.style_line, linewidth=3)
fill_MA5 = plot(showMA5 ? MA5 : na, title='MA 5 Line', color=ShowLines ? colMA5 : na, style=plot.style_line, linewidth=4)
//MA Visualizer 
fill(fill_MAV, fill_MA1, title='MA 1 Visualizer', color=col_MAV1)
fill(fill_MAV, fill_MA2, title='MA 2 Visualizer', color=col_MAV2)
fill(fill_MAV, fill_MA3, title='MA 3 Visualizer', color=col_MAV3)
fill(fill_MAV, fill_MA4, title='MA 4 Visualizer', color=col_MAV4)
fill(fill_MAV, fill_MA5, title='MA 5 Visualizer', color=col_MAV5) 
//MA Cross
plotshape(CrossLabel ? CrossO : na,  text="MA\nCrossover", color=CrossColO, textcolor=WHITE, style=shape.labelup, size=size.tiny, location=location.belowbar,editable=false)
plotshape(CrossLabel ? CrossU : na,  text="MA\nCrossunder", color=CrossColU, textcolor=WHITE, style=shape.labeldown, size=size.tiny, location=location.abovebar,editable=false)

//MA Labels
MA1Label = label.new(showMA1 and ShowMA_Labels ? bar_index : na, text=str.tostring(len_MA1, '###,### ') + str.tostring(MA1_type), color= close > MA1 ? Color1 : Color2, textcolor=WHITE, style=label.style_text_outline, size=size.small, y=MA1)
label.delete(MA1Label[1])
MA2Label = label.new(showMA2 and ShowMA_Labels ? bar_index : na, text=str.tostring(len_MA2, '###,### ') + str.tostring(MA2_type), color= close > MA2 ? Color1 : Color2, textcolor=WHITE, style=label.style_text_outline, size=size.small, y=MA2)
label.delete(MA2Label[1])
MA3Label = label.new(showMA3 and ShowMA_Labels ? bar_index : na, text=str.tostring(len_MA3, '###,### ') + str.tostring(MA3_type), color= close > MA3 ? Color1 : Color2, textcolor=WHITE, style=label.style_text_outline, size=size.small, y=MA3)
label.delete(MA3Label[1])
MA4Label = label.new(showMA4 and ShowMA_Labels ? bar_index : na, text=str.tostring(len_MA4, '###,### ') + str.tostring(MA4_type), color= close > MA4 ? Color1 : Color2, textcolor=WHITE, style=label.style_text_outline, size=size.small, y=MA4)
label.delete(MA4Label[1])
MA5Label = label.new(showMA5 and ShowMA_Labels ? bar_index : na, text=str.tostring(len_MA5, '###,### ') + str.tostring(MA5_type), color= close > MA5 ? Color1 : Color2, textcolor=WHITE, style=label.style_text_outline, size=size.small, y=MA5)
label.delete(MA5Label[1])