Bull Flag and Bear Flag Formations for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
Warehouse
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
 
Last edited:
G

GetRichOrDieTrying

Member
Does this indicator repaint or are all of the signals shown the only signals printed?
 
D

drdarshil16

New member
VIP
best way to see is, if it works in mobile, it probably is not repainting. But that is just my observation. It may not be true. Although all the repainting indicators dont work on mobile
 
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@GetRichOrDieTrying I don’t think it repaint.
 
N

Nikola

New member
is there any indicator that plots the actual flags?
 
B

Buckbull

Member
This is by far the best strategy ive come across in a long time .Made $7000 last week off this being in my watch list ! Thanks for posting !
 
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@Playstation How did you check? Based on the code, there is nothing that suggests this indicator will repaint. Also, when something repaint, you won't be able to scan for new signals on the daily chart that are within 1 bar. In the case of this indicator, you can. Maybe I'm wrong, but let me know your experience with the indicator. If it does repaint, I will include that in the original thread to warn others.
 
P

Playstation

Member
@BenTen Based on watching candles, the arrow will keep re-painting, sometimes it stays, sometimes it doesn't. I'll try to screencap tonight.
 
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@Playstation What you're referring to is just the signal waiting for confirmation while the candle is still active (the candle hasn't closed yet). Repainting is when the signal is there, but after a few candles, it disappears due to the stock moving in the opposite direction of the signal. I hope that makes sense.
 
P

Playstation

Member
@Playstation What you're referring to is just the signal waiting for confirmation while the candle is still active (the candle hasn't closed yet). Repainting is when the signal is there, but after a few candles, it disappears due to the stock moving in the opposite direction of the signal. I hope that makes sense.
👌 lemme check again tonight, will feed back.
 
B

Buckbull

Member
@BenTen Is there a way to Put this into a scan and specify that the Stochrsi on the 1 hr chart be below 20 or above 80 . What i do is I am looking at the 1 hr to make an entry to go long So If a stock fired a bull flag I would want the 1 hr stochrsi to be in oversold territory to make an entry and if the bear flag fired off I would want the 1 hr Stochrsi to be in Overbrought territory . Hope you can help . Thanks
 
Billions

Billions

Member
VIP
Warehouse
This is by far the best strategy ive come across in a long time .Made $7000 last week off this being in my watch list ! Thanks for posting !
@Buckbull what timeframe are you using it on? and when I set up my indicator on the watchlist what timeframe? Thanks!
 
N

NataUA

New member
Hello, what is the best time frame for the scan? Yesterday (11/11/19) SQ was shown as Bullish and today it is down, MCD was shown as bearish and today it is up. Any suggestions?
 
B

Buckbull

Member
I put it in a watch list http://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
 
N

NataUA

New member
I put it in a watch list http://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
Sorry for the dumb question- what is BB -Bollinger Band or something else?
 
B

Buckbull

Member
Sorry for the dumb question- what is BB -Bollinger Band or something else?
Yes Bollinger Bands they act as a rubber band stocks majority of the time dont like being outside of them
 

Top