• Get $30 off VIP with code SUMMER30. Ends July 27. Happy trading!

Bull Flag and Bear Flag Formations for ThinkorSwim

BenTen

Administrative
Staff
VIP
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.

9pBn4DQ.jpg


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: https://tos.mx/nGYN7x

mLRHr5G.png


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: https://tos.mx/5bxCeS

New Watchlist Update

974gKFy.png


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:

drdarshil16

New member
2019 Donor
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

Administrative
Staff
VIP
@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.
 

BenTen

Administrative
Staff
VIP
@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.
 

Playstation

Active member
VIP
@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.
 

Buckbull

Active 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
 

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?
 

Buckbull

Active member
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
 

NataUA

New member
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
Sorry for the dumb question- what is BB -Bollinger Band or something else?
 

Similar threads

Top