Moving Average Waves
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © LucasVivien

//@version=4
study("Moving Average Waves", shorttitle="MA Waves", overlay=true, precision=0)

////////////////////////////////////////////////////////////////////////////////
//                                  INPUTS                                    //
////////////////////////////////////////////////////////////////////////////////

Source        = input(title="Source"        , type=input.source , defval=close, group="Source & Type") 
MAtype        = input(title="MA Type"       , type=input.string , defval="EMA", group="Source & Type"        , options=["EMA", "SMA", "HMA", "WMA", "VWMA"])
FirstMAlen    = input(title="Base length"   , type=input.integer, defval=10   , group="Moving Average Length", minval=1, maxval=2000)
SpacingFactor = input(title="Spacing Factor", type=input.integer, defval=1    , group="Moving Average Length", minval=1, maxval=100)
ColorStyle    = input(title="Colors Style"  , type=input.string , defval="A"  , group="Lines Display"        , options=["A", "B", "C", "D", "E", "F", "G"])
MAwidth       = input(title="Width"         , type=input.integer, defval=1    , group="Lines Display"        , minval=1, maxval=20)
MAdisplay     = input(title="# Ploted"      , type=input.integer, defval=20   , group="Lines Display"        , minval=1, maxval=20)
Transp        = input(title="Transparency"  , type=input.integer, defval=30   , group="Lines Display"        , minval=0, maxval=100)


// spacingtype = input(title="Spacing Type Style", type=input.string, defval="Linear", options=["Linear", "logarithmic", "Exponential", "D"], tooltip=""))

////////////////////////////////////////////////////////////////////////////////
//                                  MA LENGHT                                 //
////////////////////////////////////////////////////////////////////////////////

ma1length  = FirstMAlen * SpacingFactor
ma2length  = FirstMAlen * SpacingFactor * 2
ma3length  = FirstMAlen * SpacingFactor * 3
ma4length  = FirstMAlen * SpacingFactor * 4
ma5length  = FirstMAlen * SpacingFactor * 5
ma6length  = FirstMAlen * SpacingFactor * 6
ma7length  = FirstMAlen * SpacingFactor * 7
ma8length  = FirstMAlen * SpacingFactor * 8
ma9length  = FirstMAlen * SpacingFactor * 9
ma10length = FirstMAlen * SpacingFactor * 10
ma11length = FirstMAlen * SpacingFactor * 11
ma12length = FirstMAlen * SpacingFactor * 12
ma13length = FirstMAlen * SpacingFactor * 13
ma14length = FirstMAlen * SpacingFactor * 14
ma15length = FirstMAlen * SpacingFactor * 15
ma16length = FirstMAlen * SpacingFactor * 16
ma17length = FirstMAlen * SpacingFactor * 17
ma18length = FirstMAlen * SpacingFactor * 18
ma19length = FirstMAlen * SpacingFactor * 19
ma20length = FirstMAlen * SpacingFactor * 20


////////////////////////////////////////////////////////////////////////////////
//                                  MA TYPES                                  //
////////////////////////////////////////////////////////////////////////////////

MA1  = ema(Source, ma1length)
MA2  = ema(Source, ma2length)
MA3  = ema(Source, ma3length)
MA4  = ema(Source, ma4length)
MA5  = ema(Source, ma5length)
MA6  = ema(Source, ma6length)
MA7  = ema(Source, ma7length)
MA8  = ema(Source, ma8length)
MA9  = ema(Source, ma9length)
MA10 = ema(Source, ma10length)
MA11 = ema(Source, ma11length)
MA12 = ema(Source, ma12length)
MA13 = ema(Source, ma13length)
MA14 = ema(Source, ma14length)
MA15 = ema(Source, ma15length)
MA16 = ema(Source, ma16length)
MA17 = ema(Source, ma17length)
MA18 = ema(Source, ma18length)
MA19 = ema(Source, ma19length)
MA20 = ema(Source, ma20length)

if MAtype == "SMA"
    MA1  := sma(Source, ma1length)
    MA2  := sma(Source, ma2length)
    MA3  := sma(Source, ma3length)
    MA4  := sma(Source, ma4length)
    MA5  := sma(Source, ma5length)
    MA6  := sma(Source, ma6length)
    MA7  := sma(Source, ma7length)
    MA8  := sma(Source, ma8length)
    MA9  := sma(Source, ma9length)
    MA10 := sma(Source, ma10length)
    MA11 := sma(Source, ma11length)
    MA12 := sma(Source, ma12length)
    MA13 := sma(Source, ma13length)
    MA14 := sma(Source, ma14length)
    MA15 := sma(Source, ma15length)
    MA16 := sma(Source, ma16length)
    MA17 := sma(Source, ma17length)
    MA18 := sma(Source, ma18length)
    MA19 := sma(Source, ma19length)
    MA20 := sma(Source, ma20length)
    
