Madrid EMA Ribbon For ThinkOrSwim

Passytroca

New member
How to Trade with Moving Average Ribbons

Expanding Ribbon: End of a Trend
When moving averages widen and separate (ribbon "expansion"), it signals the potential end of a trend. Moving averages, like magnets, attract each other and will eventually close the gap.

Contracting Ribbon: Trend Change
When moving averages converge (ribbon "contraction"), a trend change might be starting. Shorter-term moving averages converge first, followed by the longer-term ones.

Parallel Ribbon: Strong Trend
Parallel and evenly spaced moving averages indicate a strong trend, showing that all averages are moving in sync.

Monitor Spacing Between Moving Averages
Don't just focus on moving average crossovers or twists. The relative positioning of short-term and long-term moving averages indicates trend direction (down, neutral, up). The spacing between them shows trend strength (weak, neutral, strong).

Here is my contribution. I didn't see this exact indicator on this forum. Thank you all for all your posts.

# 19 EMA Ribbon by Passytroca based on TS original MovAvgExpRibbon.
EMA Change color: if crossed by close (default)
HDqsV82.png


Code:
input price = close;
input baseLength = 10;
input incrementOrMultiplier = 10;
input arithOrGeom1or2 = 1;

plot XMA1;
plot XMA2;
plot XMA3;
plot XMA4;
plot XMA5;
plot XMA6;
plot XMA7;
plot XMA8;
plot XMA9;
plot XMA10;
plot XMA11;
plot XMA12;
plot XMA13;
plot XMA14;
plot XMA15;
plot XMA16;
plot XMA17;
plot XMA18;
plot XMA19;
if (arithOrGeom1or2 == 1)
then {
    XMA1 = ExpAverage(price, baseLength);
    XMA2 = ExpAverage(price, baseLength + 1 * incrementOrMultiplier);
    XMA3 = ExpAverage(price, baseLength + 2 * incrementOrMultiplier);
    XMA4 = ExpAverage(price, baseLength + 3 * incrementOrMultiplier);
    XMA5 = ExpAverage(price, baseLength + 4 * incrementOrMultiplier);
    XMA6 = ExpAverage(price, baseLength + 5 * incrementOrMultiplier);
    XMA7 = ExpAverage(price, baseLength + 6 * incrementOrMultiplier);
    XMA8 = ExpAverage(price, baseLength + 7 * incrementOrMultiplier);
    XMA9 = ExpAverage(price, baseLength + 8 * incrementOrMultiplier);
    XMA10 = ExpAverage(price, baseLength + 9 * incrementOrMultiplier);
    XMA11 = ExpAverage(price, baseLength + 10 * incrementOrMultiplier);
    XMA12 = ExpAverage(price, baseLength + 11 * incrementOrMultiplier);
    XMA13 = ExpAverage(price, baseLength + 12 * incrementOrMultiplier);
    XMA14 = ExpAverage(price, baseLength + 13 * incrementOrMultiplier);
    XMA15 = ExpAverage(price, baseLength + 14 * incrementOrMultiplier);
    XMA16 = ExpAverage(price, baseLength + 15 * incrementOrMultiplier);
    XMA17 = ExpAverage(price, baseLength + 16 * incrementOrMultiplier);
    XMA18 = ExpAverage(price, baseLength + 17 * incrementOrMultiplier);
    XMA19 = ExpAverage(price, baseLength + 18 * incrementOrMultiplier);
} else {
    XMA1 = ExpAverage(price, baseLength);
    XMA2 = ExpAverage(price, baseLength * Power(incrementOrMultiplier, 1));
    XMA3 = ExpAverage(price, baseLength * Power(incrementOrMultiplier, 2));
    XMA4 = ExpAverage(price, baseLength * Power(incrementOrMultiplier, 3));
    XMA5 = ExpAverage(price, baseLength * Power(incrementOrMultiplier, 4));
    XMA6 = ExpAverage(price, baseLength * Power(incrementOrMultiplier, 5));
    XMA7 = ExpAverage(price, baseLength * Power(incrementOrMultiplier, 6));
    XMA8 = ExpAverage(price, baseLength * Power(incrementOrMultiplier, 7));
    XMA9 = ExpAverage(price, baseLength * Power(incrementOrMultiplier, 8));
    XMA10 = ExpAverage(price, baseLength* Power(incrementOrMultiplier, 9));
    XMA11 = ExpAverage(price, baseLength * Power(incrementOrMultiplier, 10));
    XMA12 = ExpAverage(price, baseLength * Power(incrementOrMultiplier, 11));
    XMA13 = ExpAverage(price, baseLength * Power(incrementOrMultiplier, 12));
    XMA14 = ExpAverage(price, baseLength * Power(incrementOrMultiplier, 13));
    XMA15 = ExpAverage(price, baseLength * Power(incrementOrMultiplier, 14));
    XMA16 = ExpAverage(price, baseLength * Power(incrementOrMultiplier, 15));
    XMA17 = ExpAverage(price, baseLength * Power(incrementOrMultiplier, 16));
    XMA18 = ExpAverage(price, baseLength * Power(incrementOrMultiplier, 17));
    XMA19 = ExpAverage(price, baseLength * Power(incrementOrMultiplier, 18));
}



DefineGlobalColor("X1", CreateColor(255, 50, 0));
DefineGlobalColor("X2", CreateColor(255, 60, 0));
DefineGlobalColor("X3", CreateColor(255, 70, 0));
DefineGlobalColor("X4", CreateColor(255, 80, 0));
DefineGlobalColor("X5", CreateColor(255, 90, 0));
DefineGlobalColor("X6", CreateColor(255, 100, 0));
DefineGlobalColor("X7", CreateColor(255, 110, 0));
DefineGlobalColor("X8", CreateColor(255, 120, 0));
DefineGlobalColor("X9", CreateColor(255, 130, 0));
DefineGlobalColor("X10", CreateColor(255, 140, 0));
DefineGlobalColor("X11", CreateColor(255, 150, 0));
DefineGlobalColor("X12", CreateColor(255, 160, 0));
DefineGlobalColor("X13", CreateColor(255, 170, 0));
DefineGlobalColor("X14", CreateColor(255, 180, 0));
DefineGlobalColor("X15", CreateColor(255, 190, 0));
DefineGlobalColor("X16", CreateColor(255, 200, 0));
DefineGlobalColor("X17", CreateColor(255, 210, 0));
DefineGlobalColor("X18", CreateColor(255, 220, 0));
DefineGlobalColor("X19", CreateColor(255, 230, 0));


DefineGlobalColor("Xx1", CreateColor(0, 255, 50));
DefineGlobalColor("Xx2", CreateColor(0, 255, 60));
DefineGlobalColor("Xx3", CreateColor(0, 255, 70));
DefineGlobalColor("Xx4", CreateColor(0, 255, 80));
DefineGlobalColor("Xx5", CreateColor(0, 255, 90));
DefineGlobalColor("Xx6", CreateColor(0, 255,100));
DefineGlobalColor("Xx7", CreateColor(0, 255, 110));
DefineGlobalColor("Xx8", CreateColor(0, 255, 120));
DefineGlobalColor("Xx9", CreateColor(0, 255, 130));
DefineGlobalColor("Xx10", CreateColor(0,255, 140));
DefineGlobalColor("Xx11", CreateColor(0, 255, 150));
DefineGlobalColor("Xx12", CreateColor(0, 255, 160));
DefineGlobalColor("Xx13", CreateColor(0, 255, 170));
DefineGlobalColor("Xx14", CreateColor(0, 255, 180));
DefineGlobalColor("Xx15", CreateColor(0, 255, 190));
DefineGlobalColor("Xx16", CreateColor(0, 255, 200));
DefineGlobalColor("Xx17", CreateColor(0, 255, 210));
DefineGlobalColor("Xx18", CreateColor(0, 255, 220));
DefineGlobalColor("Xx19", CreateColor(0, 255, 230));


XMA1 .AssignValueColor( if Xma1 <= Xma1[1]  then GlobalColor("X1")else GlobalColor("Xx1"));
XMA2 .AssignValueColor( if Xma2 <= Xma2[1]  then GlobalColor("X2")else GlobalColor("Xx2"));
XMA3 .AssignValueColor( if Xma3 <= Xma3[1]  then GlobalColor("X3")else GlobalColor("Xx3"));
XMA4 .AssignValueColor( if Xma4 <= Xma4[1]  then GlobalColor("X4")else GlobalColor("Xx4"));
XMA5 .AssignValueColor( if XMA5 <= XMA5[1]  then GlobalColor("X5")else GlobalColor("Xx5"));
XMA6 .AssignValueColor( if XMA6 <= XMA6[1]  then GlobalColor("X6")else GlobalColor("Xx6"));
XMA7 .AssignValueColor( if XMA7 <= XMA7[1]  then GlobalColor("X7")else GlobalColor("Xx7"));
XMA8 .AssignValueColor( if XMA8 <= XMA8[1]  then GlobalColor("X8")else GlobalColor("Xx8"));
XMA9 .AssignValueColor( if XMA9 <= XMA9[1]  then GlobalColor("X9")else GlobalColor("Xx9"));
XMA10 .AssignValueColor( if XMA10 <= XMA10[1]  then GlobalColor("X10")else GlobalColor("Xx10"));
XMA11 .AssignValueColor( if XMA11 <= XMA11[1]  then GlobalColor("X11")else GlobalColor("Xx11"));
XMA12 .AssignValueColor( if Xma12 <= Xma12[1]  then GlobalColor("X12")else GlobalColor("Xx12"));
XMA13 .AssignValueColor( if Xma13 <= Xma13[1]  then GlobalColor("X13")else GlobalColor("Xx13"));
XMA14 .AssignValueColor( if Xma14 <= Xma14[1]  then GlobalColor("X14")else GlobalColor("Xx14"));
XMA15 .AssignValueColor( if Xma15 <= Xma15[1]  then GlobalColor("X15")else GlobalColor("Xx15"));
XMA16 .AssignValueColor( if Xma16 <= Xma16[1]  then GlobalColor("X16")else GlobalColor("Xx16"));
XMA17 .AssignValueColor( if Xma17 <= Xma17[1]  then GlobalColor("X17")else GlobalColor("Xx17"));
XMA18 .AssignValueColor( if Xma18 <= Xma18[1]  then GlobalColor("X18")else GlobalColor("Xx18"));
XMA19 .AssignValueColor( if Xma19 <= Xma19[1]  then GlobalColor("X19")else GlobalColor("Xx19"));
 
Last edited by a moderator:
The use of the geometric function is completely useless! I tried everything from indices,etf's, large caps, mid caps and everything else that I could think of, I could not get all of the EMA's to plot correctly or be of use to me!
 
This is a version based on a 2 Pole Butterworth Filter that allows for AssignPriceColor
Code:
#Ended up Converting this script I found on TradingView which was called "MMARB" and recreated it in TOS
#http://madridjourneyonws.blogspot.com/

#This plots a moving average ribbon, either exponential or standard.
#This study is best viewed with a dark background.  It provides an easy
#and fast way to determine the trend direction and possible reversals.

# Green : Uptrend. Long trading
# Dark Green : Reentry (buy the dip) or downtrend reversal warning
# Red : Downtrend. Short trading
# Dark Red : Short Reentry (sell the peak) or uptrend reversal warning

# To best determine if this is a reentry point or a trend reversal
# the MMARB (Madrid Moving Average Ribbon Bar) study is used.
# This is the bar located at the bottom.  This bar signals when a
# current trend reentry is found (partially filled with opposite dark color)
# or when a trend reversal is ahead (completely filled with opposite dark color).
#This is to go along with Madrid Ribbons

#Converted/Ported by Xiuying 7/15/2018
#Adjusted to allow for different Ma's by Henry Kaczmarczyk 6/23/24
#Adjusted to allow for various lengths and increments by Henry Kaczmarczyk 6/23/24
#Added Assign Price Color by Henry Kaczmarczyk 6/23/24

Input APC = 0;
Input Price = Close;
input baseLength = 5;
input increment = 5;

def BL = BaseLength;
def BL1 = (BL + (1* increment));
def BL2 = (BL + (2* increment));
def BL3 = (BL + (3* increment));
def BL4 = (BL + (4* increment));
def BL5 = (BL + (5* increment));
def BL6 = (BL + (6* increment));
def BL7 = (BL + (7* increment));
def BL8 = (BL + (8* increment));
def BL9 = (BL + (9* increment));
def BL10 = (BL + (10* increment));
def BL11 = (BL + (11* increment));
def BL12 = (BL + (12* increment));
def BL13 = (BL + (13* increment));
def BL14 = (BL + (14* increment));
def BL15 = (BL + (15* increment));
def BL16 = (BL + (16* increment));
def BL17 = (BL + (17* increment));
def BL18 = (BL + (18* increment));
def BL19 = (BL + (19* increment));

