#EMA_x5_Stack
#Created by rad14733 for usethinkscript.com
#v1.0 2021-01-02
#NOTE: EMA crossovers can be set to only paint based on long term trends.
# When configured, EMA crossovers will only paint when filtered by longer term trends (ema1 <> ema5).
# EMA Length's
input ema1Length = 8;
input ema2Length = 21;
input ema3Length = 34;
input ema4Length = 55;
input ema5Length = 89;
# Display EMA's Stacked Label
input show_stacked_label = yes;
# Conditionally Plot EMA's
plot ema1 = ExpAverage(close, ema1Length);
ema1.SetPaintingStrategy(PaintingStrategy.LINE);
ema1.SetStyle(Curve.FIRM);
ema1.SetLineWeight(2);
ema1.SetDefaultColor(Color.GREEN);
plot ema2 = ExpAverage(close, ema2Length);
ema2.SetPaintingStrategy(PaintingStrategy.LINE);
ema2.SetStyle(Curve.FIRM);
ema2.SetLineWeight(2);
ema2.SetDefaultColor(Color.YELLOW);
plot ema3 = ExpAverage(close, ema3Length);
ema3.SetPaintingStrategy(PaintingStrategy.LINE);
ema3.SetStyle(Curve.FIRM);
ema3.SetLineWeight(2);
ema3.SetDefaultColor(Color.RED);
plot ema4 = ExpAverage(close, ema4Length);
ema4.SetPaintingStrategy(PaintingStrategy.LINE);
ema4.SetStyle(Curve.FIRM);
ema4.SetLineWeight(2);
ema4.SetDefaultColor(Color.MAGENTA);
plot ema5 = ExpAverage(close, ema5Length);
ema5.SetPaintingStrategy(PaintingStrategy.LINE);
ema5.SetStyle(Curve.FIRM);
ema5.SetLineWeight(2);
ema5.SetDefaultColor(Color.BLUE);
# Calculate EMA Crossovers
# (Un-)Comment to Enable/Disable EMA corssover trend filtering
#plot x1a2 = plot_ema1 and plot_ema2 and ema1 crosses above ema2 and ema1 > ema5; #Filtered Crossovers
#plot x1a2 = plot_ema1 and plot_ema2 and ema1 crosses above ema2; #Un-Filtered Crossovers
#plot x1a2 = ema1 crosses above ema2 and ema1 > ema5; #Filtered Crossovers
plot x1a2 = ema1 crosses above ema2; #Un-Filtered Crossovers
x1a2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
x1a2.SetStyle(Curve.FIRM);
x1a2.SetLineWeight(3);
x1a2.SetDefaultColor(Color.YELLOW);
# (Un-)Comment to Enable/Disable EMA corssover trend filtering
#plot x1b2 = plot_ema1 and plot_ema2 and ema1 crosses below ema2 and ema1 < ema5; #Filtered Crossovers
#plot x1b2 = plot_ema1 and plot_ema2 and ema1 crosses below ema2; #Un-Filtered Crossovers
#plot x1b2 = ema1 crosses below ema2 and ema1 < ema5; #Filtered Crossovers
plot x1b2 = ema1 crosses below ema2; #Un-Filtered Crossovers
x1b2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
x1b2.SetStyle(Curve.FIRM);
x1b2.SetLineWeight(3);
x1b2.SetDefaultColor(Color.DARK_ORANGE);
# Define Global Colors For Clouds
# Crosses Above
DefineGlobalCOlor("x1a2", Color.GREEN);
#DefineGlobalCOlor("x2a3", Color.DARK_GREEN);
#DefineGlobalCOlor("x3a4", Color.YELLOW);
#DefineGlobalCOlor("x4a5", Color.WHITE);
# Crosses Below
DefineGlobalCOlor("x1b2", Color.RED);
#DefineGlobalCOlor("x2b3", Color.DARK_RED);
#DefineGlobalCOlor("x3b4", Color.MAGENTA);
#DefineGlobalCOlor("x4b5", Color.BLUE);
# Paint Clouds
AddCloud(ema1, ema2, GlobalColor("x1a2"), GlobalColor("x1b2"));
#AddCloud(ema2, ema3, GlobalColor("x2a3"), GlobalColor("x2b3"));
#AddCloud(ema3, ema4, GlobalColor("x3a4"), GlobalColor("x3b4"));
#AddCloud(ema4, ema5, GlobalColor("x4a5"), GlobalColor("x4b5"));
# Create Chart Label to signify that EMA's are Stacked
def stackedUp = ema1 > ema2 and ema2 > ema3 and ema3 > ema4 and ema4 > ema5;
def stackedDn = ema1 < ema2 and ema2 < ema3 and ema3 < ema4 and ema4 < ema5;
#def stackedUp = ema1 > ema2 and ema2 > ema3;
#def stackedDn = ema1 < ema2 and ema2 < ema3;
AddLabel(show_stacked_label, " EMA's Stacked ", if stackedUp then Color.GREEN else if stackedDn then Color.RED else Color.GRAY);
# END EMA_5_Stack