if MAtype == "HMA"
    MA1  := hma(Source, ma1length)
    MA2  := hma(Source, ma2length)
    MA3  := hma(Source, ma3length)
    MA4  := hma(Source, ma4length)
    MA5  := hma(Source, ma5length)
    MA6  := hma(Source, ma6length)
    MA7  := hma(Source, ma7length)
    MA8  := hma(Source, ma8length)
    MA9  := hma(Source, ma9length)
    MA10 := hma(Source, ma10length)
    MA11 := hma(Source, ma11length)
    MA12 := hma(Source, ma12length)
    MA13 := hma(Source, ma13length)
    MA14 := hma(Source, ma14length)
    MA15 := hma(Source, ma15length)
    MA16 := hma(Source, ma16length)
    MA17 := hma(Source, ma17length)
    MA18 := hma(Source, ma18length)
    MA19 := hma(Source, ma19length)
    MA20 := hma(Source, ma20length)
    
if MAtype == "WMA"
    MA1  := wma(Source, ma1length)
    MA2  := wma(Source, ma2length)
    MA3  := wma(Source, ma3length)
    MA4  := wma(Source, ma4length)
    MA5  := wma(Source, ma5length)
    MA6  := wma(Source, ma6length)
    MA7  := wma(Source, ma7length)
    MA8  := wma(Source, ma8length)
    MA9  := wma(Source, ma9length)
    MA10 := wma(Source, ma10length)
    MA11 := wma(Source, ma11length)
    MA12 := wma(Source, ma12length)
    MA13 := wma(Source, ma13length)
    MA14 := wma(Source, ma14length)
    MA15 := wma(Source, ma15length)
    MA16 := wma(Source, ma16length)
    MA17 := wma(Source, ma17length)
    MA18 := wma(Source, ma18length)
    MA19 := wma(Source, ma19length)
    MA20 := wma(Source, ma20length)

if MAtype == "VWMA"
    MA1  := vwma(Source, ma1length)
    MA2  := vwma(Source, ma2length)
    MA3  := vwma(Source, ma3length)
    MA4  := vwma(Source, ma4length)
    MA5  := vwma(Source, ma5length)
    MA6  := vwma(Source, ma6length)
    MA7  := vwma(Source, ma7length)
    MA8  := vwma(Source, ma8length)
    MA9  := vwma(Source, ma9length)
    MA10 := vwma(Source, ma10length)
    MA11 := vwma(Source, ma11length)
    MA12 := vwma(Source, ma12length)
    MA13 := vwma(Source, ma13length)
    MA14 := vwma(Source, ma14length)
    MA15 := vwma(Source, ma15length)
    MA16 := vwma(Source, ma16length)
    MA17 := vwma(Source, ma17length)
    MA18 := vwma(Source, ma18length)
    MA19 := vwma(Source, ma19length)
    MA20 := vwma(Source, ma20length)

////////////////////////////////////////////////////////////////////////////////
//                                MA COLORS                                   //
////////////////////////////////////////////////////////////////////////////////

var ma1color1  = color.rgb(0, 0, 0, Transp)
var ma2color1  = color.rgb(0, 0, 0, Transp)
var ma3color1  = color.rgb(0, 0, 0, Transp)
var ma4color1  = color.rgb(0, 0, 0, Transp)
var ma5color1  = color.rgb(0, 0, 0, Transp)
var ma6color1  = color.rgb(0, 0, 0, Transp)
var ma7color1  = color.rgb(0, 0, 0, Transp)
var ma8color1  = color.rgb(0, 0, 0, Transp)
var ma9color1  = color.rgb(0, 0, 0, Transp)
var ma10color1 = color.rgb(0, 0, 0, Transp)
var ma11color1 = color.rgb(0, 0, 0, Transp)
var ma12color1 = color.rgb(0, 0, 0, Transp)
var ma13color1 = color.rgb(0, 0, 0, Transp)
var ma14color1 = color.rgb(0, 0, 0, Transp)
var ma15color1 = color.rgb(0, 0, 0, Transp)
var ma16color1 = color.rgb(0, 0, 0, Transp)
var ma17color1 = color.rgb(0, 0, 0, Transp)
var ma18color1 = color.rgb(0, 0, 0, Transp)
var ma19color1 = color.rgb(0, 0, 0, Transp)
var ma20color1 = color.rgb(0, 0, 0, Transp)

var ma1color2  = color.rgb(0, 0, 0, Transp)
var ma2color2  = color.rgb(0, 0, 0, Transp)
var ma3color2  = color.rgb(0, 0, 0, Transp)
var ma4color2  = color.rgb(0, 0, 0, Transp)
var ma5color2  = color.rgb(0, 0, 0, Transp)
var ma6color2  = color.rgb(0, 0, 0, Transp)
var ma7color2  = color.rgb(0, 0, 0, Transp)
var ma8color2  = color.rgb(0, 0, 0, Transp)
var ma9color2  = color.rgb(0, 0, 0, Transp)
var ma10color2 = color.rgb(0, 0, 0, Transp)
var ma11color2 = color.rgb(0, 0, 0, Transp)
var ma12color2 = color.rgb(0, 0, 0, Transp)
var ma13color2 = color.rgb(0, 0, 0, Transp)
var ma14color2 = color.rgb(0, 0, 0, Transp)
var ma15color2 = color.rgb(0, 0, 0, Transp)
var ma16color2 = color.rgb(0, 0, 0, Transp)
var ma17color2 = color.rgb(0, 0, 0, Transp)
var ma18color2 = color.rgb(0, 0, 0, Transp)
var ma19color2 = color.rgb(0, 0, 0, Transp)
var ma20color2 = color.rgb(0, 0, 0, Transp)



