Bollinger Bands Format, Watchlist, Label, Scan For ThinkOrSwim

I want to scan my watchlist (over 300 symbols) to get a count of how many symbols have candles that have crossed the upper (or lower) Bollinger band, and are now heading in the opposite direction. I would like this for the Daily time frame. I find that when that happens to a large number of symbols, it is very likely a "moving day" where trades are plentiful. Any help with this is appreciated.
 
I want to scan my watchlist (over 300 symbols) to get a count of how many symbols have candles that have crossed the upper (or lower) Bollinger band, and are now heading in the opposite direction. I would like this for the Daily time frame. I find that when that happens to a large number of symbols, it is very likely a "moving day" where trades are plentiful. Any help with this is appreciated.


when the goal is to make a scan, i start with a chart study, so i can see things to verify what is happening. either an upper or lower, depending on primary study used.
then i make a lower study that plots 1 or 0. this should work in a scan. i don't scan so i didn't test it.

------------------

lower / scan code
this has an output of 1 or 0, when price is above the bands or below the bands and reversing.


Code:
# bb_bands_cross_rev_00b_lower


#https://usethinkscript.com/threads/need-a-bollinger-band-study-and-or-scan.14603/
#Need a Bollinger Band study and/or scan
#ttsdmagic 
#2/24

#I want to scan my watchlist (over 300 symbols) to get a count of how many symbols have candles that have crossed the upper (or lower) Bollinger band, and are now heading in the opposite direction. I would like this for the Daily time frame. I find that when that happens to a large number of symbols, it is very likely a "moving day" where trades are plentiful. Any help with this is appreciated.


#   assign # for each step
# 2 = close > upper Bollinger band  and  close < close[1] (dropping)
# 1 = close crossed above upper Bollinger band and close > close[1] (rising)
# 0 = cancel ... #close crosses below upper  or   close crosses above lower
# -1 = close crossed below lower Bollinger band and close < close[1] (dropping)
# -2 = close < lower Bollinger band  and  close > close[1] (rising)


declare lower;

def bn = barnumber();
def na = double.nan;

def bbupper = BollingerBands().UpperBand;
def bblower = BollingerBands().LowerBand;
def bbmid = BollingerBands().MidLine;


def t = if bn == 1 then 0
  else if close crosses below bbmid or close crosses above bbmid then 0
  else if close > bbupper and close[1] < bbupper then 1
  else if close < bblower and close[1] > bblower then -1
  else if t[1] == 1 and close < close[1] then 2
  else if t[1] == -1 and close > close[1] then -2
  else t[1];


# wedges - crossing
def z1 = if t == 1 and t[1] != 1 then 1 else 0;
def z2 = if t == -1 and t[1] != -1 then 1 else 0;

#  arrows - reversal
def z3 = if t == 2 and t[1] != 2 then 1 else 0;
def z4 = if t == -2 and t[1] != -2 then 1 else 0;

# reversal signals
plot z = if z3 or z4 then 1 else 0;


addlabel(0,
(if z1 then "xup"
else if z2 then "xdwn"
else if z3 then "REV dwn"
else if z4 then "REV up"
else "-")
, (if z1 then color.cyan
else if z2 then color.yellow
else if z3 then color.red
else if z4 then color.green
else color.gray)
);

#

upper and lower studies
wedges on crossing of a bb line
arrows when price reverses, after a crossing
c8OoSWz.jpg



-------------------


upper study for testing


Code:
# bb_bands_cross_rev_00b_upper

#https://usethinkscript.com/threads/need-a-bollinger-band-study-and-or-scan.14603/
#Need a Bollinger Band study and/or scan

def bn = barnumber();
def na = double.nan;


#def green = close > close[1];
#def red = close < close[1];

def bbupper = BollingerBands().UpperBand;
def bblower = BollingerBands().LowerBand;
def bbmid = BollingerBands().MidLine;

input show_bb_lines = yes;
plot bu = bbupper;
plot bm = bbmid;
plot bl = bblower;


#   assign # for each step
# 2 = close > upper Bollinger band  and  close < close[1] (dropping)
# 1 = close crossed above upper Bollinger band and close > close[1] (rising)
# 0 = cancel ... #close crosses below upper  or   close crosses above lower
# -1 = close crossed below lower Bollinger band and close < close[1] (dropping)
# -2 = close < lower Bollinger band  and  close > close[1] (rising)


def t = if bn == 1 then 0
  else if close crosses below bbmid or close crosses above bbmid then 0
  else if close > bbupper and close[1] < bbupper then 1
  else if close < bblower and close[1] > bblower then -1
  else if t[1] == 1 and close < close[1] then 2
  else if t[1] == -1 and close > close[1] then -2
  else t[1];