def a12P = exp(-1.414 * 3.14159 / BL);
def b12P = 2 * a12P * Cos(1.414 * 3.14159 / BL);
def coef22P =b12P;
def coef32P = -a12P * a12P;
def coef12P = (1 – b12P + a12P * a12P) / 4;
rec Bma1 = if barNumber() < 3 then Price else coef12P * (Price + 2 * Price[1] + Price[2]) + coef22P * Bma1[1] + coef32P * Bma1[2];

def a12P2 = exp(-1.414 * 3.14159 / BL1);
def b12P2 = 2 * a12P2 * Cos(1.414 * 3.14159 / BL1);
def coef22P2 =b12P2;
def coef32P2 = -a12P2 * a12P2;
def coef12P2 = (1 – b12P2 + a12P2 * a12P2) / 4;
rec Bma2 = if barNumber() < 3 then Price else coef12P2 * (Price + 2 * Price[1] + Price[2]) + coef22P2 * Bma2[1] + coef32P2 * Bma2[2];

def a12P3 = exp(-1.414 * 3.14159 / BL2);
def b12P3 = 2 * a12P3 * Cos(1.414 * 3.14159 / BL2);
def coef22P3 =b12P3;
def coef32P3 = -a12P3 * a12P3;
def coef12P3 = (1 – b12P3 + a12P3 * a12P3) / 4;
rec Bma3 = if barNumber() < 3 then Price else coef12P3 * (Price + 2 * Price[1] + Price[2]) + coef22P3 * Bma3[1] + coef32P3 * Bma3[2];

def a12P4 = exp(-1.414 * 3.14159 / BL3);
def b12P4 = 2 * a12P4 * Cos(1.414 * 3.14159 / BL3);
def coef22P4 =b12P4;
def coef32P4 = -a12P4 * a12P4;
def coef12P4 = (1 – b12P4 + a12P4 * a12P4) / 4;
rec Bma4 = if barNumber() < 3 then Price else coef12P4 * (Price + 2 * Price[1] + Price[2]) + coef22P4 * Bma4[1] + coef32P4 * Bma4[2];

def a12P5 = exp(-1.414 * 3.14159 / BL4);
def b12P5 = 2 * a12P5 * Cos(1.414 * 3.14159 / BL4);
def coef22P5 =b12P5;
def coef32P5 = -a12P5 * a12P5;
def coef12P5 = (1 – b12P5 + a12P5 * a12P5) / 4;
rec Bma5 = if barNumber() < 3 then Price else coef12P5 * (Price + 2 * Price[1] + Price[2]) + coef22P5 * Bma5[1] + coef32P5 * Bma5[2];

def a12P6 = exp(-1.414 * 3.14159 / BL5);
def b12P6 = 2 * a12P6 * Cos(1.414 * 3.14159 / BL5);
def coef22P6 =b12P6;
def coef32P6 = -a12P6 * a12P6;
def coef12P6 = (1 – b12P6 + a12P6 * a12P6) / 4;
rec Bma6 = if barNumber() < 3 then Price else coef12P6 * (Price + 2 * Price[1] + Price[2]) + coef22P6 * Bma6[1] + coef32P6 * Bma6[2];

def a12P7 = exp(-1.414 * 3.14159 / BL6);
def b12P7 = 2 * a12P7 * Cos(1.414 * 3.14159 / BL6);
def coef22P7 =b12P7;
def coef32P7 = -a12P7 * a12P7;
def coef12P7 = (1 – b12P7 + a12P7 * a12P7) / 4;
rec Bma7 = if barNumber() < 3 then Price else coef12P7 * (Price + 2 * Price[1] + Price[2]) + coef22P7 * Bma7[1] + coef32P7 * Bma7[2];

def a12P8 = exp(-1.414 * 3.14159 / BL7);
def b12P8 = 2 * a12P8 * Cos(1.414 * 3.14159 / BL7);
def coef22P8 =b12P8;
def coef32P8 = -a12P8 * a12P8;
def coef12P8 = (1 – b12P8 + a12P8 * a12P8) / 4;
rec Bma8 = if barNumber() < 3 then Price else coef12P8 * (Price + 2 * Price[1] + Price[2]) + coef22P8 * Bma8[1] + coef32P8 * Bma8[2];

def a12P9 = exp(-1.414 * 3.14159 / BL8);
def b12P9 = 2 * a12P9 * Cos(1.414 * 3.14159 / BL8);
def coef22P9 =b12P9;
def coef32P9 = -a12P9 * a12P9;
def coef12P9 = (1 – b12P9 + a12P9 * a12P9) / 4;
rec Bma9 = if barNumber() < 3 then Price else coef12P9 * (Price + 2 * Price[1] + Price[2]) + coef22P9 * Bma9[1] + coef32P9 * Bma9[2];

def a12P10 = exp(-1.414 * 3.14159 / BL9);
def b12P10 = 2 * a12P10 * Cos(1.414 * 3.14159 / BL9);
def coef22P10 =b12P10;
def coef32P10 = -a12P10 * a12P10;
def coef12P10 = (1 – b12P10 + a12P10 * a12P10) / 4;
rec Bma10 = if barNumber() < 3 then Price else coef12P10 * (Price + 2 * Price[1] + Price[2]) + coef22P10 * Bma10[1] + coef32P10 * Bma10[2];

def a12P11 = exp(-1.414 * 3.14159 / BL10);
def b12P11 = 2 * a12P11 * Cos(1.414 * 3.14159 / BL10);
def coef22P11 =b12P11;
def coef32P11 = -a12P11 * a12P11;
def coef12P11 = (1 – b12P11 + a12P11 * a12P11) / 4;
rec Bma11 = if barNumber() < 3 then Price else coef12P11 * (Price + 2 * Price[1] + Price[2]) + coef22P11 * Bma11[1] + coef32P11 * Bma11[2];

def a12P12 = exp(-1.414 * 3.14159 / BL11);
def b12P12 = 2 * a12P12 * Cos(1.414 * 3.14159 / BL11);
def coef22P12 =b12P12;
def coef32P12 = -a12P12 * a12P12;
def coef12P12 = (1 – b12P12 + a12P12 * a12P12) / 4;
rec Bma12 = if barNumber() < 3 then Price else coef12P12 * (Price + 2 * Price[1] + Price[2]) + coef22P12 * Bma12[1] + coef32P12 * Bma12[2];

def a12P13 = exp(-1.414 * 3.14159 / BL12);
def b12P13 = 2 * a12P13 * Cos(1.414 * 3.14159 / BL12);
def coef22P13 =b12P13;
def coef32P13 = -a12P13 * a12P13;
def coef12P13 = (1 – b12P13 + a12P13 * a12P13) / 4;
rec Bma13 = if barNumber() < 3 then Price else coef12P13 * (Price + 2 * Price[1] + Price[2]) + coef22P13 * Bma13[1] + coef32P13 * Bma13[2];

def a12P14 = exp(-1.414 * 3.14159 / BL13);
def b12P14 = 2 * a12P14 * Cos(1.414 * 3.14159 / BL13);
def coef22P14 =b12P14;
def coef32P14 = -a12P14 * a12P14;
def coef12P14 = (1 – b12P14 + a12P14 * a12P14) / 4;
rec Bma14 = if barNumber() < 3 then Price else coef12P14 * (Price + 2 * Price[1] + Price[2]) + coef22P14 * Bma14[1] + coef32P14 * Bma14[2];

def a12P15 = exp(-1.414 * 3.14159 / BL14);
def b12P15 = 2 * a12P15 * Cos(1.414 * 3.14159 / BL14);
def coef22P15 =b12P15;
def coef32P15 = -a12P15 * a12P15;
def coef12P15 = (1 – b12P15 + a12P15 * a12P15) / 4;
rec Bma15 = if barNumber() < 3 then Price else coef12P15 * (Price + 2 * Price[1] + Price[2]) + coef22P15 * Bma15[1] + coef32P15 * Bma15[2];

def a12P16 = exp(-1.414 * 3.14159 / BL15);
def b12P16 = 2 * a12P16 * Cos(1.414 * 3.14159 / BL15);
def coef22P16 =b12P16;
def coef32P16 = -a12P16 * a12P16;
def coef12P16 = (1 – b12P16 + a12P16 * a12P16) / 4;
rec Bma16 = if barNumber() < 3 then Price else coef12P16 * (Price + 2 * Price[1] + Price[2]) + coef22P16 * Bma16[1] + coef32P16 * Bma16[2];

def a12P17 = exp(-1.414 * 3.14159 / BL16);
def b12P17 = 2 * a12P17 * Cos(1.414 * 3.14159 / BL16);
def coef22P17 =b12P17;
def coef32P17 = -a12P17 * a12P17;
def coef12P17 = (1 – b12P17 + a12P17 * a12P17) / 4;
rec Bma17 = if barNumber() < 3 then Price else coef12P17 * (Price + 2 * Price[1] + Price[2]) + coef22P17 * Bma17[1] + coef32P17 * Bma17[2];

def a12P18 = exp(-1.414 * 3.14159 / BL17);
def b12P18 = 2 * a12P18 * Cos(1.414 * 3.14159 / BL17);
def coef22P18 =b12P18;
def coef32P18 = -a12P18 * a12P18;
def coef12P18 = (1 – b12P18 + a12P18 * a12P18) / 4;
rec Bma18 = if barNumber() < 3 then Price else coef12P18 * (Price + 2 * Price[1] + Price[2]) + coef22P18 * Bma18[1] + coef32P18 * Bma18[2];

def a12P19 = exp(-1.414 * 3.14159 / BL18);
def b12P19 = 2 * a12P19 * Cos(1.414 * 3.14159 / BL18);
def coef22P19 =b12P19;
def coef32P19 = -a12P19 * a12P19;
def coef12P19 = (1 – b12P19 + a12P19 * a12P19) / 4;
rec Bma19 = if barNumber() < 3 then Price else coef12P19 * (Price + 2 * Price[1] + Price[2]) + coef22P19 * Bma19[1] + coef32P19 * Bma19[2];

def a12P20 = exp(-1.414 * 3.14159 / BL19);
def b12P20 = 2 * a12P20 * Cos(1.414 * 3.14159 / BL19);
def coef22P20 =b12P20;
def coef32P20 = -a12P20 * a12P20;
def coef12P20 = (1 – b12P20 + a12P20 * a12P20) / 4;
rec Bma20 = if barNumber() < 3 then Price else coef12P20 * (Price + 2 * Price[1] + Price[2]) + coef22P20 * Bma20[1] + coef32P20 * Bma20[2];

Plot MA1 = Bma1;
Plot MA2 = Bma2;
Plot MA3 = Bma3;
Plot MA4 = Bma4;
Plot MA5 = Bma5;
Plot MA6 = Bma6;
Plot MA7 = Bma7;
Plot MA8 = Bma8;
Plot MA9 = Bma9;
Plot MA10 = Bma10;
Plot MA11 = Bma11;
Plot MA12 = Bma12;
Plot MA13 = Bma13;
Plot MA14 = Bma14;
Plot MA15 = Bma15;
Plot MA16 = Bma16;
Plot MA17 = Bma17;
Plot MA18 = Bma18;
Plot MA19 = Bma19;
Plot MA20 = Bma20;

ma1.AssignValueColor( if ma1 >= ma1[1] and ma1>ma20 then color.Green  else if ma1 < ma1[1] and ma1>ma20 then color.Dark_Red else if ma1<= ma1[1] and ma1 <ma20 then Color.Red else if ma1 >= ma1[1] and ma1 < ma20 then color.Dark_Green else color.gray);
ma1.hidebubble();