if ColorStyle == "A"
    ma1color1  := color.rgb(121, 134, 121, Transp)
    ma2color1  := color.rgb(115, 140, 115, Transp)
    ma3color1  := color.rgb(108, 147, 108, Transp)
    ma4color1  := color.rgb(102, 153, 102, Transp)
    ma5color1  := color.rgb(96, 159, 96, Transp)
    ma6color1  := color.rgb(89, 166, 89, Transp)
    ma7color1  := color.rgb(83, 172, 83, Transp)
    ma8color1  := color.rgb(77, 179, 77, Transp)
    ma9color1  := color.rgb(70, 185, 70, Transp)
    ma10color1 := color.rgb(64, 191, 64, Transp)
    ma11color1 := color.rgb(57, 198, 57, Transp)
    ma12color1 := color.rgb(51, 204, 51, Transp)
    ma13color1 := color.rgb(45, 210, 45, Transp)
    ma14color1 := color.rgb(38, 217, 38, Transp)
    ma15color1 := color.rgb(32, 223, 32, Transp)
    ma16color1 := color.rgb(25, 230, 25, Transp)
    ma17color1 := color.rgb(19, 236, 19, Transp)
    ma18color1 := color.rgb(13, 242, 13, Transp)
    ma19color1 := color.rgb(6, 249, 6, Transp)
    ma20color1 := color.rgb(0, 255, 0, Transp)
    
    ma1color2  := color.rgb(134, 121, 121, Transp)
    ma2color2  := color.rgb(140, 115, 115, Transp)
    ma3color2  := color.rgb(147, 108, 108, Transp)
    ma4color2  := color.rgb(153, 102, 102, Transp)
    ma5color2  := color.rgb(159, 96, 96, Transp)
    ma6color2  := color.rgb(166, 89, 89, Transp)
    ma7color2  := color.rgb(172, 83, 83, Transp)
    ma8color2  := color.rgb(179, 77, 77, Transp)
    ma9color2  := color.rgb(185, 70, 70, Transp)
    ma10color2 := color.rgb(191, 64, 64, Transp)
    ma11color2 := color.rgb(198, 57, 57, Transp)
    ma12color2 := color.rgb(204, 51, 51, Transp)
    ma13color2 := color.rgb(210, 45, 45, Transp)
    ma14color2 := color.rgb(217, 38, 38, Transp)
    ma15color2 := color.rgb(223, 32, 32, Transp)
    ma16color2 := color.rgb(230, 25, 25, Transp)
    ma17color2 := color.rgb(236, 19, 19, Transp)
    ma18color2 := color.rgb(242, 13, 13, Transp)
    ma19color2 := color.rgb(249, 6, 6, Transp)
    ma20color2 := color.rgb(255, 0, 0, Transp)


if ColorStyle == "B"
    ma1color1  := color.rgb(202, 255, 202, Transp)
    ma2color1  := color.rgb(182, 255, 182, Transp)
    ma3color1  := color.rgb(162, 255, 162, Transp)
    ma4color1  := color.rgb(142, 255, 142, Transp)
    ma5color1  := color.rgb(122, 255, 122, Transp)
    ma6color1  := color.rgb(102, 255, 102, Transp)
    ma7color1  := color.rgb(77, 255, 77, Transp)
    ma8color1  := color.rgb(51, 255, 51, Transp)
    ma9color1  := color.rgb(26, 255, 26, Transp)
    ma10color1 := color.rgb(0, 255, 0, Transp)
    ma11color1 := color.rgb(0, 230, 0, Transp)
    ma12color1 := color.rgb(0, 204, 0, Transp)
    ma13color1 := color.rgb(0, 179, 0, Transp)
    ma14color1 := color.rgb(0, 153, 0, Transp)
    ma15color1 := color.rgb(0, 138, 0, Transp)
    ma16color1 := color.rgb(0, 123, 0, Transp)
    ma17color1 := color.rgb(0, 108, 0, Transp)
    ma18color1 := color.rgb(0, 93, 0, Transp)
    ma19color1 := color.rgb(0, 78, 0, Transp)
    ma20color1 := color.rgb(0, 63, 0, Transp)
    
    ma1color2  := color.rgb(255, 202, 202, Transp)
    ma2color2  := color.rgb(255, 182, 182, Transp)
    ma3color2  := color.rgb(255, 162, 162, Transp)
    ma4color2  := color.rgb(255, 142, 142, Transp)
    ma5color2  := color.rgb(255, 122, 122, Transp)
    ma6color2  := color.rgb(255, 102, 102, Transp)
    ma7color2  := color.rgb(255, 77, 77, Transp)
    ma8color2  := color.rgb(255, 51, 51, Transp)
    ma9color2  := color.rgb(255, 26, 26, Transp)
    ma10color2 := color.rgb(255, 0, 0, Transp)
    ma11color2 := color.rgb(230, 0, 0, Transp)
    ma12color2 := color.rgb(204, 0, 0, Transp)
    ma13color2 := color.rgb(179, 0, 0, Transp)
    ma14color2 := color.rgb(153, 0, 0, Transp)
    ma15color2 := color.rgb(138, 0, 0, Transp)
    ma16color2 := color.rgb(123, 0, 0, Transp)
    ma17color2 := color.rgb(108, 0, 0, Transp)
    ma18color2 := color.rgb(93, 0, 0, Transp)
    ma19color2 := color.rgb(78, 0, 0, Transp)
    ma20color2 := color.rgb(63, 0, 0, Transp)