plot z1 = if t == 1 and t[1] != 1 then 1 else 0;
z1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_up);
z1.SetDefaultColor(Color.yellow);
z1.setlineweight(2);
z1.hidebubble();

plot z2 = if t == -1 and t[1] != -1 then 1 else 0;
z2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
z2.SetDefaultColor(Color.yellow);
z2.setlineweight(2);
z2.hidebubble();


#  arrows
plot z3 = if t == 2 and t[1] != 2 then high else na;
z3.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
z3.SetDefaultColor(Color.red);
z3.setlineweight(3);
z3.hidebubble();

plot z4 = if t == -2 and t[1] != -2 then low else na;
z4.SetPaintingStrategy(PaintingStrategy.ARROW_up);
z4.SetDefaultColor(Color.green);
z4.setlineweight(3);
z4.hidebubble();
#

-------------------

watchlist study



column study

zbbxrev
http://tos.mx/Lf4aZln

Code:
# zbbxrev

# chg lower to a column
# bb_bands_cross_rev_00b_lower

#https://usethinkscript.com/threads/need-a-bollinger-band-study-and-or-scan.14603/
#Need a Bollinger Band study and/or scan

#   assign # for each step
# 2 = close > upper Bollinger band  and  close < close[1] (dropping)
# 1 = close crossed above upper Bollinger band and close > close[1] (rising)
# 0 = cancel ... #close crosses below upper  or   close crosses above lower
# -1 = close crossed below lower Bollinger band and close < close[1] (dropping)
# -2 = close < lower Bollinger band  and  close > close[1] (rising)

def bn = barnumber();
def na = double.nan;

def bbupper = BollingerBands().UpperBand;
def bblower = BollingerBands().LowerBand;
def bbmid = BollingerBands().MidLine;

def t = if bn == 1 then 0
  else if close crosses below bbmid or close crosses above bbmid then 0
  else if close > bbupper and close[1] < bbupper then 1
  else if close < bblower and close[1] > bblower then -1
  else if t[1] == 1 and close < close[1] then 2
  else if t[1] == -1 and close > close[1] then -2
  else t[1];

# find when t changes
def z1 = if t == 1 and t[1] != 1 then 1 else 0;
def z2 = if t == -1 and t[1] != -1 then 1 else 0;
def z3 = if t == 2 and t[1] != 2 then 1 else 0;
def z4 = if t == -2 and t[1] != -2 then 1 else 0;


addlabel(1,
(if z1 then "xup"
else if z2 then "xdwn"
else if z3 then "REV dwn"
else if z4 then "REV up"
else "-")
, color.black);


assignbackgroundcolor( 
 (if z1 then color.cyan
else if z2 then color.yellow
else if z3 then color.red
else if z4 then color.green
else color.gray)
);

#



-------------------------

ref
https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/A-B/BollingerBands
Plots
. MidLine
. LowerBand
. UpperBand
 
I need help coding for a bubble on the right side of the screen and a line to show the Bollinger Band level. If it above the upper BB changes color from Red to Green and visa versa. Need to be able to set the BB level.
 
Last edited:
Reaching out for coding for a BB label to be displayed on the right side of the screen. Positive BB label displayed in green. Negative BB label to be displayed in red. With an adjustable period and number devin the input section. For all those who have assisted me with coding in the past, all have worked and I am appreciative of your assistance
 
I'm running into a similar issue with the wrong type cast error when attempting a script that displays Bollinger Bands as a label. The error comes at the very end:

ADDLABEL(yes, "UpperBand " + " " OR "LowerBand " + " " OR " ", IF close > UpperBand THEN "UpperBand " + " " AND COLOR.WHITE
ELSE IF close < LowerBand
THEN "LowerBand " + " " AND COLOR.RED
ELSE " " AND CREATECOLOR (255, 255, 51));
 
I'm running into a similar issue with the wrong type cast error when attempting a script that displays Bollinger Bands as a label. The error comes at the very end:

ADDLABEL(yes, "UpperBand " + " " OR "LowerBand " + " " OR " ", IF close > UpperBand THEN "UpperBand " + " " AND COLOR.WHITE
ELSE IF close < LowerBand
THEN "LowerBand " + " " AND COLOR.RED
ELSE " " AND CREATECOLOR (255, 255, 51));

https://usethinkscript.com/threads/...st-label-scan-for-thinkorswim.762/#post-11745
 
Last edited:

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