ma2.AssignValueColor(if ma2 >= ma2[1] and ma1>ma20
then color.green  else if ma2 < ma2[1] and ma1>ma20
then color.Dark_Red else if ma2<= ma2[1] and ma1 <ma20
then color.Red else if ma2 >= ma2[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma3.hidebubble();

ma3.AssignValueColor(if ma3 >= ma3[1] and ma1>ma20
then color.green else if ma3 < ma3[1] and ma1>ma20
then color.Dark_Red else if ma3<= ma3[1] and ma1 <ma20
then color.Red else if ma3 >= ma3[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma3.hidebubble();

ma4.AssignValueColor(if ma4 >= ma4[1] and ma1>ma20
then color.Green  else if ma4 < ma4[1] and ma1>ma20
then color.Dark_Red else if ma4<= ma4[1] and ma1 <ma20
then color.Red else if ma4 >= ma4[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma4.hidebubble();

ma5.AssignValueColor(if ma5 >= ma5[1] and ma1>ma20
then color.Green  else if ma5 < ma5[1] and ma1>ma20
then color.Dark_Red else if ma5<= ma5[1] and ma1 <ma20
then color.Red else if ma5 >= ma5[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma5.hidebubble();

ma6.AssignValueColor(if ma6 >= ma6[1] and ma1>ma20
then color.Green  else if ma6 < ma6[1] and ma1>ma20
then color.Dark_Red else if ma6<= ma6[1] and ma1 <ma20
then color.Red else if ma6 >= ma6[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma6.hidebubble();

ma7.AssignValueColor(if ma7 >= ma7[1] and ma1>ma20
then color.Green  else if ma7 < ma7[1] and ma1>ma20
then color.Dark_Red else if ma7<= ma7[1] and ma1 <ma20
then color.Red else if ma7 >= ma7[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma7.hidebubble();

ma8.AssignValueColor(if ma8 >= ma8[1] and ma1>ma20
then color.Green  else if ma8 < ma8[1] and ma1>ma20
then color.Dark_Red else if ma8<= ma8[1] and ma1 <ma20
then color.Red else if ma8 >= ma8[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma8.hidebubble();

ma9.AssignValueColor(if ma9 >= ma9[1] and ma1>ma20
then color.Green  else if ma9 < ma9[1] and ma1>ma20
then color.Dark_Red else if ma9<= ma9[1] and ma1 <ma20
then color.Red else if ma9 >= ma9[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma9.hidebubble();

ma10.AssignValueColor(if ma10 >= ma10[1] and ma1>ma20
then color.Green  else if ma10 < ma10[1] and ma1>ma20
then color.Dark_Red else if ma10<= ma10[1] and ma1 <ma20
then color.Red else if ma10 >= ma10[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma10.hidebubble();

ma11.AssignValueColor(if ma11 >= ma11[1] and ma1>ma20
then color.Green  else if ma11 < ma11[1] and ma1>ma20
then color.Dark_Red else if ma11<= ma11[1] and ma1 <ma20
then color.Red else if ma11 >= ma11[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma11.hidebubble();

ma12.AssignValueColor(if ma12 >= ma12[1] and ma1>ma20
then color.Green  else if ma12 < ma12[1] and ma1>ma20
then color.Dark_Red else if ma12<= ma12[1] and ma1 <ma20
then color.Red else if ma12 >= ma12[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma12.hidebubble();

ma13.AssignValueColor(if ma13 >= ma13[1] and ma1>ma20
then color.Green  else if ma13 < ma13[1] and ma1>ma20
then color.Dark_Red else if ma13<= ma13[1] and ma1 <ma20
then color.Red else if ma13 >= ma13[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma13.hidebubble();

ma14.AssignValueColor(if ma14 >= ma14[1] and ma1>ma20
then color.Green  else if ma14 < ma14[1] and ma1>ma20
then color.Dark_Red else if ma14<= ma14[1] and ma1 <ma20
then color.Red else if ma14 >= ma14[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma14.hidebubble();

ma15.AssignValueColor(if ma15 >= ma15[1] and ma1>ma20
then color.Green  else if ma15 < ma15[1] and ma1>ma20
then color.Dark_Red else if ma15<= ma15[1] and ma1 <ma20
then color.Red else if ma15 >= ma15[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma15.hidebubble();

ma16.AssignValueColor(if ma16 >= ma16[1] and ma1>ma20
then color.Green  else if ma16 < ma16[1] and ma1>ma20
then color.Dark_Red else if ma16<= ma16[1] and ma1 <ma20
then color.Red else if ma16 >= ma16[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma16.hidebubble();

ma17.AssignValueColor(if ma17 >= ma17[1] and ma1>ma20
then color.Green  else if ma17 < ma17[1] and ma1>ma20
then color.Dark_Red else if ma17<= ma17[1] and ma1 <ma20
then color.Red else if ma17 >= ma17[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma17.hidebubble();

ma18.AssignValueColor(if ma18 >= ma18[1] and ma1>ma20
then color.Green  else if ma18 < ma18[1] and ma1>ma20
then color.Dark_Red else if ma18<= ma18[1] and ma1 <ma20
then color.Red else if ma18 >= ma18[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma18.hidebubble();

ma19.AssignValueColor(if ma19 >= ma19[1] and ma1>ma20
then color.Green  else if ma19 < ma19[1] and ma1>ma20
then color.Dark_Red else if ma19<= ma19[1] and ma1 <ma20
then color.Red else if ma19 >= ma19[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma19.hidebubble();

ma20.AssignValueColor(if ma20 >= ma20[1] and ma1>ma20
then color.Green  else if ma20 < ma20[1] and ma1>ma20
then color.Dark_Red else if ma20<= ma20[1] and ma1 <ma20
then color.Red else if ma20 >= ma20[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma20.hidebubble();

AssignPriceColor( If APC ==1 && ma1 >= ma1[1] and ma1>ma20 then color.Green  else if APC ==1 && ma1 < ma1[1] and ma1>ma20 then color.Dark_Red else if APC ==1 && ma1<= ma1[1] and ma1 <ma20 then Color.Red else if APC ==1 && ma1 >= ma1[1] and ma1 < ma20 then color.Dark_Green else if APC ==2 && ma2 >= ma2[1] and ma1>ma20 then color.green  else if APC ==2 && ma2 < ma2[1] and ma1>ma20 then color.Dark_Red else if APC ==2 && ma2<= ma2[1] and ma1 <ma20
then color.Red else if APC ==2 && ma2 >= ma2[1] and ma1 < ma20 then color.Dark_Green else
if APC ==3 && ma3 >= ma3[1] and ma1>ma20 then color.green  else if APC ==3 && ma3 < ma3[1] and ma1>ma20 then color.Dark_Red else if APC ==3 && ma3<= ma3[1] and ma1 <ma20
then color.Red else if APC ==3 && ma3 >= ma3[1] and ma1 < ma20 then color.Dark_Green else
if APC ==4 && ma4 >= ma4[1] and ma1>ma20 then color.green  else if APC ==4 && ma4 < ma4[1] and ma1>ma20 then color.Dark_Red else if APC ==4 && ma4<= ma4[1] and ma1 <ma20
then color.Red else if APC ==4 && ma4 >= ma4[1] and ma1 < ma20 then color.Dark_Green else
if APC ==5 && ma5 >= ma5[1] and ma1>ma20 then color.green  else if APC ==5 && ma5 < ma5[1] and ma1>ma20 then color.Dark_Red else if APC ==5 && ma5<= ma5[1] and ma1 <ma20
then color.Red else if APC ==5 && ma5 >= ma5[1] and ma1 < ma20 then color.Dark_Green else
if APC ==6 && ma6 >= ma6[1] and ma1>ma20 then color.green  else if APC ==6 && ma6 < ma6[1] and ma1>ma20 then color.Dark_Red else if APC ==6 && ma6<= ma6[1] and ma1 <ma20
then color.Red else if APC ==6 && ma6 >= ma6[1] and ma1 < ma20 then color.Dark_Green else
if APC ==7 && ma7 >= ma7[1] and ma1>ma20 then color.green  else if APC ==7 && ma7 < ma7[1] and ma1>ma20 then color.Dark_Red else if APC ==7 && ma7<= ma7[1] and ma1 <ma20
then color.Red else if APC ==7 && ma7 >= ma7[1] and ma1 < ma20 then color.Dark_Green else
if APC ==8 && ma8 >= ma8[1] and ma1>ma20 then color.green  else if APC ==8 && ma8 < ma8[1] and ma1>ma20 then color.Dark_Red else if APC ==8 && ma8<= ma8[1] and ma1 <ma20
then color.Red else if APC ==8 && ma8 >= ma8[1] and ma1 < ma20 then color.Dark_Green else
if APC ==9 && ma9 >= ma9[1] and ma1>ma20 then color.green  else if APC ==9 && ma9 < ma9[1] and ma1>ma20 then color.Dark_Red else if APC ==9 && ma9<= ma9[1] and ma1 <ma20
then color.Red else if APC ==9 && ma9 >= ma9[1] and ma1 < ma20 then color.Dark_Green else
if APC ==10 && ma10 >= ma10[1] and ma1>ma20 then color.green  else if APC ==10 && ma10 < ma10[1] and ma1>ma20 then color.Dark_Red else if APC ==10 && ma10<= ma10[1] and ma1 <ma20 then color.Red else if APC ==10 && ma10 >= ma10[1] and ma1 < ma20 then color.Dark_Green else
if APC ==11 && ma11 >= ma11[1] and ma1>ma20 then color.green  else if APC ==11 && ma11 < ma11[1] and ma1>ma20 then color.Dark_Red else if APC ==11 && ma11<= ma11[1] and ma1 <ma20 then color.Red else if APC ==11 && ma11 >= ma11[1] and ma1 < ma20 then color.Dark_Green else
if APC ==12 && ma12 >= ma12[1] and ma1>ma20 then color.green  else if APC ==12 && ma12 < ma12[1] and ma1>ma20 then color.Dark_Red else if APC ==12 && ma12<= ma12[1] and ma1 <ma20 then color.Red else if APC ==12 && ma12 >= ma12[1] and ma1 < ma20 then color.Dark_Green else
if APC ==13 && ma13 >= ma13[1] and ma1>ma20 then color.green  else if APC ==13 && ma13 < ma13[1] and ma1>ma20 then color.Dark_Red else if APC ==13 && ma13<= ma13[1] and ma1 <ma20 then color.Red else if APC ==13 && ma13 >= ma13[1] and ma1 < ma20 then color.Dark_Green else
if APC ==14 && ma14 >= ma14[1] and ma1>ma20 then color.green  else if APC ==14 && ma14 < ma14[1] and ma1>ma20 then color.Dark_Red else if APC ==14 && ma14<= ma14[1] and ma1 <ma20 then color.Red else if APC ==14 && ma14 >= ma14[1] and ma1 < ma20 then color.Dark_Green else
if APC ==15 && ma15 >= ma15[1] and ma1>ma20 then color.green  else if APC ==15 && ma15 < ma15[1] and ma1>ma20 then color.Dark_Red else if APC ==15 && ma15<= ma15[1] and ma1 <ma20 then color.Red else if APC ==15 && ma15 >= ma15[1] and ma1 < ma20 then color.Dark_Green else
if APC ==16 && ma16 >= ma16[1] and ma1>ma20 then color.green  else if APC ==16 && ma16 < ma16[1] and ma1>ma20 then color.Dark_Red else if APC ==16 && ma16<= ma16[1] and ma1 <ma20 then color.Red else if APC ==16 && ma16 >= ma16[1] and ma1 < ma20 then color.Dark_Green else
if APC ==17 && ma17 >= ma17[1] and ma1>ma20 then color.green  else if APC ==17 && ma17 < ma17[1] and ma1>ma20 then color.Dark_Red else if APC ==17 && ma17<= ma17[1] and ma1 <ma20 then color.Red else if APC ==17 && ma17 >= ma17[1] and ma1 < ma20 then color.Dark_Green else
if APC ==18 && ma18 >= ma18[1] and ma1>ma20 then color.green  else if APC ==18 && ma18 < ma18[1] and ma1>ma20 then color.Dark_Red else if APC ==18 && ma18<= ma18[1] and ma1 <ma20 then color.Red else if APC ==18 && ma18 >= ma18[1] and ma1 < ma20 then color.Dark_Green else
if APC ==19 && ma19 >= ma19[1] and ma1>ma20 then color.green  else if APC ==19 && ma19 < ma19[1] and ma1>ma20 then color.Dark_Red else if APC ==19 && ma19<= ma19[1] and ma1 <ma20 then color.Red else if APC ==19 && ma19 >= ma19[1] and ma1 < ma20 then color.Dark_Green else
if APC ==20 && ma20 >= ma20[1] and ma1>ma20 then color.green  else if APC ==20 && ma20 < ma20[1] and ma1>ma20 then color.Dark_Red else if APC ==20 && ma20<= ma20[1] and ma1 <ma20 then color.Red else if APC ==20 && ma20 >= ma20[1] and ma1 < ma20 then color.Dark_Green else Color.Current);
 
This version has a Bollinger Band based off the longest MA, The Bollinger bands have clouds from 30% & 70%
Code:
#Ended up Converting this script I found on TradingView which was called "MMARB" and recreated it in TOS
#http://madridjourneyonws.blogspot.com/

#This plots a moving average ribbon, either exponential or standard.
#This study is best viewed with a dark background.  It provides an easy
#and fast way to determine the trend direction and possible reversals.

# Green : Uptrend. Long trading
# Dark Green : Reentry (buy the dip) or downtrend reversal warning
# Red : Downtrend. Short trading
# Dark Red : Short Reentry (sell the peak) or uptrend reversal warning

# To best determine if this is a reentry point or a trend reversal
# the MMARB (Madrid Moving Average Ribbon Bar) study is used.
# This is the bar located at the bottom.  This bar signals when a
# current trend reentry is found (partially filled with opposite dark color)
# or when a trend reversal is ahead (completely filled with opposite dark color).
#This is to go along with Madrid Ribbons

#Converted/Ported by Xiuying 7/15/2018
#Adjusted to allow for different Ma's by Henry Kaczmarczyk 6/23/24
#Adjusted to allow for various lengths and increments by Henry Kaczmarczyk 6/23/24
#Added Assign Price Color by Henry Kaczmarczyk 6/23/24

Input APC = 0;
Input Price = Close;
input baseLength = 5;
input increment = 5;
Input Displace =0;
Input Num_Dev = 2;

def BL = BaseLength;
def BL1 = (BL + (1* increment));
def BL2 = (BL + (2* increment));
def BL3 = (BL + (3* increment));
def BL4 = (BL + (4* increment));
def BL5 = (BL + (5* increment));
def BL6 = (BL + (6* increment));
def BL7 = (BL + (7* increment));
def BL8 = (BL + (8* increment));
def BL9 = (BL + (9* increment));
def BL10 = (BL + (10* increment));
def BL11 = (BL + (11* increment));
def BL12 = (BL + (12* increment));
def BL13 = (BL + (13* increment));
def BL14 = (BL + (14* increment));
def BL15 = (BL + (15* increment));
def BL16 = (BL + (16* increment));
def BL17 = (BL + (17* increment));
def BL18 = (BL + (18* increment));
def BL19 = (BL + (19* increment));

def a12P = exp(-1.414 * 3.14159 / BL);
def b12P = 2 * a12P * Cos(1.414 * 3.14159 / BL);
def coef22P =b12P;
def coef32P = -a12P * a12P;
def coef12P = (1 – b12P + a12P * a12P) / 4;
rec Bma1 = if barNumber() < 3 then Price else coef12P * (Price + 2 * Price[1] + Price[2]) + coef22P * Bma1[1] + coef32P * Bma1[2];

def a12P2 = exp(-1.414 * 3.14159 / BL1);
def b12P2 = 2 * a12P2 * Cos(1.414 * 3.14159 / BL1);
def coef22P2 =b12P2;
def coef32P2 = -a12P2 * a12P2;
def coef12P2 = (1 – b12P2 + a12P2 * a12P2) / 4;
rec Bma2 = if barNumber() < 3 then Price else coef12P2 * (Price + 2 * Price[1] + Price[2]) + coef22P2 * Bma2[1] + coef32P2 * Bma2[2];

def a12P3 = exp(-1.414 * 3.14159 / BL2);
def b12P3 = 2 * a12P3 * Cos(1.414 * 3.14159 / BL2);
def coef22P3 =b12P3;
def coef32P3 = -a12P3 * a12P3;
def coef12P3 = (1 – b12P3 + a12P3 * a12P3) / 4;
rec Bma3 = if barNumber() < 3 then Price else coef12P3 * (Price + 2 * Price[1] + Price[2]) + coef22P3 * Bma3[1] + coef32P3 * Bma3[2];

def a12P4 = exp(-1.414 * 3.14159 / BL3);
def b12P4 = 2 * a12P4 * Cos(1.414 * 3.14159 / BL3);
def coef22P4 =b12P4;
def coef32P4 = -a12P4 * a12P4;
def coef12P4 = (1 – b12P4 + a12P4 * a12P4) / 4;
rec Bma4 = if barNumber() < 3 then Price else coef12P4 * (Price + 2 * Price[1] + Price[2]) + coef22P4 * Bma4[1] + coef32P4 * Bma4[2];

def a12P5 = exp(-1.414 * 3.14159 / BL4);
def b12P5 = 2 * a12P5 * Cos(1.414 * 3.14159 / BL4);
def coef22P5 =b12P5;
def coef32P5 = -a12P5 * a12P5;
def coef12P5 = (1 – b12P5 + a12P5 * a12P5) / 4;
rec Bma5 = if barNumber() < 3 then Price else coef12P5 * (Price + 2 * Price[1] + Price[2]) + coef22P5 * Bma5[1] + coef32P5 * Bma5[2];

def a12P6 = exp(-1.414 * 3.14159 / BL5);
def b12P6 = 2 * a12P6 * Cos(1.414 * 3.14159 / BL5);
def coef22P6 =b12P6;
def coef32P6 = -a12P6 * a12P6;
def coef12P6 = (1 – b12P6 + a12P6 * a12P6) / 4;
rec Bma6 = if barNumber() < 3 then Price else coef12P6 * (Price + 2 * Price[1] + Price[2]) + coef22P6 * Bma6[1] + coef32P6 * Bma6[2];

def a12P7 = exp(-1.414 * 3.14159 / BL6);
def b12P7 = 2 * a12P7 * Cos(1.414 * 3.14159 / BL6);
def coef22P7 =b12P7;
def coef32P7 = -a12P7 * a12P7;
def coef12P7 = (1 – b12P7 + a12P7 * a12P7) / 4;
rec Bma7 = if barNumber() < 3 then Price else coef12P7 * (Price + 2 * Price[1] + Price[2]) + coef22P7 * Bma7[1] + coef32P7 * Bma7[2];

def a12P8 = exp(-1.414 * 3.14159 / BL7);
def b12P8 = 2 * a12P8 * Cos(1.414 * 3.14159 / BL7);
def coef22P8 =b12P8;
def coef32P8 = -a12P8 * a12P8;
def coef12P8 = (1 – b12P8 + a12P8 * a12P8) / 4;
rec Bma8 = if barNumber() < 3 then Price else coef12P8 * (Price + 2 * Price[1] + Price[2]) + coef22P8 * Bma8[1] + coef32P8 * Bma8[2];

def a12P9 = exp(-1.414 * 3.14159 / BL8);
def b12P9 = 2 * a12P9 * Cos(1.414 * 3.14159 / BL8);
def coef22P9 =b12P9;
def coef32P9 = -a12P9 * a12P9;
def coef12P9 = (1 – b12P9 + a12P9 * a12P9) / 4;
rec Bma9 = if barNumber() < 3 then Price else coef12P9 * (Price + 2 * Price[1] + Price[2]) + coef22P9 * Bma9[1] + coef32P9 * Bma9[2];

def a12P10 = exp(-1.414 * 3.14159 / BL9);
def b12P10 = 2 * a12P10 * Cos(1.414 * 3.14159 / BL9);
def coef22P10 =b12P10;
def coef32P10 = -a12P10 * a12P10;
def coef12P10 = (1 – b12P10 + a12P10 * a12P10) / 4;
rec Bma10 = if barNumber() < 3 then Price else coef12P10 * (Price + 2 * Price[1] + Price[2]) + coef22P10 * Bma10[1] + coef32P10 * Bma10[2];

def a12P11 = exp(-1.414 * 3.14159 / BL10);
def b12P11 = 2 * a12P11 * Cos(1.414 * 3.14159 / BL10);
def coef22P11 =b12P11;
def coef32P11 = -a12P11 * a12P11;
def coef12P11 = (1 – b12P11 + a12P11 * a12P11) / 4;
rec Bma11 = if barNumber() < 3 then Price else coef12P11 * (Price + 2 * Price[1] + Price[2]) + coef22P11 * Bma11[1] + coef32P11 * Bma11[2];

def a12P12 = exp(-1.414 * 3.14159 / BL11);
def b12P12 = 2 * a12P12 * Cos(1.414 * 3.14159 / BL11);
def coef22P12 =b12P12;
def coef32P12 = -a12P12 * a12P12;
def coef12P12 = (1 – b12P12 + a12P12 * a12P12) / 4;
rec Bma12 = if barNumber() < 3 then Price else coef12P12 * (Price + 2 * Price[1] + Price[2]) + coef22P12 * Bma12[1] + coef32P12 * Bma12[2];

def a12P13 = exp(-1.414 * 3.14159 / BL12);
def b12P13 = 2 * a12P13 * Cos(1.414 * 3.14159 / BL12);
def coef22P13 =b12P13;
def coef32P13 = -a12P13 * a12P13;
def coef12P13 = (1 – b12P13 + a12P13 * a12P13) / 4;
rec Bma13 = if barNumber() < 3 then Price else coef12P13 * (Price + 2 * Price[1] + Price[2]) + coef22P13 * Bma13[1] + coef32P13 * Bma13[2];

def a12P14 = exp(-1.414 * 3.14159 / BL13);
def b12P14 = 2 * a12P14 * Cos(1.414 * 3.14159 / BL13);
def coef22P14 =b12P14;
def coef32P14 = -a12P14 * a12P14;
def coef12P14 = (1 – b12P14 + a12P14 * a12P14) / 4;
rec Bma14 = if barNumber() < 3 then Price else coef12P14 * (Price + 2 * Price[1] + Price[2]) + coef22P14 * Bma14[1] + coef32P14 * Bma14[2];

def a12P15 = exp(-1.414 * 3.14159 / BL14);
def b12P15 = 2 * a12P15 * Cos(1.414 * 3.14159 / BL14);
def coef22P15 =b12P15;
def coef32P15 = -a12P15 * a12P15;
def coef12P15 = (1 – b12P15 + a12P15 * a12P15) / 4;
rec Bma15 = if barNumber() < 3 then Price else coef12P15 * (Price + 2 * Price[1] + Price[2]) + coef22P15 * Bma15[1] + coef32P15 * Bma15[2];

def a12P16 = exp(-1.414 * 3.14159 / BL15);
def b12P16 = 2 * a12P16 * Cos(1.414 * 3.14159 / BL15);
def coef22P16 =b12P16;
def coef32P16 = -a12P16 * a12P16;
def coef12P16 = (1 – b12P16 + a12P16 * a12P16) / 4;
rec Bma16 = if barNumber() < 3 then Price else coef12P16 * (Price + 2 * Price[1] + Price[2]) + coef22P16 * Bma16[1] + coef32P16 * Bma16[2];

def a12P17 = exp(-1.414 * 3.14159 / BL16);
def b12P17 = 2 * a12P17 * Cos(1.414 * 3.14159 / BL16);
def coef22P17 =b12P17;
def coef32P17 = -a12P17 * a12P17;
def coef12P17 = (1 – b12P17 + a12P17 * a12P17) / 4;
rec Bma17 = if barNumber() < 3 then Price else coef12P17 * (Price + 2 * Price[1] + Price[2]) + coef22P17 * Bma17[1] + coef32P17 * Bma17[2];

def a12P18 = exp(-1.414 * 3.14159 / BL17);
def b12P18 = 2 * a12P18 * Cos(1.414 * 3.14159 / BL17);
def coef22P18 =b12P18;
def coef32P18 = -a12P18 * a12P18;
def coef12P18 = (1 – b12P18 + a12P18 * a12P18) / 4;
rec Bma18 = if barNumber() < 3 then Price else coef12P18 * (Price + 2 * Price[1] + Price[2]) + coef22P18 * Bma18[1] + coef32P18 * Bma18[2];

def a12P19 = exp(-1.414 * 3.14159 / BL18);
def b12P19 = 2 * a12P19 * Cos(1.414 * 3.14159 / BL18);
def coef22P19 =b12P19;
def coef32P19 = -a12P19 * a12P19;
def coef12P19 = (1 – b12P19 + a12P19 * a12P19) / 4;
rec Bma19 = if barNumber() < 3 then Price else coef12P19 * (Price + 2 * Price[1] + Price[2]) + coef22P19 * Bma19[1] + coef32P19 * Bma19[2];

def a12P20 = exp(-1.414 * 3.14159 / BL19);
def b12P20 = 2 * a12P20 * Cos(1.414 * 3.14159 / BL19);
def coef22P20 =b12P20;
def coef32P20 = -a12P20 * a12P20;
def coef12P20 = (1 – b12P20 + a12P20 * a12P20) / 4;
rec Bma20 = if barNumber() < 3 then Price else coef12P20 * (Price + 2 * Price[1] + Price[2]) + coef22P20 * Bma20[1] + coef32P20 * Bma20[2];

Plot MA1 = Bma1;
Plot MA2 = Bma2;
Plot MA3 = Bma3;
Plot MA4 = Bma4;
Plot MA5 = Bma5;
Plot MA6 = Bma6;
Plot MA7 = Bma7;
Plot MA8 = Bma8;
Plot MA9 = Bma9;
Plot MA10 = Bma10;
Plot MA11 = Bma11;
Plot MA12 = Bma12;
Plot MA13 = Bma13;
Plot MA14 = Bma14;
Plot MA15 = Bma15;
Plot MA16 = Bma16;
Plot MA17 = Bma17;
Plot MA18 = Bma18;
Plot MA19 = Bma19;
Plot MA20 = Bma20;

def sDev = stdev(data = MA20[-displace], BL19);
plot LL = MA20 – Num_Dev * SDev;
plot HH = MA20 + num_Dev * sDev;
LL.setdefaultColor(Color.Gray);
HH.setdefaultColor(Color.Gray);
def Height = HH- LL;
Plot A3 = LL + Height*0.3;
Plot A7 = LL + Height * 0.7;
A3.setdefaultColor(Color.Gray);
A7.setdefaultColor(Color.Gray);
AddCloud(A3, LL, Color.Light_Red,Color.Light_Red);
AddCloud(A7, A3, Color.Yellow,Color.Yellow);
AddCloud(HH,A7, Color.Light_Green,Color.Light_Green);

ma1.AssignValueColor( if ma1 >= ma1[1] and ma1>ma20 then color.Green  else if ma1 < ma1[1] and ma1>ma20 then color.Dark_Red else if ma1<= ma1[1] and ma1 <ma20 then Color.Red else if ma1 >= ma1[1] and ma1 < ma20 then color.Dark_Green else color.gray);
ma1.hidebubble();
MA1.setlineweight(1);


ma2.AssignValueColor(if ma2 >= ma2[1] and ma1>ma20
then color.green  else if ma2 < ma2[1] and ma1>ma20
then color.Dark_Red else if ma2<= ma2[1] and ma1 <ma20
then color.Red else if ma2 >= ma2[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma2.hidebubble();
MA2.setlineweight(1);

ma3.AssignValueColor(if ma3 >= ma3[1] and ma1>ma20
then color.green else if ma3 < ma3[1] and ma1>ma20
then color.Dark_Red else if ma3<= ma3[1] and ma1 <ma20
then color.Red else if ma3 >= ma3[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma3.hidebubble();
MA3.setlineweight(1);

ma4.AssignValueColor(if ma4 >= ma4[1] and ma1>ma20
then color.Green  else if ma4 < ma4[1] and ma1>ma20
then color.Dark_Red else if ma4<= ma4[1] and ma1 <ma20
then color.Red else if ma4 >= ma4[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma4.hidebubble();
MA4.setlineweight(1);

ma5.AssignValueColor(if ma5 >= ma5[1] and ma1>ma20
then color.Green  else if ma5 < ma5[1] and ma1>ma20
then color.Dark_Red else if ma5<= ma5[1] and ma1 <ma20
then color.Red else if ma5 >= ma5[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma5.hidebubble();
MA5.setlineweight(1);

ma6.AssignValueColor(if ma6 >= ma6[1] and ma1>ma20
then color.Green  else if ma6 < ma6[1] and ma1>ma20
then color.Dark_Red else if ma6<= ma6[1] and ma1 <ma20
then color.Red else if ma6 >= ma6[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma6.hidebubble();
MA6.setlineweight(1);

ma7.AssignValueColor(if ma7 >= ma7[1] and ma1>ma20
then color.Green  else if ma7 < ma7[1] and ma1>ma20
then color.Dark_Red else if ma7<= ma7[1] and ma1 <ma20
then color.Red else if ma7 >= ma7[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma7.hidebubble();
MA7.setlineweight(1);

ma8.AssignValueColor(if ma8 >= ma8[1] and ma1>ma20
then color.Green  else if ma8 < ma8[1] and ma1>ma20
then color.Dark_Red else if ma8<= ma8[1] and ma1 <ma20
then color.Red else if ma8 >= ma8[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma8.hidebubble();
MA8.setlineweight(1);

ma9.AssignValueColor(if ma9 >= ma9[1] and ma1>ma20
then color.Green  else if ma9 < ma9[1] and ma1>ma20
then color.Dark_Red else if ma9<= ma9[1] and ma1 <ma20
then color.Red else if ma9 >= ma9[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma9.hidebubble();
MA9.setlineweight(1);

ma10.AssignValueColor(if ma10 >= ma10[1] and ma1>ma20
then color.Green  else if ma10 < ma10[1] and ma1>ma20
then color.Dark_Red else if ma10<= ma10[1] and ma1 <ma20
then color.Red else if ma10 >= ma10[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma10.hidebubble();
MA10.setLineweight(2);

ma11.AssignValueColor(if ma11 >= ma11[1] and ma1>ma20
then color.Green  else if ma11 < ma11[1] and ma1>ma20
then color.Dark_Red else if ma11<= ma11[1] and ma1 <ma20
then color.Red else if ma11 >= ma11[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma11.hidebubble();
MA11.setlineweight(1);

ma12.AssignValueColor(if ma12 >= ma12[1] and ma1>ma20
then color.Green  else if ma12 < ma12[1] and ma1>ma20
then color.Dark_Red else if ma12<= ma12[1] and ma1 <ma20
then color.Red else if ma12 >= ma12[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma12.hidebubble();
MA12.setlineweight(1);

ma13.AssignValueColor(if ma13 >= ma13[1] and ma1>ma20
then color.Green  else if ma13 < ma13[1] and ma1>ma20
then color.Dark_Red else if ma13<= ma13[1] and ma1 <ma20
then color.Red else if ma13 >= ma13[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma13.hidebubble();
MA13.setlineweight(1);

ma14.AssignValueColor(if ma14 >= ma14[1] and ma1>ma20
then color.Green  else if ma14 < ma14[1] and ma1>ma20
then color.Dark_Red else if ma14<= ma14[1] and ma1 <ma20
then color.Red else if ma14 >= ma14[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma14.hidebubble();
MA14.setlineweight(1);

ma15.AssignValueColor(if ma15 >= ma15[1] and ma1>ma20
then color.Green  else if ma15 < ma15[1] and ma1>ma20
then color.Dark_Red else if ma15<= ma15[1] and ma1 <ma20
then color.Red else if ma15 >= ma15[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma15.hidebubble();
MA15.setlineweight(1);

ma16.AssignValueColor(if ma16 >= ma16[1] and ma1>ma20
then color.Green  else if ma16 < ma16[1] and ma1>ma20
then color.Dark_Red else if ma16<= ma16[1] and ma1 <ma20
then color.Red else if ma16 >= ma16[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma16.hidebubble();
MA16.setlineweight(1);

ma17.AssignValueColor(if ma17 >= ma17[1] and ma1>ma20
then color.Green  else if ma17 < ma17[1] and ma1>ma20
then color.Dark_Red else if ma17<= ma17[1] and ma1 <ma20
then color.Red else if ma17 >= ma17[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma17.hidebubble();
MA17.setlineweight(1);

ma18.AssignValueColor(if ma18 >= ma18[1] and ma1>ma20
then color.Green  else if ma18 < ma18[1] and ma1>ma20
then color.Dark_Red else if ma18<= ma18[1] and ma1 <ma20
then color.Red else if ma18 >= ma18[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma18.hidebubble();
MA18.setlineweight(1);

ma19.AssignValueColor(if ma19 >= ma19[1] and ma1>ma20
then color.Green  else if ma19 < ma19[1] and ma1>ma20
then color.Dark_Red else if ma19<= ma19[1] and ma1 <ma20
then color.Red else if ma19 >= ma19[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma19.hidebubble();
MA19.setlineweight(1);

ma20.AssignValueColor(if ma20 >= ma20[1] and ma1>ma20
then color.Green  else if ma20 < ma20[1] and ma1>ma20
then color.Dark_Red else if ma20<= ma20[1] and ma1 <ma20
then color.Red else if ma20 >= ma20[1] and ma1 < ma20
then color.Dark_Green else color.gray);
ma20.hidebubble();
MA20.setlineweight(3);


AssignPriceColor( If APC ==1 && ma1 >= ma1[1] and ma1>ma20 then color.Green  else if APC ==1 && ma1 < ma1[1] and ma1>ma20 then color.Dark_Red else if APC ==1 && ma1<= ma1[1] and ma1 <ma20 then Color.Red else if APC ==1 && ma1 >= ma1[1] and ma1 < ma20 then color.Dark_Green else if APC ==2 && ma2 >= ma2[1] and ma1>ma20 then color.green  else if APC ==2 && ma2 < ma2[1] and ma1>ma20 then color.Dark_Red else if APC ==2 && ma2<= ma2[1] and ma1 <ma20
then color.Red else if APC ==2 && ma2 >= ma2[1] and ma1 < ma20 then color.Dark_Green else
if APC ==3 && ma3 >= ma3[1] and ma1>ma20 then color.green  else if APC ==3 && ma3 < ma3[1] and ma1>ma20 then color.Dark_Red else if APC ==3 && ma3<= ma3[1] and ma1 <ma20
then color.Red else if APC ==3 && ma3 >= ma3[1] and ma1 < ma20 then color.Dark_Green else
if APC ==4 && ma4 >= ma4[1] and ma1>ma20 then color.green  else if APC ==4 && ma4 < ma4[1] and ma1>ma20 then color.Dark_Red else if APC ==4 && ma4<= ma4[1] and ma1 <ma20
then color.Red else if APC ==4 && ma4 >= ma4[1] and ma1 < ma20 then color.Dark_Green else
if APC ==5 && ma5 >= ma5[1] and ma1>ma20 then color.green  else if APC ==5 && ma5 < ma5[1] and ma1>ma20 then color.Dark_Red else if APC ==5 && ma5<= ma5[1] and ma1 <ma20
then color.Red else if APC ==5 && ma5 >= ma5[1] and ma1 < ma20 then color.Dark_Green else
if APC ==6 && ma6 >= ma6[1] and ma1>ma20 then color.green  else if APC ==6 && ma6 < ma6[1] and ma1>ma20 then color.Dark_Red else if APC ==6 && ma6<= ma6[1] and ma1 <ma20
then color.Red else if APC ==6 && ma6 >= ma6[1] and ma1 < ma20 then color.Dark_Green else
if APC ==7 && ma7 >= ma7[1] and ma1>ma20 then color.green  else if APC ==7 && ma7 < ma7[1] and ma1>ma20 then color.Dark_Red else if APC ==7 && ma7<= ma7[1] and ma1 <ma20
then color.Red else if APC ==7 && ma7 >= ma7[1] and ma1 < ma20 then color.Dark_Green else
if APC ==8 && ma8 >= ma8[1] and ma1>ma20 then color.green  else if APC ==8 && ma8 < ma8[1] and ma1>ma20 then color.Dark_Red else if APC ==8 && ma8<= ma8[1] and ma1 <ma20
then color.Red else if APC ==8 && ma8 >= ma8[1] and ma1 < ma20 then color.Dark_Green else
if APC ==9 && ma9 >= ma9[1] and ma1>ma20 then color.green  else if APC ==9 && ma9 < ma9[1] and ma1>ma20 then color.Dark_Red else if APC ==9 && ma9<= ma9[1] and ma1 <ma20
then color.Red else if APC ==9 && ma9 >= ma9[1] and ma1 < ma20 then color.Dark_Green else
if APC ==10 && ma10 >= ma10[1] and ma1>ma20 then color.green  else if APC ==10 && ma10 < ma10[1] and ma1>ma20 then color.Dark_Red else if APC ==10 && ma10<= ma10[1] and ma1 <ma20 then color.Red else if APC ==10 && ma10 >= ma10[1] and ma1 < ma20 then color.Dark_Green else
if APC ==11 && ma11 >= ma11[1] and ma1>ma20 then color.green  else if APC ==11 && ma11 < ma11[1] and ma1>ma20 then color.Dark_Red else if APC ==11 && ma11<= ma11[1] and ma1 <ma20 then color.Red else if APC ==11 && ma11 >= ma11[1] and ma1 < ma20 then color.Dark_Green else
if APC ==12 && ma12 >= ma12[1] and ma1>ma20 then color.green  else if APC ==12 && ma12 < ma12[1] and ma1>ma20 then color.Dark_Red else if APC ==12 && ma12<= ma12[1] and ma1 <ma20 then color.Red else if APC ==12 && ma12 >= ma12[1] and ma1 < ma20 then color.Dark_Green else
if APC ==13 && ma13 >= ma13[1] and ma1>ma20 then color.green  else if APC ==13 && ma13 < ma13[1] and ma1>ma20 then color.Dark_Red else if APC ==13 && ma13<= ma13[1] and ma1 <ma20 then color.Red else if APC ==13 && ma13 >= ma13[1] and ma1 < ma20 then color.Dark_Green else
if APC ==14 && ma14 >= ma14[1] and ma1>ma20 then color.green  else if APC ==14 && ma14 < ma14[1] and ma1>ma20 then color.Dark_Red else if APC ==14 && ma14<= ma14[1] and ma1 <ma20 then color.Red else if APC ==14 && ma14 >= ma14[1] and ma1 < ma20 then color.Dark_Green else
if APC ==15 && ma15 >= ma15[1] and ma1>ma20 then color.green  else if APC ==15 && ma15 < ma15[1] and ma1>ma20 then color.Dark_Red else if APC ==15 && ma15<= ma15[1] and ma1 <ma20 then color.Red else if APC ==15 && ma15 >= ma15[1] and ma1 < ma20 then color.Dark_Green else
if APC ==16 && ma16 >= ma16[1] and ma1>ma20 then color.green  else if APC ==16 && ma16 < ma16[1] and ma1>ma20 then color.Dark_Red else if APC ==16 && ma16<= ma16[1] and ma1 <ma20 then color.Red else if APC ==16 && ma16 >= ma16[1] and ma1 < ma20 then color.Dark_Green else
if APC ==17 && ma17 >= ma17[1] and ma1>ma20 then color.green  else if APC ==17 && ma17 < ma17[1] and ma1>ma20 then color.Dark_Red else if APC ==17 && ma17<= ma17[1] and ma1 <ma20 then color.Red else if APC ==17 && ma17 >= ma17[1] and ma1 < ma20 then color.Dark_Green else
if APC ==18 && ma18 >= ma18[1] and ma1>ma20 then color.green  else if APC ==18 && ma18 < ma18[1] and ma1>ma20 then color.Dark_Red else if APC ==18 && ma18<= ma18[1] and ma1 <ma20 then color.Red else if APC ==18 && ma18 >= ma18[1] and ma1 < ma20 then color.Dark_Green else
if APC ==19 && ma19 >= ma19[1] and ma1>ma20 then color.green  else if APC ==19 && ma19 < ma19[1] and ma1>ma20 then color.Dark_Red else if APC ==19 && ma19<= ma19[1] and ma1 <ma20 then color.Red else if APC ==19 && ma19 >= ma19[1] and ma1 < ma20 then color.Dark_Green else
if APC ==20 && ma20 >= ma20[1] and ma1>ma20 then color.green  else if APC ==20 && ma20 < ma20[1] and ma1>ma20 then color.Dark_Red else if APC ==20 && ma20<= ma20[1] and ma1 <ma20 then color.Red else if APC ==20 && ma20 >= ma20[1] and ma1 < ma20 then color.Dark_Green else Color.Current);
 
This is the Madrid Moving Avg Ribbons Buttered Binary w APC "AssignPriceColor"
Code:
Declare Lower;
Input APC = 0;
Input Price = Close;
input baseLength = 5;
input increment = 5;
input Width = 3;
def BL = BaseLength;
def BL1 = (BL + (1* increment));
def BL2 = (BL + (2* increment));
def BL3 = (BL + (3* increment));
def BL4 = (BL + (4* increment));
def BL5 = (BL + (5* increment));
def BL6 = (BL + (6* increment));
def BL7 = (BL + (7* increment));
def BL8 = (BL + (8* increment));
def BL9 = (BL + (9* increment));
def BL10 = (BL + (10* increment));
def BL11 = (BL + (11* increment));
def BL12 = (BL + (12* increment));
def BL13 = (BL + (13* increment));
def BL14 = (BL + (14* increment));
def BL15 = (BL + (15* increment));
def BL16 = (BL + (16* increment));
def BL17 = (BL + (17* increment));
def BL18 = (BL + (18* increment));
def BL19 = (BL + (19* increment));

def a12P = exp(-1.414 * 3.14159 / BL);
def b12P = 2 * a12P * Cos(1.414 * 3.14159 / BL);
def coef22P =b12P;
def coef32P = -a12P * a12P;
def coef12P = (1 – b12P + a12P * a12P) / 4;
rec ma1 = if barNumber() < 3 then Price else coef12P * (Price + 2 * Price[1] + Price[2]) + coef22P * ma1[1] + coef32P * ma1[2];

def a12P2 = exp(-1.414 * 3.14159 / BL1);
def b12P2 = 2 * a12P2 * Cos(1.414 * 3.14159 / BL1);
def coef22P2 =b12P2;
def coef32P2 = -a12P2 * a12P2;
def coef12P2 = (1 – b12P2 + a12P2 * a12P2) / 4;
rec ma2 = if barNumber() < 3 then Price else coef12P2 * (Price + 2 * Price[1] + Price[2]) + coef22P2 * ma2[1] + coef32P2 * ma2[2];

def a12P3 = exp(-1.414 * 3.14159 / BL2);
def b12P3 = 2 * a12P3 * Cos(1.414 * 3.14159 / BL2);
def coef22P3 =b12P3;
def coef32P3 = -a12P3 * a12P3;
def coef12P3 = (1 – b12P3 + a12P3 * a12P3) / 4;
rec ma3 = if barNumber() < 3 then Price else coef12P3 * (Price + 2 * Price[1] + Price[2]) + coef22P3 * ma3[1] + coef32P3 * ma3[2];

def a12P4 = exp(-1.414 * 3.14159 / BL3);
def b12P4 = 2 * a12P4 * Cos(1.414 * 3.14159 / BL3);
def coef22P4 =b12P4;
def coef32P4 = -a12P4 * a12P4;
def coef12P4 = (1 – b12P4 + a12P4 * a12P4) / 4;
rec ma4 = if barNumber() < 3 then Price else coef12P4 * (Price + 2 * Price[1] + Price[2]) + coef22P4 * ma4[1] + coef32P4 * ma4[2];

def a12P5 = exp(-1.414 * 3.14159 / BL4);
def b12P5 = 2 * a12P5 * Cos(1.414 * 3.14159 / BL4);
def coef22P5 =b12P5;
def coef32P5 = -a12P5 * a12P5;
def coef12P5 = (1 – b12P5 + a12P5 * a12P5) / 4;
rec ma5 = if barNumber() < 3 then Price else coef12P5 * (Price + 2 * Price[1] + Price[2]) + coef22P5 * ma5[1] + coef32P5 * ma5[2];

def a12P6 = exp(-1.414 * 3.14159 / BL5);
def b12P6 = 2 * a12P6 * Cos(1.414 * 3.14159 / BL5);
def coef22P6 =b12P6;
def coef32P6 = -a12P6 * a12P6;
def coef12P6 = (1 – b12P6 + a12P6 * a12P6) / 4;
rec ma6 = if barNumber() < 3 then Price else coef12P6 * (Price + 2 * Price[1] + Price[2]) + coef22P6 * ma6[1] + coef32P6 * ma6[2];

def a12P7 = exp(-1.414 * 3.14159 / BL6);
def b12P7 = 2 * a12P7 * Cos(1.414 * 3.14159 / BL6);
def coef22P7 =b12P7;
def coef32P7 = -a12P7 * a12P7;
def coef12P7 = (1 – b12P7 + a12P7 * a12P7) / 4;
rec ma7 = if barNumber() < 3 then Price else coef12P7 * (Price + 2 * Price[1] + Price[2]) + coef22P7 * ma7[1] + coef32P7 * ma7[2];

def a12P8 = exp(-1.414 * 3.14159 / BL7);
def b12P8 = 2 * a12P8 * Cos(1.414 * 3.14159 / BL7);
def coef22P8 =b12P8;
def coef32P8 = -a12P8 * a12P8;
def coef12P8 = (1 – b12P8 + a12P8 * a12P8) / 4;
rec ma8 = if barNumber() < 3 then Price else coef12P8 * (Price + 2 * Price[1] + Price[2]) + coef22P8 * ma8[1] + coef32P8 * ma8[2];

def a12P9 = exp(-1.414 * 3.14159 / BL8);
def b12P9 = 2 * a12P9 * Cos(1.414 * 3.14159 / BL8);
def coef22P9 =b12P9;
def coef32P9 = -a12P9 * a12P9;
def coef12P9 = (1 – b12P9 + a12P9 * a12P9) / 4;
rec ma9 = if barNumber() < 3 then Price else coef12P9 * (Price + 2 * Price[1] + Price[2]) + coef22P9 * ma9[1] + coef32P9 * ma9[2];

def a12P10 = exp(-1.414 * 3.14159 / BL9);
def b12P10 = 2 * a12P10 * Cos(1.414 * 3.14159 / BL9);
def coef22P10 =b12P10;
def coef32P10 = -a12P10 * a12P10;
def coef12P10 = (1 – b12P10 + a12P10 * a12P10) / 4;
rec ma10 = if barNumber() < 3 then Price else coef12P10 * (Price + 2 * Price[1] + Price[2]) + coef22P10 * ma10[1] + coef32P10 * ma10[2];

def a12P11 = exp(-1.414 * 3.14159 / BL10);
def b12P11 = 2 * a12P11 * Cos(1.414 * 3.14159 / BL10);
def coef22P11 =b12P11;
def coef32P11 = -a12P11 * a12P11;
def coef12P11 = (1 – b12P11 + a12P11 * a12P11) / 4;
rec ma11 = if barNumber() < 3 then Price else coef12P11 * (Price + 2 * Price[1] + Price[2]) + coef22P11 * ma11[1] + coef32P11 * ma11[2];

def a12P12 = exp(-1.414 * 3.14159 / BL11);
def b12P12 = 2 * a12P12 * Cos(1.414 * 3.14159 / BL11);
def coef22P12 =b12P12;
def coef32P12 = -a12P12 * a12P12;
def coef12P12 = (1 – b12P12 + a12P12 * a12P12) / 4;
rec ma12 = if barNumber() < 3 then Price else coef12P12 * (Price + 2 * Price[1] + Price[2]) + coef22P12 * ma12[1] + coef32P12 * ma12[2];

def a12P13 = exp(-1.414 * 3.14159 / BL12);
def b12P13 = 2 * a12P13 * Cos(1.414 * 3.14159 / BL12);
def coef22P13 =b12P13;
def coef32P13 = -a12P13 * a12P13;
def coef12P13 = (1 – b12P13 + a12P13 * a12P13) / 4;
rec ma13 = if barNumber() < 3 then Price else coef12P13 * (Price + 2 * Price[1] + Price[2]) + coef22P13 * ma13[1] + coef32P13 * ma13[2];

def a12P14 = exp(-1.414 * 3.14159 / BL13);
def b12P14 = 2 * a12P14 * Cos(1.414 * 3.14159 / BL13);
def coef22P14 =b12P14;
def coef32P14 = -a12P14 * a12P14;
def coef12P14 = (1 – b12P14 + a12P14 * a12P14) / 4;
rec ma14 = if barNumber() < 3 then Price else coef12P14 * (Price + 2 * Price[1] + Price[2]) + coef22P14 * ma14[1] + coef32P14 * ma14[2];

def a12P15 = exp(-1.414 * 3.14159 / BL14);
def b12P15 = 2 * a12P15 * Cos(1.414 * 3.14159 / BL14);
def coef22P15 =b12P15;
def coef32P15 = -a12P15 * a12P15;
def coef12P15 = (1 – b12P15 + a12P15 * a12P15) / 4;
rec ma15 = if barNumber() < 3 then Price else coef12P15 * (Price + 2 * Price[1] + Price[2]) + coef22P15 * ma15[1] + coef32P15 * ma15[2];

def a12P16 = exp(-1.414 * 3.14159 / BL15);
def b12P16 = 2 * a12P16 * Cos(1.414 * 3.14159 / BL15);
def coef22P16 =b12P16;
def coef32P16 = -a12P16 * a12P16;
def coef12P16 = (1 – b12P16 + a12P16 * a12P16) / 4;
rec ma16 = if barNumber() < 3 then Price else coef12P16 * (Price + 2 * Price[1] + Price[2]) + coef22P16 * ma16[1] + coef32P16 * ma16[2];

def a12P17 = exp(-1.414 * 3.14159 / BL16);
def b12P17 = 2 * a12P17 * Cos(1.414 * 3.14159 / BL16);
def coef22P17 =b12P17;
def coef32P17 = -a12P17 * a12P17;
def coef12P17 = (1 – b12P17 + a12P17 * a12P17) / 4;
rec ma17 = if barNumber() < 3 then Price else coef12P17 * (Price + 2 * Price[1] + Price[2]) + coef22P17 * ma17[1] + coef32P17 * ma17[2];

def a12P18 = exp(-1.414 * 3.14159 / BL17);
def b12P18 = 2 * a12P18 * Cos(1.414 * 3.14159 / BL17);
def coef22P18 =b12P18;
def coef32P18 = -a12P18 * a12P18;
def coef12P18 = (1 – b12P18 + a12P18 * a12P18) / 4;
rec ma18 = if barNumber() < 3 then Price else coef12P18 * (Price + 2 * Price[1] + Price[2]) + coef22P18 * ma18[1] + coef32P18 * ma18[2];

def a12P19 = exp(-1.414 * 3.14159 / BL18);
def b12P19 = 2 * a12P19 * Cos(1.414 * 3.14159 / BL18);
def coef22P19 =b12P19;
def coef32P19 = -a12P19 * a12P19;
def coef12P19 = (1 – b12P19 + a12P19 * a12P19) / 4;
rec ma19 = if barNumber() < 3 then Price else coef12P19 * (Price + 2 * Price[1] + Price[2]) + coef22P19 * ma19[1] + coef32P19 * ma19[2];

def a12P20 = exp(-1.414 * 3.14159 / BL19);
def b12P20 = 2 * a12P20 * Cos(1.414 * 3.14159 / BL19);
def coef22P20 =b12P20;
def coef32P20 = -a12P20 * a12P20;
def coef12P20 = (1 – b12P20 + a12P20 * a12P20) / 4;
rec ma20 = if barNumber() < 3 then Price else coef12P20 * (Price + 2 * Price[1] + Price[2]) + coef22P20 * ma20[1] + coef32P20 * ma20[2];

plot Dma1 = if IsNaN(close) then Double.NaN else 1;
plot Dma2 = if IsNaN(close) then Double.NaN else 2;
plot Dma3 = if IsNaN(close) then Double.NaN else 3;
plot Dma4 = if IsNaN(close) then Double.NaN else 4;
plot Dma5 = if IsNaN(close) then Double.NaN else 5;
plot Dma6 = if IsNaN(close) then Double.NaN else 6;
plot Dma7 = if IsNaN(close) then Double.NaN else 7;
plot Dma8 = if IsNaN(close) then Double.NaN else 8;
plot Dma9 = if IsNaN(close) then Double.NaN else 9;
plot Dma10 = if IsNaN(close) then Double.NaN else 10;
plot Dma11 = if IsNaN(close) then Double.NaN else 11;
plot Dma12 = if IsNaN(close) then Double.NaN else 12;
plot Dma13 = if IsNaN(close) then Double.NaN else 13;
plot Dma14 = if IsNaN(close) then Double.NaN else 14;
plot Dma15 = if IsNaN(close) then Double.NaN else 15;
plot Dma16 = if IsNaN(close) then Double.NaN else 16;
plot Dma17 = if IsNaN(close) then Double.NaN else 17;
plot Dma18 = if IsNaN(close) then Double.NaN else 18;
plot Dma19 = if IsNaN(close) then Double.NaN else 19;
plot Dma20 = if IsNaN(close) then Double.NaN else 20;

Dma1.SetpaintingStrategy(PaintingStrategy.Triangles);
Dma1.AssignValueColor( if ma1 >= ma1[1] and ma1>ma20 then color.Green  else if ma1 < ma1[1] and ma1>ma20 then color.Dark_Red else if ma1<= ma1[1] and ma1 <ma20 then Color.Red else if ma1 >= ma1[1] and ma1 < ma20 then color.Dark_Green else color.gray);
Dma1.hidebubble();

Dma2.SetpaintingStrategy(PaintingStrategy.Triangles);
Dma2.AssignValueColor(if ma2 >= ma2[1] and ma1>ma20
then color.green  else if ma2 < ma2[1] and ma1>ma20
then color.Dark_Red else if ma2<= ma2[1] and ma1 <ma20
then color.Red else if ma2 >= ma2[1] and ma1 < ma20
then color.Dark_Green else color.gray);
Dma3.hidebubble();

Dma3.SetpaintingStrategy(PaintingStrategy.Triangles);
Dma3.AssignValueColor(if ma3 >= ma3[1] and ma1>ma20
then color.green else if ma3 < ma3[1] and ma1>ma20
then color.Dark_Red else if ma3<= ma3[1] and ma1 <ma20
then color.Red else if ma3 >= ma3[1] and ma1 < ma20
then color.Dark_Green else color.gray);
Dma3.hidebubble();

Dma4.SetpaintingStrategy(PaintingStrategy.Triangles);
Dma4.AssignValueColor(if ma4 >= ma4[1] and ma1>ma20
then color.Green  else if ma4 < ma4[1] and ma1>ma20
then color.Dark_Red else if ma4<= ma4[1] and ma1 <ma20
then color.Red else if ma4 >= ma4[1] and ma1 < ma20
then color.Dark_Green else color.gray);
Dma4.hidebubble();

Dma5.SetpaintingStrategy(PaintingStrategy.Triangles);
Dma5.AssignValueColor(if ma5 >= ma5[1] and ma1>ma20
then color.Green  else if ma5 < ma5[1] and ma1>ma20
then color.Dark_Red else if ma5<= ma5[1] and ma1 <ma20
then color.Red else if ma5 >= ma5[1] and ma1 < ma20
then color.Dark_Green else color.gray);
Dma5.hidebubble();

Dma6.SetpaintingStrategy(PaintingStrategy.Triangles);
Dma6.AssignValueColor(if ma6 >= ma6[1] and ma1>ma20
then color.Green  else if ma6 < ma6[1] and ma1>ma20
then color.Dark_Red else if ma6<= ma6[1] and ma1 <ma20
then color.Red else if ma6 >= ma6[1] and ma1 < ma20
then color.Dark_Green else color.gray);
Dma6.hidebubble();

Dma7.SetpaintingStrategy(PaintingStrategy.Triangles);
Dma7.AssignValueColor(if ma7 >= ma7[1] and ma1>ma20
then color.Green  else if ma7 < ma7[1] and ma1>ma20
then color.Dark_Red else if ma7<= ma7[1] and ma1 <ma20
then color.Red else if ma7 >= ma7[1] and ma1 < ma20
then color.Dark_Green else color.gray);
Dma7.hidebubble();

Dma8.SetpaintingStrategy(PaintingStrategy.Triangles);
Dma8.AssignValueColor(if ma8 >= ma8[1] and ma1>ma20
then color.Green  else if ma8 < ma8[1] and ma1>ma20
then color.Dark_Red else if ma8<= ma8[1] and ma1 <ma20
then color.Red else if ma8 >= ma8[1] and ma1 < ma20
then color.Dark_Green else color.gray);
Dma8.hidebubble();

Dma9.SetpaintingStrategy(PaintingStrategy.Triangles);
Dma9.AssignValueColor(if ma9 >= ma9[1] and ma1>ma20
then color.Green  else if ma9 < ma9[1] and ma1>ma20
then color.Dark_Red else if ma9<= ma9[1] and ma1 <ma20
then color.Red else if ma9 >= ma9[1] and ma1 < ma20
then color.Dark_Green else color.gray);
Dma9.hidebubble();

Dma10.SetpaintingStrategy(PaintingStrategy.Triangles);
Dma10.AssignValueColor(if ma10 >= ma10[1] and ma1>ma20
then color.Green  else if ma10 < ma10[1] and ma1>ma20
then color.Dark_Red else if ma10<= ma10[1] and ma1 <ma20
then color.Red else if ma10 >= ma10[1] and ma1 < ma20
then color.Dark_Green else color.gray);
Dma10.hidebubble();

Dma11.SetpaintingStrategy(PaintingStrategy.Triangles);
Dma11.AssignValueColor(if ma11 >= ma11[1] and ma1>ma20
then color.Green  else if ma11 < ma11[1] and ma1>ma20
then color.Dark_Red else if ma11<= ma11[1] and ma1 <ma20
then color.Red else if ma11 >= ma11[1] and ma1 < ma20
then color.Dark_Green else color.gray);
Dma11.hidebubble();

Dma12.SetpaintingStrategy(PaintingStrategy.Triangles);
Dma12.AssignValueColor(if ma12 >= ma12[1] and ma1>ma20
then color.Green  else if ma12 < ma12[1] and ma1>ma20
then color.Dark_Red else if ma12<= ma12[1] and ma1 <ma20
then color.Red else if ma12 >= ma12[1] and ma1 < ma20
then color.Dark_Green else color.gray);
Dma12.hidebubble();

Dma13.SetpaintingStrategy(PaintingStrategy.Triangles);
Dma13.AssignValueColor(if ma13 >= ma13[1] and ma1>ma20
then color.Green  else if ma13 < ma13[1] and ma1>ma20
then color.Dark_Red else if ma13<= ma13[1] and ma1 <ma20
then color.Red else if ma13 >= ma13[1] and ma1 < ma20
then color.Dark_Green else color.gray);
Dma13.hidebubble();

Dma14.SetpaintingStrategy(PaintingStrategy.Triangles);
Dma14.AssignValueColor(if ma14 >= ma14[1] and ma1>ma20
then color.Green  else if ma14 < ma14[1] and ma1>ma20
then color.Dark_Red else if ma14<= ma14[1] and ma1 <ma20
then color.Red else if ma14 >= ma14[1] and ma1 < ma20
then color.Dark_Green else color.gray);
Dma14.hidebubble();

Dma15.SetpaintingStrategy(PaintingStrategy.Triangles);
Dma15.AssignValueColor(if ma15 >= ma15[1] and ma1>ma20
then color.Green  else if ma15 < ma15[1] and ma1>ma20
then color.Dark_Red else if ma15<= ma15[1] and ma1 <ma20
then color.Red else if ma15 >= ma15[1] and ma1 < ma20
then color.Dark_Green else color.gray);
Dma15.hidebubble();

Dma16.SetpaintingStrategy(PaintingStrategy.Triangles);
Dma16.AssignValueColor(if ma16 >= ma16[1] and ma1>ma20
then color.Green  else if ma16 < ma16[1] and ma1>ma20
then color.Dark_Red else if ma16<= ma16[1] and ma1 <ma20
then color.Red else if ma16 >= ma16[1] and ma1 < ma20
then color.Dark_Green else color.gray);
Dma16.hidebubble();

Dma17.SetpaintingStrategy(PaintingStrategy.Triangles);
Dma17.AssignValueColor(if ma17 >= ma17[1] and ma1>ma20
then color.Green  else if ma17 < ma17[1] and ma1>ma20
then color.Dark_Red else if ma17<= ma17[1] and ma1 <ma20
then color.Red else if ma17 >= ma17[1] and ma1 < ma20
then color.Dark_Green else color.gray);
Dma17.hidebubble();

Dma18.SetpaintingStrategy(PaintingStrategy.Triangles);
Dma18.AssignValueColor(if ma18 >= ma18[1] and ma1>ma20
then color.Green  else if ma18 < ma18[1] and ma1>ma20
then color.Dark_Red else if ma18<= ma18[1] and ma1 <ma20
then color.Red else if ma18 >= ma18[1] and ma1 < ma20
then color.Dark_Green else color.gray);
Dma18.hidebubble();

Dma19.SetpaintingStrategy(PaintingStrategy.Triangles);
Dma19.AssignValueColor(if ma19 >= ma19[1] and ma1>ma20
then color.Green  else if ma19 < ma19[1] and ma1>ma20
then color.Dark_Red else if ma19<= ma19[1] and ma1 <ma20
then color.Red else if ma19 >= ma19[1] and ma1 < ma20
then color.Dark_Green else color.gray);
Dma19.hidebubble();

Dma20.SetpaintingStrategy(PaintingStrategy.Triangles);
Dma20.AssignValueColor(if ma20 >= ma20[1] and ma1>ma20
then color.Green  else if ma20 < ma20[1] and ma1>ma20
then color.Dark_Red else if ma20<= ma20[1] and ma1 <ma20
then color.Red else if ma20 >= ma20[1] and ma1 < ma20
then color.Dark_Green else color.gray);
Dma20.hidebubble();

Dma1 .setLineWeight(width);
Dma2 .setLineWeight(width);
Dma3 .setLineWeight(width);
Dma4 .setLineWeight(width);
Dma5 .setLineWeight(width);
Dma6 .setLineWeight(width);
Dma7 .setLineWeight(width);
Dma8 .setLineWeight(width);
Dma9 .setLineWeight(width);
Dma10 .setLineWeight(width);
Dma11 .setLineWeight(width);
Dma12 .setLineWeight(width);
Dma13 .setLineWeight(width);
Dma14 .setLineWeight(width);
Dma15 .setLineWeight(width);
Dma16 .setLineWeight(width);
Dma17 .setLineWeight(width);
Dma18 .setLineWeight(width);
Dma19 .setLineWeight(width);
Dma20 .setLineWeight(width);
AssignPriceColor( If APC ==1 && ma1 >= ma1[1] and ma1>ma20 then color.Green  else if APC ==1 && ma1 < ma1[1] and ma1>ma20 then color.Dark_Red else if APC ==1 && ma1<= ma1[1] and ma1 <ma20 then Color.Red else if APC ==1 && ma1 >= ma1[1] and ma1 < ma20 then color.Dark_Green else if APC ==2 && ma2 >= ma2[1] and ma1>ma20 then color.green  else if APC ==2 && ma2 < ma2[1] and ma1>ma20 then color.Dark_Red else if APC ==2 && ma2<= ma2[1] and ma1 <ma20
then color.Red else if APC ==2 && ma2 >= ma2[1] and ma1 < ma20 then color.Dark_Green else
if APC ==3 && ma3 >= ma3[1] and ma1>ma20 then color.green  else if APC ==3 && ma3 < ma3[1] and ma1>ma20 then color.Dark_Red else if APC ==3 && ma3<= ma3[1] and ma1 <ma20
then color.Red else if APC ==3 && ma3 >= ma3[1] and ma1 < ma20 then color.Dark_Green else
if APC ==4 && ma4 >= ma4[1] and ma1>ma20 then color.green  else if APC ==4 && ma4 < ma4[1] and ma1>ma20 then color.Dark_Red else if APC ==4 && ma4<= ma4[1] and ma1 <ma20
then color.Red else if APC ==4 && ma4 >= ma4[1] and ma1 < ma20 then color.Dark_Green else
if APC ==5 && ma5 >= ma5[1] and ma1>ma20 then color.green  else if APC ==5 && ma5 < ma5[1] and ma1>ma20 then color.Dark_Red else if APC ==5 && ma5<= ma5[1] and ma1 <ma20
then color.Red else if APC ==5 && ma5 >= ma5[1] and ma1 < ma20 then color.Dark_Green else
if APC ==6 && ma6 >= ma6[1] and ma1>ma20 then color.green  else if APC ==6 && ma6 < ma6[1] and ma1>ma20 then color.Dark_Red else if APC ==6 && ma6<= ma6[1] and ma1 <ma20
then color.Red else if APC ==6 && ma6 >= ma6[1] and ma1 < ma20 then color.Dark_Green else
if APC ==7 && ma7 >= ma7[1] and ma1>ma20 then color.green  else if APC ==7 && ma7 < ma7[1] and ma1>ma20 then color.Dark_Red else if APC ==7 && ma7<= ma7[1] and ma1 <ma20
then color.Red else if APC ==7 && ma7 >= ma7[1] and ma1 < ma20 then color.Dark_Green else
if APC ==8 && ma8 >= ma8[1] and ma1>ma20 then color.green  else if APC ==8 && ma8 < ma8[1] and ma1>ma20 then color.Dark_Red else if APC ==8 && ma8<= ma8[1] and ma1 <ma20
then color.Red else if APC ==8 && ma8 >= ma8[1] and ma1 < ma20 then color.Dark_Green else
if APC ==9 && ma9 >= ma9[1] and ma1>ma20 then color.green  else if APC ==9 && ma9 < ma9[1] and ma1>ma20 then color.Dark_Red else if APC ==9 && ma9<= ma9[1] and ma1 <ma20
then color.Red else if APC ==9 && ma9 >= ma9[1] and ma1 < ma20 then color.Dark_Green else
if APC ==10 && ma10 >= ma10[1] and ma1>ma20 then color.green  else if APC ==10 && ma10 < ma10[1] and ma1>ma20 then color.Dark_Red else if APC ==10 && ma10<= ma10[1] and ma1 <ma20 then color.Red else if APC ==10 && ma10 >= ma10[1] and ma1 < ma20 then color.Dark_Green else
if APC ==11 && ma11 >= ma11[1] and ma1>ma20 then color.green  else if APC ==11 && ma11 < ma11[1] and ma1>ma20 then color.Dark_Red else if APC ==11 && ma11<= ma11[1] and ma1 <ma20 then color.Red else if APC ==11 && ma11 >= ma11[1] and ma1 < ma20 then color.Dark_Green else
if APC ==12 && ma12 >= ma12[1] and ma1>ma20 then color.green  else if APC ==12 && ma12 < ma12[1] and ma1>ma20 then color.Dark_Red else if APC ==12 && ma12<= ma12[1] and ma1 <ma20 then color.Red else if APC ==12 && ma12 >= ma12[1] and ma1 < ma20 then color.Dark_Green else
if APC ==13 && ma13 >= ma13[1] and ma1>ma20 then color.green  else if APC ==13 && ma13 < ma13[1] and ma1>ma20 then color.Dark_Red else if APC ==13 && ma13<= ma13[1] and ma1 <ma20 then color.Red else if APC ==13 && ma13 >= ma13[1] and ma1 < ma20 then color.Dark_Green else
if APC ==14 && ma14 >= ma14[1] and ma1>ma20 then color.green  else if APC ==14 && ma14 < ma14[1] and ma1>ma20 then color.Dark_Red else if APC ==14 && ma14<= ma14[1] and ma1 <ma20 then color.Red else if APC ==14 && ma14 >= ma14[1] and ma1 < ma20 then color.Dark_Green else
if APC ==15 && ma15 >= ma15[1] and ma1>ma20 then color.green  else if APC ==15 && ma15 < ma15[1] and ma1>ma20 then color.Dark_Red else if APC ==15 && ma15<= ma15[1] and ma1 <ma20 then color.Red else if APC ==15 && ma15 >= ma15[1] and ma1 < ma20 then color.Dark_Green else
if APC ==16 && ma16 >= ma16[1] and ma1>ma20 then color.green  else if APC ==16 && ma16 < ma16[1] and ma1>ma20 then color.Dark_Red else if APC ==16 && ma16<= ma16[1] and ma1 <ma20 then color.Red else if APC ==16 && ma16 >= ma16[1] and ma1 < ma20 then color.Dark_Green else
if APC ==17 && ma17 >= ma17[1] and ma1>ma20 then color.green  else if APC ==17 && ma17 < ma17[1] and ma1>ma20 then color.Dark_Red else if APC ==17 && ma17<= ma17[1] and ma1 <ma20 then color.Red else if APC ==17 && ma17 >= ma17[1] and ma1 < ma20 then color.Dark_Green else
if APC ==18 && ma18 >= ma18[1] and ma1>ma20 then color.green  else if APC ==18 && ma18 < ma18[1] and ma1>ma20 then color.Dark_Red else if APC ==18 && ma18<= ma18[1] and ma1 <ma20 then color.Red else if APC ==18 && ma18 >= ma18[1] and ma1 < ma20 then color.Dark_Green else
if APC ==19 && ma19 >= ma19[1] and ma1>ma20 then color.green  else if APC ==19 && ma19 < ma19[1] and ma1>ma20 then color.Dark_Red else if APC ==19 && ma19<= ma19[1] and ma1 <ma20 then color.Red else if APC ==19 && ma19 >= ma19[1] and ma1 < ma20 then color.Dark_Green else
if APC ==20 && ma20 >= ma20[1] and ma1>ma20 then color.green  else if APC ==20 && ma20 < ma20[1] and ma1>ma20 then color.Dark_Red else if APC ==20 && ma20<= ma20[1] and ma1 <ma20 then color.Red else if APC ==20 && ma20 >= ma20[1] and ma1 < ma20 then color.Dark_Green else Color.Current);
 
Very cool and thanks for this script. One interesting thing I'm seeing is when prices are at a low and drop some distance outside and below the EMAs, they always seem to return/reverse a little or a lot soon after. This is just my initial observation anyway.

I removed the geometric function as I don't see how it would work with this indicator (first stated by @henry1224.) I also added the 20th EMA so we get a 200 EMA.

Code:
input price = close;
input baseLength = 10;
input multiplier = 10;

plot XMA1 = ExpAverage(price, baseLength);
plot XMA2 = ExpAverage(price, baseLength + 1 * multiplier);
plot XMA3 = ExpAverage(price, baseLength + 2 * multiplier);
plot XMA4 = ExpAverage(price, baseLength + 3 * multiplier);
plot XMA5 = ExpAverage(price, baseLength + 4 * multiplier);
plot XMA6 = ExpAverage(price, baseLength + 5 * multiplier);
plot XMA7 = ExpAverage(price, baseLength + 6 * multiplier);
plot XMA8 = ExpAverage(price, baseLength + 7 * multiplier);
plot XMA9 = ExpAverage(price, baseLength + 8 * multiplier);
plot XMA10 = ExpAverage(price, baseLength + 9 * multiplier);
plot XMA11 = ExpAverage(price, baseLength + 10 * multiplier);
plot XMA12 = ExpAverage(price, baseLength + 11 * multiplier);
plot XMA13 = ExpAverage(price, baseLength + 12 * multiplier);
plot XMA14 = ExpAverage(price, baseLength + 13 * multiplier);
plot XMA15 = ExpAverage(price, baseLength + 14 * multiplier);
plot XMA16 = ExpAverage(price, baseLength + 15 * multiplier);
plot XMA17 = ExpAverage(price, baseLength + 16 * multiplier);
plot XMA18 = ExpAverage(price, baseLength + 17 * multiplier);
plot XMA19 = ExpAverage(price, baseLength + 18 * multiplier);
plot XMA20 = ExpAverage(price, baseLength + 19 * multiplier);

DefineGlobalColor("X1", CreateColor(255, 50, 0));
DefineGlobalColor("X2", CreateColor(255, 60, 0));
DefineGlobalColor("X3", CreateColor(255, 70, 0));
DefineGlobalColor("X4", CreateColor(255, 80, 0));
DefineGlobalColor("X5", CreateColor(255, 90, 0));
DefineGlobalColor("X6", CreateColor(255, 100, 0));
DefineGlobalColor("X7", CreateColor(255, 110, 0));
DefineGlobalColor("X8", CreateColor(255, 120, 0));
DefineGlobalColor("X9", CreateColor(255, 130, 0));
DefineGlobalColor("X10", CreateColor(255, 140, 0));
DefineGlobalColor("X11", CreateColor(255, 150, 0));
DefineGlobalColor("X12", CreateColor(255, 160, 0));
DefineGlobalColor("X13", CreateColor(255, 170, 0));
DefineGlobalColor("X14", CreateColor(255, 180, 0));
DefineGlobalColor("X15", CreateColor(255, 190, 0));
DefineGlobalColor("X16", CreateColor(255, 200, 0));
DefineGlobalColor("X17", CreateColor(255, 210, 0));
DefineGlobalColor("X18", CreateColor(255, 220, 0));
DefineGlobalColor("X19", CreateColor(255, 230, 0));
DefineGlobalColor("X20", CreateColor(255, 240, 0));

DefineGlobalColor("Xx1", CreateColor(0, 255, 50));
DefineGlobalColor("Xx2", CreateColor(0, 255, 60));
DefineGlobalColor("Xx3", CreateColor(0, 255, 70));
DefineGlobalColor("Xx4", CreateColor(0, 255, 80));
DefineGlobalColor("Xx5", CreateColor(0, 255, 90));
DefineGlobalColor("Xx6", CreateColor(0, 255,100));
DefineGlobalColor("Xx7", CreateColor(0, 255, 110));
DefineGlobalColor("Xx8", CreateColor(0, 255, 120));
DefineGlobalColor("Xx9", CreateColor(0, 255, 130));
DefineGlobalColor("Xx10", CreateColor(0,255, 140));
DefineGlobalColor("Xx11", CreateColor(0, 255, 150));
DefineGlobalColor("Xx12", CreateColor(0, 255, 160));
DefineGlobalColor("Xx13", CreateColor(0, 255, 170));
DefineGlobalColor("Xx14", CreateColor(0, 255, 180));
DefineGlobalColor("Xx15", CreateColor(0, 255, 190));
DefineGlobalColor("Xx16", CreateColor(0, 255, 200));
DefineGlobalColor("Xx17", CreateColor(0, 255, 210));
DefineGlobalColor("Xx18", CreateColor(0, 255, 220));
DefineGlobalColor("Xx19", CreateColor(0, 255, 230));
DefineGlobalColor("Xx20", CreateColor(0, 255, 240));

XMA1 .AssignValueColor( if Xma1 <= Xma1[1]  then GlobalColor("X1")else GlobalColor("Xx1"));
XMA2 .AssignValueColor( if Xma2 <= Xma2[1]  then GlobalColor("X2")else GlobalColor("Xx2"));
XMA3 .AssignValueColor( if Xma3 <= Xma3[1]  then GlobalColor("X3")else GlobalColor("Xx3"));
XMA4 .AssignValueColor( if Xma4 <= Xma4[1]  then GlobalColor("X4")else GlobalColor("Xx4"));
XMA5 .AssignValueColor( if XMA5 <= XMA5[1]  then GlobalColor("X5")else GlobalColor("Xx5"));
XMA6 .AssignValueColor( if XMA6 <= XMA6[1]  then GlobalColor("X6")else GlobalColor("Xx6"));
XMA7 .AssignValueColor( if XMA7 <= XMA7[1]  then GlobalColor("X7")else GlobalColor("Xx7"));
XMA8 .AssignValueColor( if XMA8 <= XMA8[1]  then GlobalColor("X8")else GlobalColor("Xx8"));
XMA9 .AssignValueColor( if XMA9 <= XMA9[1]  then GlobalColor("X9")else GlobalColor("Xx9"));
XMA10 .AssignValueColor( if XMA10 <= XMA10[1]  then GlobalColor("X10")else GlobalColor("Xx10"));
XMA11 .AssignValueColor( if XMA11 <= XMA11[1]  then GlobalColor("X11")else GlobalColor("Xx11"));
XMA12 .AssignValueColor( if Xma12 <= Xma12[1]  then GlobalColor("X12")else GlobalColor("Xx12"));
XMA13 .AssignValueColor( if Xma13 <= Xma13[1]  then GlobalColor("X13")else GlobalColor("Xx13"));
XMA14 .AssignValueColor( if Xma14 <= Xma14[1]  then GlobalColor("X14")else GlobalColor("Xx14"));
XMA15 .AssignValueColor( if Xma15 <= Xma15[1]  then GlobalColor("X15")else GlobalColor("Xx15"));
XMA16 .AssignValueColor( if Xma16 <= Xma16[1]  then GlobalColor("X16")else GlobalColor("Xx16"));
XMA17 .AssignValueColor( if Xma17 <= Xma17[1]  then GlobalColor("X17")else GlobalColor("Xx17"));
XMA18 .AssignValueColor( if Xma18 <= Xma18[1]  then GlobalColor("X18")else GlobalColor("Xx18"));
XMA19 .AssignValueColor( if Xma19 <= Xma19[1]  then GlobalColor("X19")else GlobalColor("Xx19"));
XMA20 .AssignValueColor( if Xma20 <= Xma20[1]  then GlobalColor("X20")else GlobalColor("Xx20"));

# End of script.
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
543 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top