if ColorStyle == "C"
    ma1color1  := color.rgb(209, 255, 209, Transp)
    ma2color1  := color.rgb(198, 255, 198, Transp)
    ma3color1  := color.rgb(187, 255, 187, Transp)
    ma4color1  := color.rgb(176, 255, 176, Transp)
    ma5color1  := color.rgb(165, 255, 165, Transp)
    ma6color1  := color.rgb(154, 255, 154, Transp)
    ma7color1  := color.rgb(143, 255, 143, Transp)
    ma8color1  := color.rgb(132, 255, 132, Transp)
    ma9color1  := color.rgb(121, 255, 121, Transp)
    ma10color1 := color.rgb(110, 255, 110, Transp)
    ma11color1 := color.rgb(99, 255, 99, Transp)
    ma12color1 := color.rgb(88, 255, 88, Transp)
    ma13color1 := color.rgb(77, 255, 77, Transp)
    ma14color1 := color.rgb(66, 255, 66, Transp)
    ma15color1 := color.rgb(55, 255, 55, Transp)
    ma16color1 := color.rgb(44, 255, 44, Transp)
    ma17color1 := color.rgb(33, 255, 33, Transp)
    ma18color1 := color.rgb(22, 255, 22, Transp)
    ma19color1 := color.rgb(11, 255, 11, Transp)
    ma20color1 := color.rgb(0, 255, 0, Transp)
    
    ma1color2  := color.rgb(255, 209, 209, Transp)
    ma2color2  := color.rgb(255, 198, 198, Transp)
    ma3color2  := color.rgb(255, 187, 187, Transp)
    ma4color2  := color.rgb(255, 176, 176, Transp)
    ma5color2  := color.rgb(255, 165, 165, Transp)
    ma6color2  := color.rgb(255, 154, 154, Transp)
    ma7color2  := color.rgb(255, 143, 143, Transp)
    ma8color2  := color.rgb(255, 132, 132, Transp)
    ma9color2  := color.rgb(255, 121, 121, Transp)
    ma10color2 := color.rgb(255, 110, 110, Transp)
    ma11color2 := color.rgb(255, 99, 99, Transp)
    ma12color2 := color.rgb(255, 88, 88, Transp)
    ma13color2 := color.rgb(255, 77, 77, Transp)
    ma14color2 := color.rgb(255, 66, 66, Transp)
    ma15color2 := color.rgb(255, 55, 55, Transp)
    ma16color2 := color.rgb(255, 44, 44, Transp)
    ma17color2 := color.rgb(255, 33, 33, Transp)
    ma18color2 := color.rgb(255, 22, 22, Transp)
    ma19color2 := color.rgb(255, 11, 11, Transp)
    ma20color2 := color.rgb(255, 0, 0, Transp)


if ColorStyle == "D"
    ma1color1  := color.rgb(0, 46, 0, Transp)
    ma2color1  := color.rgb(0, 57, 0, Transp)
    ma3color1  := color.rgb(0, 68, 0, Transp)
    ma4color1  := color.rgb(0, 79, 0, Transp)
    ma5color1  := color.rgb(0, 90, 0, Transp)
    ma6color1  := color.rgb(0, 101, 0, Transp)
    ma7color1  := color.rgb(0, 112, 0, Transp)
    ma8color1  := color.rgb(0, 123, 0, Transp)
    ma9color1  := color.rgb(0, 134, 0, Transp)
    ma10color1 := color.rgb(0, 145, 0, Transp)
    ma11color1 := color.rgb(0, 156, 0, Transp)
    ma12color1 := color.rgb(0, 167, 0, Transp)
    ma13color1 := color.rgb(0, 178, 0, Transp)
    ma14color1 := color.rgb(0, 189, 0, Transp)
    ma15color1 := color.rgb(0, 200, 0, Transp)
    ma16color1 := color.rgb(0, 211, 0, Transp)
    ma17color1 := color.rgb(0, 222, 0, Transp)
    ma18color1 := color.rgb(0, 233, 0, Transp)
    ma19color1 := color.rgb(0, 244, 0, Transp)
    ma20color1 := color.rgb(0, 255, 0, Transp)
    
    ma1color2  := color.rgb(46, 0, 0, Transp)
    ma2color2  := color.rgb(57, 0, 0, Transp)
    ma3color2  := color.rgb(68, 0, 0, Transp)
    ma4color2  := color.rgb(79, 0, 0, Transp)
    ma5color2  := color.rgb(90, 0, 0, Transp)
    ma6color2  := color.rgb(101, 0, 0, Transp)
    ma7color2  := color.rgb(112, 0, 0, Transp)
    ma8color2  := color.rgb(123, 0, 0, Transp)
    ma9color2  := color.rgb(134, 0, 0, Transp)
    ma10color2 := color.rgb(145, 0, 0, Transp)
    ma11color2 := color.rgb(156, 0, 0, Transp)
    ma12color2 := color.rgb(167, 0, 0, Transp)
    ma13color2 := color.rgb(178, 0, 0, Transp)
    ma14color2 := color.rgb(189, 0, 0, Transp)
    ma15color2 := color.rgb(200, 0, 0, Transp)
    ma16color2 := color.rgb(211, 0, 0, Transp)
    ma17color2 := color.rgb(222, 0, 0, Transp)
    ma18color2 := color.rgb(233, 0, 0, Transp)
    ma19color2 := color.rgb(244, 0, 0, Transp)
    ma20color2 := color.rgb(255, 0, 0, Transp)


