Bull Flag and Bear Flag Formations for ThinkorSwim

Improvement for me. Thank you.

Would you mind posting the script for the column please? The link posted here as "column" is coming up as a scanned watchlist.
I thinks it's in the thread, ..........
# Follow @KRose_TDA on twitter for updates to this and other scripts
# Thanks to Alan Burch for emoji enhancement
# Thumbs up = potential Bull Flag - Thumbs Down potential bear flag
# To use for scan place # signs before 2 Addlabel statements.
# For Bull Flag Scan change "def" before Bulltrigger statement to "plot"
# For Bear Flag scan change "def" before BearTrigger Statement to "Plot"
#Enter desired distance of flag by changing FlagDistance value
def FlagDistance = .75; #Percent of ATR from high/low
##############Bull Flag
def StockPrice = close>=10;

##############ThinkScriptWebcast##################
def FATR = ATR();
def trigATR = (highest(high,5)-close)> (FlagDistance*FATR); #flag slopping down
def PriceSma = close>simpleMovingAvg("length"=30); #Trend still in force

##########################################
def trend = simpleMovingAvg("length"=30)> (simpleMovingAvg("length"=30)[5]);
def MacdLow = macdHistogram(8,17,9)[1]< macdHistogram(8,17,9)[2]and close[1]<close[2];
#def Momentum = macdHistogram(8,17,9) > macdHistogram(8,17,9)[1];
##############Bear Flag
def StockPriceBear = close>=10;
def trendBear = simpleMovingAvg("length"=30)< (simpleMovingAvg("length"=30)[5]);
def MacdHighBear = macdHistogram(8,17,9)[1]> macdHistogram(8,17,9)[2]and close[1]>close[2];
#########################################
##############ThinkScriptWebcast##################
def BFATR = reference ATR();
def BtrigATR = (close-lowest(low,5))> (FlagDistance*FATR); #flag slopping up
def BPriceSma = close<simpleMovingAvg("length"=30); #Trend still in force

##########################################

def Bulltrigger = trend and MacdLow and trigATR and PriceSma;
def BearTrigger = TrendBear and MacdHighBear and BtrigATR and BPriceSma ;

AssignBackgroundColor(if Bulltrigger then color.YELLOW else if bearTrigger then color.LIGHT_RED else color.WHITE);

##########################################################
AddLabel(yes, if Bulltrigger then "👍" else if BearTrigger then "👎" else " ", if BearTrigger then Color.dark_red else if Bulltrigger then Color.dark_GREEN else Color.ORANGE);
AssignBackgroundColor(color.light_ORANGE);
############################################################
 
Improvement for me. Thank you.

Would you mind posting the script for the column please? The link posted here as "column" is coming up as a scanned watchlist.
Here's another that can be turned into scan by using # in front of plot......
# [email protected] CBLOLD Search
#To use for scan place # signs before 2 Addlabel statements and change "def" before trigger statement to "plot"
##############Bull Flag
def StockPrice = close>=10;
def trend = simpleMovingAvg("length"=30)> (simpleMovingAvg("length"=30)[5]);
def MacdLow = macdHistogram(8,17,9)[1]< macdHistogram(8,17,9)[2]and close[1]<close[2] and close>high[1];
#def Momentum = macdHistogram(8,17,9) > macdHistogram(8,17,9)[1];
##############Bear Flag
def StockPriceBear = close>=10;
def trendBear = simpleMovingAvg("length"=30)< (simpleMovingAvg("length"=30)[5]);
def MacdHighBear = macdHistogram(8,17,9)[1]> macdHistogram(8,17,9)[2]and close[1]>close[2] and close<low[1];
#########################################
#def trigger = trend and momentum and MacdLow;
def Bulltrigger = trend and MacdLow;
def BearTrigger = TrendBear and MacdHighBear;

#AddLabel(yes, if Bulltrigger then "Bull Flag" else " ",Color.PLUM);
AddLabel(yes, if Bulltrigger then "Bull Flag" else if BearTrigger then "Bear Flag" else " ",Color.black);
AssignBackgroundColor(if Bulltrigger then color.YELLOW else if bearTrigger then color.LIGHT_RED else color.WHITE);
 
Hi Everyone,

I am looking for a ThinkorSwim code that can scan for stocks with the Bull/Bear pennant pattern on hourly, 4Hr, and daily time frames. Only the scanner but not the
indicator (that plots on the chart).


BullBear Pennant.PNG



Can someone please share if they have one?

Thanks in advance!
 
I have this bull flag indicator I pulled from the post here: https://usethinkscript.com/threads/bull-flag-and-bear-flag-formations-for-thinkorswim.467/

I modified it to work for day traders. I use this indicator while showing the 1 MIN chart, but its aggregation is on the 3 min chart. So I can see ALL bull flag formations on the 3 minute charts, at the 1 min chart level.

HOW TO:
  1. Add the script to your 1 min chart.
  2. ONLY use this on a moving upward trend. I use a 20 chart layout, opening this up with Trade Ideas scanners. I find the Momentum stocks that are continuing to hit new highs. The problem with these stocks, is you never know when they will crash, right? So now you know, when they will push up.
  3. When I place these upward trend charts and this indicator finds a bull flag, it sends me a PING. I look at the chart and I have about 30 seconds - 5 minutes to decide if I will enter the trade.
    1. If its a flag sideways bull flag, I have longer to decide. If its a moving upwards bull flag, I have 30 seconds or so to decide to enter the trade.
  4. I kid you not, 9 times out of 10 bull flags that appear, this one makes money on UPWARD trending stocks 90% of the time.
This is one of my favorite indicators as it makes money ALL day long when paired with a momentum trending up scanner.

Code:
# Bull Flag and Bear Flag Indicator
# Original from https://twitter.com/KRose_TDA/status/1158974048518328320
# [email protected] CBLOLD Search
#To use for scan place # signs before 2 Addlabel statements and change "def" before trigger statement to "plot"
# Modified by BenTen at useThinkScript to Display Signals on Chart
##############Bull Flag
input agg3 = AggregationPeriod.Three_MIN;

def StockPrice = close(period=agg3)>=10;
def trend = simpleMovingAvg("length"=90)> (simpleMovingAvg("length"=90)[5]);
def MacdLow = macdHistogram(24,51,27)[1]< macdHistogram(24,51,27)[2]and close(period=agg3)[1]<close(period=agg3)[2] and close(period=agg3)>high(period=agg3)[1];
#def Momentum = macdHistogram(8,17,9) > macdHistogram(8,17,9)[1];
##############Bear Flag
def StockPriceBear = close(period=agg3)>=10;
def trendBear = simpleMovingAvg("length"=90)< (simpleMovingAvg("length"=90)[5]);
def MacdHighBear = macdHistogram(24,51,27)[1]> macdHistogram(24,51,27)[2]and close(period=agg3)[1]>close(period=agg3)[2] and close(period=agg3)<low(period=agg3)[1];
#########################################
#def trigger = trend and momentum and MacdLow;
def Bulltrigger = trend and MacdLow;
def BearTrigger = TrendBear and MacdHighBear;

Alert (Bulltrigger,"BULL FLAG", Alert.Bar, Sound.Bell);

AddLabel(yes, if Bulltrigger then "Bull Flag" else "",Color.PLUM);
#AddLabel(yes, if Bulltrigger then "Bull Flag" else if BearTrigger then "Bear Flag" else " ",Color.black);
#AssignBackgroundColor(if Bulltrigger then color.YELLOW else if bearTrigger then color.LIGHT_RED else color.WHITE);

# Plot Confirmed Signals
plot bullish = Bulltrigger;
bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullish.SetDefaultColor(Color.RED);
bullish.SetLineWeight(1);
plot bearish = BearTrigger;
bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearish.SetDefaultColor(Color.CYAN);
bearish.SetLineWeight(1);
Hi, I've been using this script for the past couple of weeks, which has been extremely helpful. However, I've noticed that the BULL FLAG Alert only reflects "BULL FLAG" even when a Bearish reversal occurs. Is there a way to update the script to trigger "BEAR FLAG" as well, instead of only & always alerting "BULL FLAG" regardless of the stocks direction? I'm hoping to avoid trade confusions as I've just received a BULL FLAG Trigger while the stock ($AMZN) was clearing reversing towards a Bearish direction. Please assist & Thanks in advance,
 
Hi, I've been using this script for the past couple of weeks, which has been extremely helpful. However, I've noticed that the BULL FLAG Alert only reflects "BULL FLAG" even when a Bearish reversal occurs. Is there a way to update the script to trigger "BEAR FLAG" as well, instead of only & always alerting "BULL FLAG" regardless of the stocks direction? I'm hoping to avoid trade confusions as I've just received a BULL FLAG Trigger while the stock ($AMZN) was clearing reversing towards a Bearish direction. Please assist & Thanks in advance,
In your code, there are "Plots," one bullish, other bearish,..... you either make two different scans Bull/Bear and (#) hashtag one plot or leave so. The other thing is using these columns FLAG https://tos.mx/AiyoCt3 TRENDBULL https://tos.mx/2Py0zL7
there is a column system Ken created.......
 
In your code, there are "Plots," one bullish, other bearish,..... you either make two different scans Bull/Bear and (#) hashtag one plot or leave so. The other thing is using these columns FLAG https://tos.mx/AiyoCt3 TRENDBULL https://tos.mx/2Py0zL7
there is a column system Ken created.......
Thanks for the response. I'm currently not using the scanner feature, as I'm only using this indicator for day trading but let me back test the scripts you've provided. Thanks for the quick response and awesome work! I've truly enjoyed my membership thus far!!! #happytrading
 
Pennants Breakout
Guys, Do you have any scan/ Watch list that can indicate particular stock in Pennants break. so that I can buy on those stocks. I like Alert for Scan /Watchlist
 
Last edited by a moderator:
Last edited:
@Buckbull per your request here is Mobius Bull Flag scan

# Bull Flag on Pole - SCAN
# Mobius
# V01.02.2014

# Price trend - Upward leading to the pattern.
# Shape - A consolidation pattern forms.
# Volume - Recedes for best performance
# Confirmation - The pattern confirms as valid when price closes above the highest peak in the pattern.

input n = 21;

def upward = IsAscending(HL2, 65);
def p = (highest(high, 21) / close[65]) > 1.1;
def h = high;
def l = low;
def c = close;
def FE = (Log(Sum(TrueRange(h, c, l), n) /
(Highest(h, n) - Lowest(l, n))) /
Log(n)) > .68;
def LowVol = volume < Average(volume, 50);

plot Flag = upward and p and FE and LowVol;
Hi Tom, Do you happen to have the full study instead of a scan.... including the Bear Flag
 
Hi Tom, Do you happen to have the full study instead of a scan.... including the Bear Flag
Yes the script in your post works a study by adding the following to the bottom of the script:
Code:
flag.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

The script in your post has no definition for Bear Flag but there are several scripts in this thread that will provide that including the one in the 1st post.
 
Hello team,
I have recently enrolled. does anyone ever did the megaphone pattern setup on the SPX of any stocks, if so can you please share the study if possible. Thanks
 
Ruby:
#Bull Flag on Pole - SCAN
# Mobius
# V01.02.2014
# Price trend - Upward leading to the pattern. The price should rise by at least 90% in less than 2 months.
# Shape - A consolidation pattern forms after price doubles. It usually doesn't look like a flag or pennant, just a pause in the price rise.
# Volume - Recedes for best performance
# Confirmation - The pattern confirms as valid when price closes above the highest peak in the pattern.
input n = 21;

def upward = IsAscending(HL2, 65);
def p = (highest(high, 21) / close[65]) > 1.1;
def h = high;
def l = low;
def c = close;
def FE = (Log(Sum(TrueRange(h, c, l), n) /
         (Highest(h, n) - Lowest(l, n))) /
          Log(n)) > .68;

plot Flag = upward and p and FE;
 
https://usethinkscript.com/threads/best-bull-flag-indicator-yet-for-thinkorswim.4278/post-39401
"If its a flag sideways bull flag, I have longer to decide. If its a moving upwards bull flag, I have 30 seconds or so to decide to enter the trade."
Referring to the post #1, what is flag sideways bull flag? what is moving upwards bull flag?
The OP uses this scanner:
https://usethinkscript.com/threads/...or-yet-for-thinkorswim.4278/page-2#post-55417
The OP states:
So I can see ALL bull flag formations on the 3 minute charts, at the 1 min chart level.
From what I can understand from the OP's post, the OP then reviews those charts and based on what type of flag is forming, decides on whether to take a trade.
 
Hello team,
I have recently enrolled. does anyone ever did the megaphone pattern setup on the SPX of any stocks, if so can you please share the study if possible. Thanks
Moved your question to this thread which has 6 pages that discuss pendants / flags / megaphones.
 

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