Bullish and Bearish Engulfing Candles in ThinkorSwim

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
Engulfing pattern on your candlestick chart can be useful for identifying trend changes, potential reversal play, etc. Here is an indicator for ThinkorSwim that will automatically find and highlight Engulfing candle on your chart. Both bullish and bearish engulfing patterns.

I also included labels and a unique color for each type of pattern. By default, a bullish engulfing candle will be yellow and a bearish engulfing candle will be purple. You can change this via the source code. This works for any timeframes.

Gr202cS.png


thinkScript Code

Rich (BB code):
#
# TD Ameritrade IP Company, Inc. (c) 2011-2018
# Modified by BenTen @ usethinkscript.com
#
#wizard plots
#wizard text: Inputs: length:
#wizard input: length
#wizard text: trend setup:
#wizard input: trendSetup

input length = 20;
input trendSetup = 3;

def BodyMax = Max(open, close);
def BodyMin = Min(open, close);
def IsEngulfing = BodyMax > BodyMax[1] and
    BodyMin < BodyMin[1];
def IsWhite = open < close;
def IsBlack = open > close;
def IsPrevDoji = IsDoji(length)[1];

plot Bearish = IsAscending(close, trendSetup)[1] and
    (IsWhite[1] or IsPrevDoji) and
    IsBlack and
    IsEngulfing;

plot Bullish = IsDescending(close, trendSetup)[1] and
    (IsBlack[1] or IsPrevDoji) and
    IsWhite and
    IsEngulfing;

assignpriceColor(if Bearish then Color.VIOLET else if Bullish then Color.Yellow else Color.Current);
AddLabel(yes,"Bu_Engulf",color.Yellow);
AddLabel(yes,"Be_Engulf",color.VIOLET);

Shareable Link

https://tos.mx/nirPCb

P.S: To fix the shrinking issue, be sure to untick "Show Plot" for Bullish and Bearish options in the indicator's setting.
 
Last edited:

bh129022

New member
@BenTen I know it's been a year, but I'm very new to trading and I've been studying patterns. How do I get my chart to this on TOS? I'm just paper trading right now and it'd be nice to see this live, while I'm learning.
 
Hello!

Does anyone have any way to scan for an engulfing pattern bullish? There are indicators on this site for bullish patterns, but there are no scanners for them.
 

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
@TopDog Here is the updated code:

Code:
# Engulfing Candle with Fibonacci Values
# Assembled by BenTen at UseThinkScript.com

input length = 20;
input trendSetup = 3;
input ShowTodayOnly = yes;
def Today = if GetDay() == GetLastDay() then 1 else 0;

def BodyMax = Max(open, close);
def BodyMin = Min(open, close);
def IsEngulfing = BodyMax > BodyMax[1] and
    BodyMin < BodyMin[1];
def IsWhite = open < close;
def IsBlack = open > close;
def IsPrevDoji = IsDoji(length)[1];

plot Bearish = IsAscending(close, trendSetup)[1] and
    (IsWhite[1] or IsPrevDoji) and
    IsBlack and
    IsEngulfing;

plot Bullish = IsDescending(close, trendSetup)[1] and
    (IsBlack[1] or IsPrevDoji) and
    IsWhite and
    IsEngulfing;

Bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Bearish.SetDefaultColor(GetColor(1));
Bearish.SetLineWeight(2);
Bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Bullish.SetDefaultColor(GetColor(2));
Bullish.SetLineWeight(2);

def up_candle = bullish;
def down_candle = bearish;

def bu_high = if up_candle then high else bu_high[1];
def bu_low = if up_candle then low  else bu_low[1];

plot hh1 = bu_high;
plot ll1 = bu_low;

def be_high = if down_candle then high else be_high[1];
def be_low = if down_candle then low  else be_low[1];

plot hh2 = be_high;
plot ll2 = be_low;

hh1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ll1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hh1.SetDefaultColor(Color.YELLOW);
ll1.SetDefaultColor(Color.YELLOW);
hh2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ll2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hh2.SetDefaultColor(Color.YELLOW);
ll2.SetDefaultColor(Color.YELLOW);

def range = hh1 - ll1;
input fib1 = 0.618;
input fib2 = 0.236;
input fib3 = 0.382;
input fib4 = 0.5;
input fib5 = 0.786;
input fib6 = 1.618;
input fib7 = 2.618;
input fib8 = 4.236;

# Fibs for bullish candles
plot h = if ShowTodayOnly and !Today then Double.NaN else hh1 + range*(fib1-1);
plot h1 = if ShowTodayOnly and !Today then Double.NaN else hh1 + range*(fib2-1);
plot h2 = if ShowTodayOnly and !Today then Double.NaN else hh1 + range*(fib3-1);
plot h3 = if ShowTodayOnly and !Today then Double.NaN else hh1 + range*(fib4-1);
plot h4 = if ShowTodayOnly and !Today then Double.NaN else hh1 + range*(fib5-1);
plot h5 = if ShowTodayOnly and !Today then Double.NaN else hh1 + range*(fib6-1);
plot h6 = if ShowTodayOnly and !Today then Double.NaN else hh1 + range*(fib7-1);
plot h7 = if ShowTodayOnly and !Today then Double.NaN else hh1 + range*(fib8-1);

# Fibs for bearish candles
plot h8 = if ShowTodayOnly and !Today then Double.NaN else ll2 - range*(fib1-1);
plot h9 = if ShowTodayOnly and !Today then Double.NaN else  - range*(fib2-1);
plot h10 = if ShowTodayOnly and !Today then Double.NaN else ll2 - range*(fib3-1);
plot h11 = if ShowTodayOnly and !Today then Double.NaN else ll2 - range*(fib4-1);
plot h12 = if ShowTodayOnly and !Today then Double.NaN else ll2 - range*(fib5-1);
plot h13 = if ShowTodayOnly and !Today then Double.NaN else ll2 - range*(fib6-1);
plot h14 = if ShowTodayOnly and !Today then Double.NaN else ll2 - range*(fib7-1);
plot h15 = if ShowTodayOnly and !Today then Double.NaN else ll2 - range*(fib8-1);
 

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.
Top