if ColorStyle == "E"
    ma1color1  := color.rgb(255, 0, 0, Transp)
    ma2color1  := color.rgb(255, 64, 0, Transp)
    ma3color1  := color.rgb(255, 128, 0, Transp)
    ma4color1  := color.rgb(255, 191, 0, Transp)
    ma5color1  := color.rgb(255, 255, 0, Transp)
    ma6color1  := color.rgb(191, 255, 0, Transp)
    ma7color1  := color.rgb(128, 255, 0, Transp)
    ma8color1  := color.rgb(64, 255, 0, Transp)
    ma9color1  := color.rgb(0, 255, 128, Transp)
    ma10color1 := color.rgb(0, 255, 191, Transp)
    ma11color1 := color.rgb(0, 255, 255, Transp)
    ma12color1 := color.rgb(0, 191, 255, Transp)
    ma13color1 := color.rgb(0, 128, 255, Transp)
    ma14color1 := color.rgb(0, 64, 255, Transp)
    ma15color1 := color.rgb(0, 0, 255, Transp)
    ma16color1 := color.rgb(64, 0, 255, Transp)
    ma17color1 := color.rgb(128, 0, 255, Transp)
    ma18color1 := color.rgb(191, 0, 255, Transp)
    ma19color1 := color.rgb(255, 0, 255, Transp)
    ma20color1 := color.rgb(255, 0, 191, Transp)
    
    ma1color2  := color.rgb(255, 0, 0, Transp)
    ma2color2  := color.rgb(255, 64, 0, Transp)
    ma3color2  := color.rgb(255, 128, 0, Transp)
    ma4color2  := color.rgb(255, 191, 0, Transp)
    ma5color2  := color.rgb(255, 255, 0, Transp)
    ma6color2  := color.rgb(191, 255, 0, Transp)
    ma7color2  := color.rgb(128, 255, 0, Transp)
    ma8color2  := color.rgb(64, 255, 0, Transp)
    ma9color2  := color.rgb(0, 255, 128, Transp)
    ma10color2 := color.rgb(0, 255, 191, Transp)
    ma11color2 := color.rgb(0, 255, 255, Transp)
    ma12color2 := color.rgb(0, 191, 255, Transp)
    ma13color2 := color.rgb(0, 128, 255, Transp)
    ma14color2 := color.rgb(0, 64, 255, Transp)
    ma15color2 := color.rgb(0, 0, 255, Transp)
    ma16color2 := color.rgb(64, 0, 255, Transp)
    ma17color2 := color.rgb(128, 0, 255, Transp)
    ma18color2 := color.rgb(191, 0, 255, Transp)
    ma19color2 := color.rgb(255, 0, 255, Transp)
    ma20color2 := color.rgb(255, 0, 191, Transp)


if ColorStyle == "F"
    ma1color1  := color.rgb(243, 243, 243, Transp)
    ma2color1  := color.rgb(231, 231, 231, Transp)
    ma3color1  := color.rgb(219, 219, 219, Transp)
    ma4color1  := color.rgb(207, 207, 207, Transp)
    ma5color1  := color.rgb(195, 195, 195, Transp)
    ma6color1  := color.rgb(183, 183, 183, Transp)
    ma7color1  := color.rgb(171, 171, 171, Transp)
    ma8color1  := color.rgb(159, 159, 159, Transp)
    ma9color1  := color.rgb(147, 147, 147, Transp)
    ma10color1 := color.rgb(135, 135, 135, Transp)
    ma11color1 := color.rgb(123, 123, 123, Transp)
    ma12color1 := color.rgb(111, 111, 111, Transp)
    ma13color1 := color.rgb(99, 99, 99, Transp)
    ma14color1 := color.rgb(87, 87, 87, Transp)
    ma15color1 := color.rgb(75, 75, 75, Transp)
    ma16color1 := color.rgb(63, 63, 63, Transp)
    ma17color1 := color.rgb(51, 51, 51, Transp)
    ma18color1 := color.rgb(39, 39, 39, Transp)
    ma19color1 := color.rgb(27, 27, 27, Transp)
    ma20color1 := color.rgb(15, 15, 15, Transp)
    
    ma1color2  := color.rgb(243, 243, 243, Transp)
    ma2color2  := color.rgb(231, 231, 231, Transp)
    ma3color2  := color.rgb(219, 219, 219, Transp)
    ma4color2  := color.rgb(207, 207, 207, Transp)
    ma5color2  := color.rgb(195, 195, 195, Transp)
    ma6color2  := color.rgb(183, 183, 183, Transp)
    ma7color2  := color.rgb(171, 171, 171, Transp)
    ma8color2  := color.rgb(159, 159, 159, Transp)
    ma9color2  := color.rgb(147, 147, 147, Transp)
    ma10color2 := color.rgb(135, 135, 135, Transp)
    ma11color2 := color.rgb(123, 123, 123, Transp)
    ma12color2 := color.rgb(111, 111, 111, Transp)
    ma13color2 := color.rgb(99, 99, 99, Transp)
    ma14color2 := color.rgb(87, 87, 87, Transp)
    ma15color2 := color.rgb(75, 75, 75, Transp)
    ma16color2 := color.rgb(63, 63, 63, Transp)
    ma17color2 := color.rgb(51, 51, 51, Transp)
    ma18color2 := color.rgb(39, 39, 39, Transp)
    ma19color2 := color.rgb(27, 27, 27, Transp)
    ma20color2 := color.rgb(15, 15, 15, Transp)


