Simple 2 ema and 1 sma cloud with HTF capability, candle coloring, EMA cross arrow option, and structure label
# =========================================================
# === MTF EMA + SMA Structure Indicator (with EMA Cross Arrows)
# =========================================================
declare upper;
# =======================
# USER INPUTS
# =======================
input timeFrame = {default CURRENT, MIN1, MIN2, MIN3, MIN5, MIN15, MIN30, HOUR1, HOUR2, HOUR4, DAY};
input showPlots = yes;
input colorCandles = yes;
input showEMACloud = yes;
input showEMACrossArrows = yes;
input fastEMALength = 8;
input slowEMALength = 21;
input smaLength = 50;
input arrowOffsetTicks = 2;
# =======================
# GLOBAL COLORS
# =======================
DefineGlobalColor("Bull", Color.GREEN);
DefineGlobalColor("Bear", Color.RED);
DefineGlobalColor("Neutral", Color.GRAY);
# =======================
# AGGREGATION PERIOD
# =======================
def aggTF;
switch (timeFrame) {
case CURRENT:
aggTF = GetAggregationPeriod();
case MIN1:
aggTF = AggregationPeriod.MIN;
case MIN2:
aggTF = AggregationPeriod.TWO_MIN;
case MIN3:
aggTF = AggregationPeriod.THREE_MIN;
case MIN5:
aggTF = AggregationPeriod.FIVE_MIN;
case MIN15:
aggTF = AggregationPeriod.FIFTEEN_MIN;
case MIN30:
aggTF = AggregationPeriod.THIRTY_MIN;
case HOUR1:
aggTF = AggregationPeriod.HOUR;
case HOUR2:
aggTF = AggregationPeriod.TWO_HOURS;
case HOUR4:
aggTF = AggregationPeriod.FOUR_HOURS;
case DAY:
aggTF = AggregationPeriod.DAY;
}
# =======================
# PRICE & MOVING AVERAGES
# =======================
def price = close(period = aggTF);
def fastEMA = ExpAverage(price, fastEMALength);
def slowEMA = ExpAverage(price, slowEMALength);
def baseSMA = Average(price, smaLength);
# =======================
# STRUCTURE LOGIC
# =======================
def bull_fast_slow = fastEMA > slowEMA;
def bear_fast_slow = fastEMA < slowEMA;
def bull_slow_sma = slowEMA > baseSMA;
def bear_slow_sma = slowEMA < baseSMA;
def bull_structure = bull_fast_slow and bull_slow_sma;
def bear_structure = bear_fast_slow and bear_slow_sma;
def neutral_structure = !bull_structure and !bear_structure;
# =======================
# EMA CLOUDS
# =======================
AddCloud(
if showEMACloud and bull_structure then fastEMA else Double.NaN,
if showEMACloud and bull_structure then slowEMA else Double.NaN,
Color.GREEN,
Color.GREEN
);
AddCloud(
if showEMACloud and bear_structure then fastEMA else Double.NaN,
if showEMACloud and bear_structure then slowEMA else Double.NaN,
Color.RED,
Color.RED
);
AddCloud(
if showEMACloud and neutral_structure then fastEMA else Double.NaN,
if showEMACloud and neutral_structure then slowEMA else Double.NaN,
Color.GRAY,
Color.GRAY
);
# =======================
# CANDLE COLORING
# =======================
AssignPriceColor(
if !colorCandles then Color.CURRENT
else if bull_structure then GlobalColor("Bull")
else if bear_structure then GlobalColor("Bear")
else GlobalColor("Neutral")
);
# =======================
# EMA + SMA PLOTS
# =======================
plot pFastEMA = if showPlots then fastEMA else Double.NaN;
plot pSlowEMA = if showPlots then slowEMA else Double.NaN;
plot pSMA = if showPlots then baseSMA else Double.NaN;
pFastEMA.AssignValueColor(
if bull_fast_slow then GlobalColor("Bull")
else if bear_fast_slow then GlobalColor("Bear")
else GlobalColor("Neutral")
);
pSlowEMA.AssignValueColor(
if bull_slow_sma then GlobalColor("Bull")
else if bear_slow_sma then GlobalColor("Bear")
else GlobalColor("Neutral")
);
pSMA.AssignValueColor(
if bull_structure then GlobalColor("Bull")
else if bear_structure then GlobalColor("Bear")
else GlobalColor("Neutral")
);
pFastEMA.SetLineWeight(2);
pSlowEMA.SetLineWeight(2);
pSMA.SetLineWeight(2);
# =======================
# EMA CROSS LOGIC
# =======================
def bullCross = fastEMA crosses above slowEMA;
def bearCross = fastEMA crosses below slowEMA;
# =======================
# EMA CROSS ARROWS
# =======================
plot BullCrossArrow =
if showEMACrossArrows and bullCross
then low - arrowOffsetTicks * TickSize()
else Double.NaN;
BullCrossArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BullCrossArrow.SetDefaultColor(GlobalColor("Bull"));
BullCrossArrow.SetLineWeight(3);
plot BearCrossArrow =
if showEMACrossArrows and bearCross
then high + arrowOffsetTicks * TickSize()
else Double.NaN;
BearCrossArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
BearCrossArrow.SetDefaultColor(GlobalColor("Bear"));
BearCrossArrow.SetLineWeight(3);
# =======================
# LABEL
# =======================
AddLabel(
yes,
"TF: " +
(if timeFrame == timeFrame.CURRENT then "Current"
else if timeFrame == timeFrame.MIN1 then "1m"
else if timeFrame == timeFrame.MIN2 then "2m"
else if timeFrame == timeFrame.MIN3 then "3m"
else if timeFrame == timeFrame.MIN5 then "5m"
else if timeFrame == timeFrame.MIN15 then "15m"
else if timeFrame == timeFrame.MIN30 then "30m"
else if timeFrame == timeFrame.HOUR1 then "1h"
else if timeFrame == timeFrame.HOUR2 then "2h"
else if timeFrame == timeFrame.HOUR4 then "4h"
else "1D")
+ " | Structure: "
+ (if bull_structure then "Bull"
else if bear_structure then "Bear"
else "Neutral"),
if bull_structure then GlobalColor("Bull")
else if bear_structure then GlobalColor("Bear")
else GlobalColor("Neutral")
);
# =========================================================
# === MTF EMA + SMA Structure Indicator (with EMA Cross Arrows)
# =========================================================
declare upper;
# =======================
# USER INPUTS
# =======================
input timeFrame = {default CURRENT, MIN1, MIN2, MIN3, MIN5, MIN15, MIN30, HOUR1, HOUR2, HOUR4, DAY};
input showPlots = yes;
input colorCandles = yes;
input showEMACloud = yes;
input showEMACrossArrows = yes;
input fastEMALength = 8;
input slowEMALength = 21;
input smaLength = 50;
input arrowOffsetTicks = 2;
# =======================
# GLOBAL COLORS
# =======================
DefineGlobalColor("Bull", Color.GREEN);
DefineGlobalColor("Bear", Color.RED);
DefineGlobalColor("Neutral", Color.GRAY);
# =======================
# AGGREGATION PERIOD
# =======================
def aggTF;
switch (timeFrame) {
case CURRENT:
aggTF = GetAggregationPeriod();
case MIN1:
aggTF = AggregationPeriod.MIN;
case MIN2:
aggTF = AggregationPeriod.TWO_MIN;
case MIN3:
aggTF = AggregationPeriod.THREE_MIN;
case MIN5:
aggTF = AggregationPeriod.FIVE_MIN;
case MIN15:
aggTF = AggregationPeriod.FIFTEEN_MIN;
case MIN30:
aggTF = AggregationPeriod.THIRTY_MIN;
case HOUR1:
aggTF = AggregationPeriod.HOUR;
case HOUR2:
aggTF = AggregationPeriod.TWO_HOURS;
case HOUR4:
aggTF = AggregationPeriod.FOUR_HOURS;
case DAY:
aggTF = AggregationPeriod.DAY;
}
# =======================
# PRICE & MOVING AVERAGES
# =======================
def price = close(period = aggTF);
def fastEMA = ExpAverage(price, fastEMALength);
def slowEMA = ExpAverage(price, slowEMALength);
def baseSMA = Average(price, smaLength);
# =======================
# STRUCTURE LOGIC
# =======================
def bull_fast_slow = fastEMA > slowEMA;
def bear_fast_slow = fastEMA < slowEMA;
def bull_slow_sma = slowEMA > baseSMA;
def bear_slow_sma = slowEMA < baseSMA;
def bull_structure = bull_fast_slow and bull_slow_sma;
def bear_structure = bear_fast_slow and bear_slow_sma;
def neutral_structure = !bull_structure and !bear_structure;
# =======================
# EMA CLOUDS
# =======================
AddCloud(
if showEMACloud and bull_structure then fastEMA else Double.NaN,
if showEMACloud and bull_structure then slowEMA else Double.NaN,
Color.GREEN,
Color.GREEN
);
AddCloud(
if showEMACloud and bear_structure then fastEMA else Double.NaN,
if showEMACloud and bear_structure then slowEMA else Double.NaN,
Color.RED,
Color.RED
);
AddCloud(
if showEMACloud and neutral_structure then fastEMA else Double.NaN,
if showEMACloud and neutral_structure then slowEMA else Double.NaN,
Color.GRAY,
Color.GRAY
);
# =======================
# CANDLE COLORING
# =======================
AssignPriceColor(
if !colorCandles then Color.CURRENT
else if bull_structure then GlobalColor("Bull")
else if bear_structure then GlobalColor("Bear")
else GlobalColor("Neutral")
);
# =======================
# EMA + SMA PLOTS
# =======================
plot pFastEMA = if showPlots then fastEMA else Double.NaN;
plot pSlowEMA = if showPlots then slowEMA else Double.NaN;
plot pSMA = if showPlots then baseSMA else Double.NaN;
pFastEMA.AssignValueColor(
if bull_fast_slow then GlobalColor("Bull")
else if bear_fast_slow then GlobalColor("Bear")
else GlobalColor("Neutral")
);
pSlowEMA.AssignValueColor(
if bull_slow_sma then GlobalColor("Bull")
else if bear_slow_sma then GlobalColor("Bear")
else GlobalColor("Neutral")
);
pSMA.AssignValueColor(
if bull_structure then GlobalColor("Bull")
else if bear_structure then GlobalColor("Bear")
else GlobalColor("Neutral")
);
pFastEMA.SetLineWeight(2);
pSlowEMA.SetLineWeight(2);
pSMA.SetLineWeight(2);
# =======================
# EMA CROSS LOGIC
# =======================
def bullCross = fastEMA crosses above slowEMA;
def bearCross = fastEMA crosses below slowEMA;
# =======================
# EMA CROSS ARROWS
# =======================
plot BullCrossArrow =
if showEMACrossArrows and bullCross
then low - arrowOffsetTicks * TickSize()
else Double.NaN;
BullCrossArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BullCrossArrow.SetDefaultColor(GlobalColor("Bull"));
BullCrossArrow.SetLineWeight(3);
plot BearCrossArrow =
if showEMACrossArrows and bearCross
then high + arrowOffsetTicks * TickSize()
else Double.NaN;
BearCrossArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
BearCrossArrow.SetDefaultColor(GlobalColor("Bear"));
BearCrossArrow.SetLineWeight(3);
# =======================
# LABEL
# =======================
AddLabel(
yes,
"TF: " +
(if timeFrame == timeFrame.CURRENT then "Current"
else if timeFrame == timeFrame.MIN1 then "1m"
else if timeFrame == timeFrame.MIN2 then "2m"
else if timeFrame == timeFrame.MIN3 then "3m"
else if timeFrame == timeFrame.MIN5 then "5m"
else if timeFrame == timeFrame.MIN15 then "15m"
else if timeFrame == timeFrame.MIN30 then "30m"
else if timeFrame == timeFrame.HOUR1 then "1h"
else if timeFrame == timeFrame.HOUR2 then "2h"
else if timeFrame == timeFrame.HOUR4 then "4h"
else "1D")
+ " | Structure: "
+ (if bull_structure then "Bull"
else if bear_structure then "Bear"
else "Neutral"),
if bull_structure then GlobalColor("Bull")
else if bear_structure then GlobalColor("Bear")
else GlobalColor("Neutral")
);
Last edited: