# Bull Flag and Bear Flag Formations for ThinkorSwim

Under the second condition (on the right) select RSI under Study.

Ken Rose updated the BFBF Indicator to be more sensitive to trend , here's the link https://tos.mx/6xou4xs

@Buckbull Possible to post the code here in this study? I avoid Watchlist links as it is not possible to DELETE any such watchlists once it has been imported

@BenTen Which post # is that ? #1 or #2 ? If so I'm good else please advise

@BenTen I looked at Ken Rose's code, it seems that his definition of a bull flag has no mention of a typical flag pole vide the following snippet extracted from his code

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 Bulltrigger = trend and MacdLow;

I reviewed Mobius implementation of a bull flag scan - he uses a fractal energy computation as part of the equation amongst other things.

@tomsk Yup, this flag formation by Ken Rose is different from what you would look for in a typical flag pattern. Not sure why he called it that.

whatever he calls it , it works !!

@tomsk Do you have the Mobius script I would like to check it out .

@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) > .68;
def LowVol = volume < Average(volume, 50);

plot Flag = upward and p and FE and LowVol;

I put it in a watch list https://tos.mx/Nn4Oje1 criteria \$20.00 stock with a volume at or above 250,000. then I add the Bullflag Bearflag into my watchlist . I just go through the watchlist seeing where the MA's are and where the candle is in relation to the BB whether they are pointed up, down or flat . Thats what dictates if I get into trade or not

Hi @Buckbull , which BB length and standard deviation have you found to be most useful on the daily chart? - and do you play weeklies or month or so out for Options expiry?

Thanks!

Have you guys compared the two to see what one is more accurate ?

@Buckbull A bull flag is usually described with the notion of a flag pole. Mobius incorporates that in his code while in Ken Rose's study he does not.

@Buckbull A bull flag is usually described with the notion of a flag pole. Mobius incorporates that in his code while in Ken Rose's study he does not.
I have heard references about Mobius on this site so many times, who is he/she?

@ganq he is a very talented and well versed in thinkscript, written thousands of wonderful studies, a professor, mathematician, programmer at large. Many of studies here like Opening Range Breakout, RSI Laguerre and others were written by him.

@Buckbull A bull flag is usually described with the notion of a flag pole. Mobius incorporates that in his code while in Ken Rose's study he does not.
Kens Alerts you after it breaks out of the Flag

@ganq I change the length to 21 and leave the deviations alone 2 -2 . I buy monthlys 1 strike out of the money I buy 2 months out . You would be shocked how good 2 months out moves and you dont get really crushed on the pullbacks . I brought Dec 20 140 call on JAZZ today I made 64% today on it . What I brought for \$2.15 a contract I sold for \$3.50

@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) > .68;
def LowVol = volume < Average(volume, 50);

plot Flag = upward and p and FE and LowVol;
Does He have one for a Bear Flag as well ?

@Buckbull He sure does, here is the companion bear flag scan. Hope this helps

Code:
``````# Bear Flag on Pole - SCAN
# Mobius
# V01.02.2014
# Price trend - Downward leading to the pattern. The price should fall for at least 2 months.
# Shape - A consolidation pattern forms. It usually doesn't look like a flag or pennant, just a pause in the price decline.
# Volume - Recedes for best performance
# Confirmation - The pattern confirms as valid when price closes below the lowest trough in the pattern.

def o = open;
def h = high;
def l = low;
def c = close;
def BBl = BollingerBands().LowerBand;
def KCl = KeltnerChannels().Lower_Band;
def downward = isDescending(close, 42);
def p = (c[42] / lowest(l, 21)) > 1.2;
def squeezeLow = if BBl < KCl
then squeezeLow[1]
else if BBl crosses above KCl
then l
else if BBl > KCl and l < squeezeLow[1]
then l
else squeezeLow[1];
def NotSqueeze = BBl < KCl;
plot Flag = if downward and
p and
NotSqueeze and
close crosses below squeezeLow
then 1
else Double.NaN;
# End Code Bear Flag``````

Automatic patterns studies, Bull, Bear, Bullish only & Bearish only For ThinkOrSwim Indicators 7

87k+ Posts
303 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?