if ColorStyle == "G"
    ma1color1  := color.rgb(15, 15, 15, Transp)
    ma2color1  := color.rgb(27, 27, 27, Transp)
    ma3color1  := color.rgb(39, 39, 39, Transp)
    ma4color1  := color.rgb(51, 51, 51, Transp)
    ma5color1  := color.rgb(63, 63, 63, Transp)
    ma6color1  := color.rgb(75, 75, 75, Transp)
    ma7color1  := color.rgb(87, 87, 87, Transp)
    ma8color1  := color.rgb(99, 99, 99, Transp)
    ma9color1  := color.rgb(111, 111, 111, Transp)
    ma10color1 := color.rgb(123, 123, 123, Transp)
    ma11color1 := color.rgb(135, 135, 135, Transp)
    ma12color1 := color.rgb(147, 147, 147, Transp)
    ma13color1 := color.rgb(159, 159, 159, Transp)
    ma14color1 := color.rgb(171, 171, 171, Transp)
    ma15color1 := color.rgb(183, 183, 183, Transp)
    ma16color1 := color.rgb(195, 195, 195, Transp)
    ma17color1 := color.rgb(207, 207, 207, Transp)
    ma18color1 := color.rgb(219, 219, 219, Transp)
    ma19color1 := color.rgb(231, 231, 231, Transp)
    ma20color1 := color.rgb(243, 243, 243, Transp)
    
    ma1color2  := color.rgb(15, 15, 15, Transp)
    ma2color2  := color.rgb(27, 27, 27, Transp)
    ma3color2  := color.rgb(39, 39, 39, Transp)
    ma4color2  := color.rgb(51, 51, 51, Transp)
    ma5color2  := color.rgb(63, 63, 63, Transp)
    ma6color2  := color.rgb(75, 75, 75, Transp)
    ma7color2  := color.rgb(87, 87, 87, Transp)
    ma8color2  := color.rgb(99, 99, 99, Transp)
    ma9color2  := color.rgb(111, 111, 111, Transp)
    ma10color2 := color.rgb(123, 123, 123, Transp)
    ma11color2 := color.rgb(135, 135, 135, Transp)
    ma12color2 := color.rgb(147, 147, 147, Transp)
    ma13color2 := color.rgb(159, 159, 159, Transp)
    ma14color2 := color.rgb(171, 171, 171, Transp)
    ma15color2 := color.rgb(183, 183, 183, Transp)
    ma16color2 := color.rgb(195, 195, 195, Transp)
    ma17color2 := color.rgb(207, 207, 207, Transp)
    ma18color2 := color.rgb(219, 219, 219, Transp)
    ma19color2 := color.rgb(231, 231, 231, Transp)
    ma20color2 := color.rgb(243, 243, 243, Transp)



////////////////////////////////////////////////////////////////////////////////
//                                 MA PLOTS                                   //
////////////////////////////////////////////////////////////////////////////////

plot(MAdisplay >= 1  ? MA1  : na, title="MA1" , color = Source > MA1  ? ma1color1  : ma1color2 , linewidth = MAwidth)
plot(MAdisplay >= 2  ? MA2  : na, title="MA2" , color = Source > MA2  ? ma2color1  : ma2color2 , linewidth = MAwidth)
plot(MAdisplay >= 3  ? MA3  : na, title="MA3" , color = Source > MA3  ? ma3color1  : ma3color2 , linewidth = MAwidth)
plot(MAdisplay >= 4  ? MA4  : na, title="MA4" , color = Source > MA4  ? ma4color1  : ma4color2 , linewidth = MAwidth)
plot(MAdisplay >= 5  ? MA5  : na, title="MA5" , color = Source > MA5  ? ma5color1  : ma5color2 , linewidth = MAwidth)
plot(MAdisplay >= 6  ? MA6  : na, title="MA6" , color = Source > MA6  ? ma6color1  : ma6color2 , linewidth = MAwidth)
plot(MAdisplay >= 7  ? MA7  : na, title="MA7" , color = Source > MA7  ? ma7color1  : ma7color2 , linewidth = MAwidth)
plot(MAdisplay >= 8  ? MA8  : na, title="MA8" , color = Source > MA8  ? ma8color1  : ma8color2 , linewidth = MAwidth)
plot(MAdisplay >= 9  ? MA9  : na, title="MA9" , color = Source > MA9  ? ma9color1  : ma9color2 , linewidth = MAwidth)
plot(MAdisplay >= 10 ? MA10 : na, title="MA10", color = Source > MA10 ? ma10color1 : ma10color2, linewidth = MAwidth)
plot(MAdisplay >= 11 ? MA11 : na, title="MA11", color = Source > MA11 ? ma11color1 : ma11color2, linewidth = MAwidth)
plot(MAdisplay >= 12 ? MA12 : na, title="MA12", color = Source > MA12 ? ma12color1 : ma12color2, linewidth = MAwidth)
plot(MAdisplay >= 13 ? MA13 : na, title="MA13", color = Source > MA13 ? ma13color1 : ma13color2, linewidth = MAwidth)
plot(MAdisplay >= 14 ? MA14 : na, title="MA14", color = Source > MA14 ? ma14color1 : ma14color2, linewidth = MAwidth)
plot(MAdisplay >= 15 ? MA15 : na, title="MA15", color = Source > MA15 ? ma15color1 : ma15color2, linewidth = MAwidth)
plot(MAdisplay >= 16 ? MA16 : na, title="MA16", color = Source > MA16 ? ma16color1 : ma16color2, linewidth = MAwidth)
plot(MAdisplay >= 17 ? MA17 : na, title="MA17", color = Source > MA17 ? ma17color1 : ma17color2, linewidth = MAwidth)
plot(MAdisplay >= 18 ? MA18 : na, title="MA18", color = Source > MA18 ? ma18color1 : ma18color2, linewidth = MAwidth)
plot(MAdisplay >= 19 ? MA19 : na, title="MA19", color = Source > MA19 ? ma19color1 : ma19color2, linewidth = MAwidth)
plot(MAdisplay >= 20 ? MA20 : na, title="MA20", color = Source > MA20 ? ma20color1 : ma20color2, linewidth = MAwidth)

