Bull Flag and Bear Flag Formations for ThinkorSwim

B

Buckbull

Member
@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
 
B

Buckbull

Member
@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;
Does He have one for a Bear Flag as well ?
 
T

tomsk

Well-known member
VIP
@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
 
B

Buckbull

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

# 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
Thank you sir , Does he have a site or did you save these scripts from other places ?
 
T

tomsk

Well-known member
VIP
@Buckbull I happen to have this saved from some time back. Glad to assist. Have a great evening
 
B

Buckbull

Member
@tomsk I just at looked at both of his scans His scans as Im sure you know let you know something is in a flag pattern still. Kens let you know it possibly broke out. Mobius is a good scan to do alert with drawing to let you know when it breaks out .
 
T

tomsk

Well-known member
VIP
@Buckbull An excellent comment (y) very well done. Just a thought - perhaps you might like to explore combining both of these indicators and see what sort of results you might get
 
allpozitiv

allpozitiv

New member
2019 Donor
Warehouse
Ken Rose updated the BFBF Indicator to be more sensitive to trend , here's the link https://tos.mx/6xou4xs
Does anybody understand how to use this watchlist quote? As I uploaded this in TOS and applied indicator from post#1, but still cannot see how it correllates between each other. Example stock: FND. It shows in Watchlist (5m agg) sign down, but in chart there is no arrow in such case.

Below is the link to see described scenario:
https://prnt.sc/pxr6ao
 
T

tsleong

New member
I was trying figure out how to get the watchlist column

I have the indicator working, but not the watchlist, I couldn't figure out where to copy and paste the watchlist info.
 
B

Buckbull

Member
Go into your watchlist and click the little gear that says customize .then type in whatever you named it it will appear double click it and it will be put in your watchlist .
 
B

Buckbull

Member
Does anybody understand how to use this watchlist quote? As I uploaded this in TOS and applied indicator from post#1, but still cannot see how it correllates between each other. Example stock: FND. It shows in Watchlist (5m agg) sign down, but in chart there is no arrow in such case.

Below is the link to see described scenario:
https://prnt.sc/pxr6ao
Use it on the Daily not 5 min .
 
D

dolcea23

New member
Ken Rose of TD Ameritrade recently shared a watchlist column that shows potential bull flag and bear flag patterns being formed. I modified it a little so that it can also plot bull flag signal and also bear flag signal on your chart.



Here is the watchlist column:

Code:
# [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);
Shareable Link: http://tos.mx/nGYN7x



Here is the indicator

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
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);

# Plot Confirmed Signals
plot bullish = Bulltrigger;
bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullish.SetDefaultColor(Color.CYAN);
bullish.SetLineWeight(1);
plot bearish = BearTrigger;
bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearish.SetDefaultColor(Color.CYAN);
bearish.SetLineWeight(1);
Shareable link: http://tos.mx/5bxCeS

New Watchlist Update



Ken Rose recently updated his watchlist column. Here is the new code with a bit more customization :)

Code:
# 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);
############################################################
Shareable Link: https://tos.mx/6xou4xs
I am confused on where to put these source codes. example watchlist and scanner. Please help
 
T

tomsk

Well-known member
VIP
@dolcea23 Indeed, there sure are differences in where to deploy code for studies, strategies, scanner, watchlists, etc. Have a look through the tutorial section that @BenTen and many other contributors have posted and you'll soon get the hang of it

 
D

dolcea23

New member
@dolcea23 Indeed, there sure are differences in where to deploy code for studies, strategies, scanner, watchlists, etc. Have a look through the tutorial section that @BenTen and many other contributors have posted and you'll soon get the hang of it

I know how to input the indicator but where do I input the scanner and watchlist
 
D

dolcea23

New member
Go into your watchlist and click the little gear that says customize .then type in whatever you named it it will appear double click it and it will be put in your watchlist .
So I put the custom watch list second link from been and added the indicator. Im now sure how it correlates because stock list show bull yet the flag is bearish on chart. Please help
 
B

Buckbull

Member
So I put the custom watch list second link from been and added the indicator. Im now sure how it correlates because stock list show bull yet the flag is bearish on chart. Please help
what stock are you referring to ?
 
T

tsleong

New member
Is there a way to change the timeframe on the watchlist to 30 Min or something else, I think its default to 1 day, but in the code, I didn't see a timeframe location. It does look awesome by the way.
 
B

Buckbull

Member
Is there a way to change the timeframe on the watchlist to 30 Min or something else, I think its default to 1 day, but in the code, I didn't see a timeframe location. It does look awesome by the way.
Yes go to edit script and in the top of the Box you will see timeframe and will see the letter D click on that and you could switch to a different time frame
 
J

joshua74133

New member
im looking for something that will draw the flag on the chart.
 

Top