Repaints HTF 2 EMA 1 SMA Cloud with EMA cross for ThinkOrSwim

Repaints

Ajordan930

Member
VIP
Simple 2 ema and 1 sma cloud with HTF capability, candle coloring, EMA cross arrow option, and structure label

1769467861921.png


# =========================================================
# === 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:

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
1234 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