L1  = MAdisplay >= 1  ? label.new(bar_index, MA1 , color=color.rgb(0, 0, 0, 100), text=tostring(MAtype) + " " + tostring(ma1length) , textcolor=Source > MA1  ? ma1color1  : ma1color2 , size=size.small, style=label.style_label_left) : na
L2  = MAdisplay >= 2  ? label.new(bar_index, MA2 , color=color.rgb(0, 0, 0, 100), text=tostring(MAtype) + " " + tostring(ma2length) , textcolor=Source > MA2  ? ma2color1  : ma2color2 , size=size.small, style=label.style_label_left) : na
L3  = MAdisplay >= 3  ? label.new(bar_index, MA3 , color=color.rgb(0, 0, 0, 100), text=tostring(MAtype) + " " + tostring(ma3length) , textcolor=Source > MA3  ? ma3color1  : ma3color2 , size=size.small, style=label.style_label_left) : na
L4  = MAdisplay >= 4  ? label.new(bar_index, MA4 , color=color.rgb(0, 0, 0, 100), text=tostring(MAtype) + " " + tostring(ma4length) , textcolor=Source > MA4  ? ma4color1  : ma4color2 , size=size.small, style=label.style_label_left) : na
L5  = MAdisplay >= 5  ? label.new(bar_index, MA5 , color=color.rgb(0, 0, 0, 100), text=tostring(MAtype) + " " + tostring(ma5length) , textcolor=Source > MA5  ? ma5color1  : ma5color2 , size=size.small, style=label.style_label_left) : na
L6  = MAdisplay >= 6  ? label.new(bar_index, MA6 , color=color.rgb(0, 0, 0, 100), text=tostring(MAtype) + " " + tostring(ma6length) , textcolor=Source > MA6  ? ma6color1  : ma6color2 , size=size.small, style=label.style_label_left) : na
L7  = MAdisplay >= 7  ? label.new(bar_index, MA7 , color=color.rgb(0, 0, 0, 100), text=tostring(MAtype) + " " + tostring(ma7length) , textcolor=Source > MA7  ? ma7color1  : ma7color2 , size=size.small, style=label.style_label_left) : na
L8  = MAdisplay >= 8  ? label.new(bar_index, MA8 , color=color.rgb(0, 0, 0, 100), text=tostring(MAtype) + " " + tostring(ma8length) , textcolor=Source > MA8  ? ma8color1  : ma8color2 , size=size.small, style=label.style_label_left) : na
L9  = MAdisplay >= 9  ? label.new(bar_index, MA9 , color=color.rgb(0, 0, 0, 100), text=tostring(MAtype) + " " + tostring(ma9length) , textcolor=Source > MA9  ? ma9color1  : ma9color2 , size=size.small, style=label.style_label_left) : na
L10 = MAdisplay >= 10 ? label.new(bar_index, MA10, color=color.rgb(0, 0, 0, 100), text=tostring(MAtype) + " " + tostring(ma10length), textcolor=Source > MA10 ? ma10color1 : ma10color2, size=size.small, style=label.style_label_left) : na
L11 = MAdisplay >= 11 ? label.new(bar_index, MA11, color=color.rgb(0, 0, 0, 100), text=tostring(MAtype) + " " + tostring(ma11length), textcolor=Source > MA11 ? ma11color1 : ma11color2, size=size.small, style=label.style_label_left) : na
L12 = MAdisplay >= 12 ? label.new(bar_index, MA12, color=color.rgb(0, 0, 0, 100), text=tostring(MAtype) + " " + tostring(ma12length), textcolor=Source > MA12 ? ma12color1 : ma12color2, size=size.small, style=label.style_label_left) : na
L13 = MAdisplay >= 13 ? label.new(bar_index, MA13, color=color.rgb(0, 0, 0, 100), text=tostring(MAtype) + " " + tostring(ma13length), textcolor=Source > MA13 ? ma13color1 : ma13color2, size=size.small, style=label.style_label_left) : na
L14 = MAdisplay >= 14 ? label.new(bar_index, MA14, color=color.rgb(0, 0, 0, 100), text=tostring(MAtype) + " " + tostring(ma14length), textcolor=Source > MA14 ? ma14color1 : ma14color2, size=size.small, style=label.style_label_left) : na
L15 = MAdisplay >= 15 ? label.new(bar_index, MA15, color=color.rgb(0, 0, 0, 100), text=tostring(MAtype) + " " + tostring(ma15length), textcolor=Source > MA15 ? ma15color1 : ma15color2, size=size.small, style=label.style_label_left) : na
L16 = MAdisplay >= 16 ? label.new(bar_index, MA16, color=color.rgb(0, 0, 0, 100), text=tostring(MAtype) + " " + tostring(ma16length), textcolor=Source > MA16 ? ma16color1 : ma16color2, size=size.small, style=label.style_label_left) : na
L17 = MAdisplay >= 17 ? label.new(bar_index, MA17, color=color.rgb(0, 0, 0, 100), text=tostring(MAtype) + " " + tostring(ma17length), textcolor=Source > MA17 ? ma17color1 : ma17color2, size=size.small, style=label.style_label_left) : na
L18 = MAdisplay >= 18 ? label.new(bar_index, MA18, color=color.rgb(0, 0, 0, 100), text=tostring(MAtype) + " " + tostring(ma18length), textcolor=Source > MA18 ? ma18color1 : ma18color2, size=size.small, style=label.style_label_left) : na
L19 = MAdisplay >= 19 ? label.new(bar_index, MA19, color=color.rgb(0, 0, 0, 100), text=tostring(MAtype) + " " + tostring(ma19length), textcolor=Source > MA19 ? ma19color1 : ma19color2, size=size.small, style=label.style_label_left) : na
L20 = MAdisplay >= 20 ? label.new(bar_index, MA20, color=color.rgb(0, 0, 0, 100), text=tostring(MAtype) + " " + tostring(ma20length), textcolor=Source > MA20 ? ma20color1 : ma20color2, size=size.small, style=label.style_label_left) : na

label.delete(L1[1])
label.delete(L2[1])
label.delete(L3[1])
label.delete(L4[1])
label.delete(L5[1])
label.delete(L6[1])
label.delete(L7[1])
label.delete(L8[1])
label.delete(L9[1])
label.delete(L10[1])
label.delete(L11[1])
label.delete(L12[1])
label.delete(L13[1])
label.delete(L14[1])
label.delete(L15[1])
label.delete(L16[1])
label.delete(L17[1])
label.delete(L18[1])
label.delete(L19[1])
label.delete(L20[1])


// USE LOOPS WHEREVER POSSIBLE!


// if ColorStyle == "E"
//     ma1color1  := color.rgb(0, 255, 255, Transp)
//     ma2color1  := color.rgb(0, 191, 255, Transp)
//     ma3color1  := color.rgb(0, 127, 255, Transp)
//     ma4color1  := color.rgb(0, 64, 255, Transp)
//     ma5color1  := color.rgb(0, 0, 255, Transp)
//     ma6color1  := color.rgb(64, 0, 255, Transp)
//     ma7color1  := color.rgb(127, 0, 255, Transp)
//     ma8color1  := color.rgb(191, 0, 255, Transp)
//     ma9color1  := color.rgb(255, 0, 127, Transp)
//     ma10color1 := color.rgb(255, 0, 64, Transp)
//     ma11color1 := color.rgb(255, 0, 0, Transp)
//     ma12color1 := color.rgb(255, 64, 0, Transp)
//     ma13color1 := color.rgb(255, 127, 0, Transp)
//     ma14color1 := color.rgb(255, 191, 0, Transp)
//     ma15color1 := color.rgb(255, 255, 0, Transp)
//     ma16color1 := color.rgb(191, 255, 0, Transp)
//     ma17color1 := color.rgb(127, 255, 0, Transp)
//     ma18color1 := color.rgb(64, 255, 0, Transp)
//     ma19color1 := color.rgb(0, 255, 0, Transp)
//     ma20color1 := color.rgb(0, 255, 64, Transp)


