Bollinger Bands Format, Watchlist, Label, Scan For ThinkOrSwim

Hi, I need a script to scan the stocks and, draw an arrow every time when the high and low of the candlestick crosses the upper and lower bands or when the candle closes above and below the upper and lower bands at the same time. I have attached a screenshot to show the idea.
@samalley970 I moved your post to this thread because there are several examples of bollinger band crosses herein.
While not exactly what you are asking for, slight modification of the syntax should get you there.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Hello everyone, I am looking for the Bollinger Band oscillator. If at all anyone can help with this , it would be awesome.

Thanks in advance

This is the end result.
xYBGqWU.jpg

https://media.discordapp.net/attach...86470371378/s-l1600.jpg?width=1039&height=630
 
Last edited by a moderator:
Hello everyone, I am looking for the Bollinger Band oscillator. If at all anyone can help with this , it would be awesome.

Thanks in advance

This is the end result.
xYBGqWU.jpg

https://media.discordapp.net/attach...86470371378/s-l1600.jpg?width=1039&height=630
is not a bollinger of price, it it bollinger of the rsi? what is the bollinnger calculating, because the bollinger rsi is called tdi traders dynamic index i believe.
https://usethinkscript.com/threads/traders-dynamic-index-tdi-indicator-for-thinkorswim.651/
 
Last edited by a moderator:
The Issue With Scan Requests:
The greatest difficulty is that scans requires a precise mathematical-based logic.
As you have not defined your logic for "tight channel", no one would be able to help you create a custom scan.

However, scanning for squeezes is a popular topic on the forum. Here are some threads that have an abundant number of examples.
Plug&Play and see what works for you.
https://usethinkscript.com/threads/john-carters-squeeze-pro-question.8705/#post-80562
Yes true. Thanks for the link! For example, a scan on 15min aggregation for stocks where the Upper Band Bollinger is less than 20% away from it's Lower Band?
 
Yes true. Thanks for the link! For example, a scan on 15min aggregation for stocks where the Upper Band Bollinger is less than 20% away from it's Lower Band?
I don't see anyone on the forum that approaches "Tight Channels" in the manner that you describe.
These approaches might yield better results:
https://usethinkscript.com/threads/rate-of-change-in-bollinger-bands-thickness.6303/
https://usethinkscript.com/threads/bollingerbandwidth-for-thinkorswim.6910/

If you are set on using percentages. Here is a thread that is dedicated to finding the percentage difference between any two plots.
To use one of the many examples just change the definition of the plots to your name for your bollinger bands:
https://usethinkscript.com/threads/percent-distance-between-emas-or-any-2-plots.1345/
 
Last edited:
It is not possible to hazard a guess an image :(
you right MerryDay, I will put here what I'm doing and see if somebody help me to resolve this idea.

Code:
def prange = high - low;
def phigh = high + prange * .2;
def plow = low - prange * .2;

def AvgExp = ExpAverage(price[-displace], length);
def UpSignal = price crosses above AvgExp;
def DnSignal = price crosses below AvgExp;

AssignPriceColor(if UpSignal or DnSignal then CreateColor(0,130,211) else Color.CURRENT);

def SignUp = if close[1] crosses below AvgExp and close crosses above AvgExp then 1 else 0;
def SignDn = if close[1] crosses above AvgExp and close crosses below AvgExp then 1 else 0;

plot SignUpDt = if SignUp then plow else Double.NaN;
plot SignDnDt = if SignDn then phigh else Double.NaN;

SignUpDt.SetDefaultColor(Color.YELLOW);
SignUpDt.SetStyle(Curve.POINTS);
SignUpDt.SetLineWeight(3);

SignDnDt.SetDefaultColor(Color.YELLOW);
SignDnDt.SetStyle(Curve.POINTS);
SignDnDt.SetLineWeight(3);

zfsbjnI.png


in sample 1 and 2 the code work fine BUT in 3 and 4 don't, my idea is to show me the point every time the price cross as sample over but when cross over multiple times just show me in the las bar as sample 1 and 2
 
you right MerryDay, I will put here what I'm doing and see if somebody help me to resolve this idea.

Code:
def prange = high - low;
def phigh = high + prange * .2;
def plow = low - prange * .2;

def AvgExp = ExpAverage(price[-displace], length);
def UpSignal = price crosses above AvgExp;
def DnSignal = price crosses below AvgExp;

AssignPriceColor(if UpSignal or DnSignal then CreateColor(0,130,211) else Color.CURRENT);

def SignUp = if close[1] crosses below AvgExp and close crosses above AvgExp then 1 else 0;
def SignDn = if close[1] crosses above AvgExp and close crosses below AvgExp then 1 else 0;

plot SignUpDt = if SignUp then plow else Double.NaN;
plot SignDnDt = if SignDn then phigh else Double.NaN;

SignUpDt.SetDefaultColor(Color.YELLOW);
SignUpDt.SetStyle(Curve.POINTS);
SignUpDt.SetLineWeight(3);

SignDnDt.SetDefaultColor(Color.YELLOW);
SignDnDt.SetStyle(Curve.POINTS);
SignDnDt.SetLineWeight(3);

zfsbjnI.png


in sample 1 and 2 the code work fine BUT in 3 and 4 don't, my idea is to show me the point every time the price cross as sample over but when cross over multiple times just show me in the las bar as sample 1 and 2

This has an addition of SignUpDn to count consecutive SignUp or SignDn candles. Then it will plot a dot when the last candle with a SignUp or SignDn is followed by SignUpDn[-1] == 0 candle. The debug was left to yes so you can see consecutive candles with a 1 underneath the candles to confirm that a dot will plot only on the last candle with a 1 followed by a candle with 0. Once you are satisfied, set debug to no.

Capture.jpg
Ruby:
def prange = high - low;
def phigh  = high + prange * .2;
def plow   = low - prange * .2;

input price    = close;
input length   = 9;
input displace = 0;

plot AvgExp   = ExpAverage(price[-displace], length);
def UpSignal  = price crosses above AvgExp;
def DnSignal  = price crosses below AvgExp;

AssignPriceColor(if UpSignal or DnSignal then CreateColor(0, 130, 211) else Color.CURRENT);

def SignUp   = if close[1] crosses below AvgExp and close crosses above AvgExp then 1 else 0;
def SignDn   = if close[1] crosses above AvgExp and close crosses below AvgExp then 1 else 0;


#Determine consecutive SignUp or SignDn candles-------------------------------------------
def signupdn = if signup or signdn then 1 else if signupdn[1]==1 and signup or signdn then 1 else 0;

input debug  = yes;
plot x       = if !debug then double.nan else signupdn;
x.setpaintingStrategy(paintingStrategy.VALUES_BELOW);

#------------------------------------------------------------------------------------------

plot SignUpDt = if signup and signupdn[-1]==0 then plow else Double.NaN;
plot SignDnDt = if SignDn and signupdn[-1]==0 then phigh else Double.NaN;

SignUpDt.SetDefaultColor(Color.YELLOW);
SignUpDt.SetStyle(Curve.POINTS);
SignUpDt.SetLineWeight(3);

SignDnDt.SetDefaultColor(Color.YELLOW);
SignDnDt.SetStyle(Curve.POINTS);
SignDnDt.SetLineWeight(3);
 
This has an addition of SignUpDn to count consecutive SignUp or SignDn candles. Then it will plot a dot when the last candle with a SignUp or SignDn is followed by SignUpDn[-1] == 0 candle. The debug was left to yes so you can see consecutive candles with a 1 underneath the candles to confirm that a dot will plot only on the last candle with a 1 followed by a candle with 0. Once you are satisfied, set debug to no.
Again thanks SleepyZ, do you think that you can include the signal when is only 1 candle too?
 
It does. You can check it with the debug.
you right it does but look at this pictures here I don't know why on these cases not? any idea? could be because the candle before doesn't meet the criteria from the code?

qri099w.png



is there a way to manipulate the showbreakoutSignals to show the points too when is only 1 candle crossing the AvgExp?
 
you right it does but look at this pictures here I don't know why on these cases not? any idea? could be because the candle before doesn't meet the criteria from the code?

qri099w.png



is there a way to manipulate the showbreakoutSignals to show the points too when is only 1 candle crossing the AvgExp?

you right it does but look at this pictures here I don't know why on these cases not? any idea? could be because the candle before doesn't meet the criteria from the code?

qri099w.png



is there a way to manipulate the showbreakoutSignals to show the points too when is only 1 candle crossing the AvgExp?
Those UpSignal and DownSignal and are not part of the coding you used, SignUp and SignDn, for the dots.
 
Those UpSignal and DownSignal and are not part of the coding you used, SignUp and SignDn, for the dots.
I think that I figure out, you where right to many signal up and downs, now play the way I need it. you help me to see more clear! here is the code

Code:
input price = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.EXPONENTIAL;

def sDev = stdev(data = price[-displace], length = length);

plot MidLine = MovingAverage(averageType, data = price[-displace], length = length);
plot LowerBand = MidLine + num_Dev_Dn * sDev;
plot UpperBand = MidLine + num_Dev_Up * sDev;

MidLine.SetPaintingStrategy(PaintingStrategy.LINE);
MidLine.SetStyle(curve.SHORT_DASH);
MidLine.SetDefaultColor(Color.GRAY);
UpperBand.SetPaintingStrategy(PaintingStrategy.LINE);
UpperBand.SetStyle(curve.LONG_DASH);
UpperBand.SetDefaultColor(Color.DARK_RED);
LowerBand.SetPaintingStrategy(PaintingStrategy.LINE);
LowerBand.SetStyle(curve.LONG_DASH);
LowerBand.SetDefaultColor(Color.DARK_GREEN);

def AvgExp = ExpAverage(price[-displace], length);

def UpSignal = if close[1] crosses below AvgExp and close crosses above AvgExp or close crosses above AvgExp then 1 else 0;
def DnSignal = if close[1] crosses above AvgExp and close crosses below AvgExp or close crosses below AvgExp then 1 else 0;

AssignPriceColor(if UpSignal or DnSignal then CreateColor(0,130,211) else Color.CURRENT);

def prange = high - low;
def phigh = high + prange * .2;
def plow = low - prange * .2;

def SignUpDn = if UpSignal or DnSignal then 1 else if SignUpDn[1] == 1 and UpSignal or DnSignal then 1 else 0;

#input debug = yes;
#plot x = if !debug then Double.NAN else SignUpDn;

plot SignUpDt = if UpSignal and signUpDn[-1] == 0 then plow else Double.NaN;
plot SignDnDt = if DnSignal and signUpDn[-1] == 0 then phigh else Double.NaN;

SignUpDt.SetDefaultColor(Color.YELLOW);
SignUpDt.SetStyle(Curve.POINTS);
SignUpDt.SetLineWeight(3);

SignDnDt.SetDefaultColor(Color.YELLOW);
SignDnDt.SetStyle(Curve.POINTS);
SignDnDt.SetLineWeight(3);

should I keep the debug or you just put it for testing?
 
I think that I figure out, you where right to many signal up and downs, now play the way I need it. you help me to see more clear! here is the code

Code:
input price = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.EXPONENTIAL;

def sDev = stdev(data = price[-displace], length = length);

plot MidLine = MovingAverage(averageType, data = price[-displace], length = length);
plot LowerBand = MidLine + num_Dev_Dn * sDev;
plot UpperBand = MidLine + num_Dev_Up * sDev;

MidLine.SetPaintingStrategy(PaintingStrategy.LINE);
MidLine.SetStyle(curve.SHORT_DASH);
MidLine.SetDefaultColor(Color.GRAY);
UpperBand.SetPaintingStrategy(PaintingStrategy.LINE);
UpperBand.SetStyle(curve.LONG_DASH);
UpperBand.SetDefaultColor(Color.DARK_RED);
LowerBand.SetPaintingStrategy(PaintingStrategy.LINE);
LowerBand.SetStyle(curve.LONG_DASH);
LowerBand.SetDefaultColor(Color.DARK_GREEN);

def AvgExp = ExpAverage(price[-displace], length);

def UpSignal = if close[1] crosses below AvgExp and close crosses above AvgExp or close crosses above AvgExp then 1 else 0;
def DnSignal = if close[1] crosses above AvgExp and close crosses below AvgExp or close crosses below AvgExp then 1 else 0;

AssignPriceColor(if UpSignal or DnSignal then CreateColor(0,130,211) else Color.CURRENT);

def prange = high - low;
def phigh = high + prange * .2;
def plow = low - prange * .2;

def SignUpDn = if UpSignal or DnSignal then 1 else if SignUpDn[1] == 1 and UpSignal or DnSignal then 1 else 0;

#input debug = yes;
#plot x = if !debug then Double.NAN else SignUpDn;

plot SignUpDt = if UpSignal and signUpDn[-1] == 0 then plow else Double.NaN;
plot SignDnDt = if DnSignal and signUpDn[-1] == 0 then phigh else Double.NaN;

SignUpDt.SetDefaultColor(Color.YELLOW);
SignUpDt.SetStyle(Curve.POINTS);
SignUpDt.SetLineWeight(3);

SignDnDt.SetDefaultColor(Color.YELLOW);
SignDnDt.SetStyle(Curve.POINTS);
SignDnDt.SetLineWeight(3);

should I keep the debug or you just put it for testing?
No, it was just to help you and me. It is one of the ways I use to test any code I do to make sure it is doing what I expect. The Addlabel() function is another debugging tool.
 
No, it was just to help you and me. It is one of the ways I use to test any code I do to make sure it is doing what I expect. The Addlabel() function is another debugging tool.
what this mean signUpDn[-1], I learn that counting 1 day back I can use this signUpDn[1] but with the minus what I count?
its any place that I can learn more about thinkscrip beside here?
 
It Is the future 0 bar after the last 1. That is one easy way to identify the last 1 in a group of 1’s. Go to the education tab to learn more, but you can learn more here in my opinion from the examples and explanations.
 
It Is the future 0 bar after the last 1. That is one easy way to identify the last 1 in a group of 1’s. Go to the education tab to learn more, but you can learn more here in my opinion from the examples and explanations.
yes this site is my first option for research
 
Hi
Is there a way to fill-in(ie shade) the BollingerBands, between the lower and upper standard deviation lines, with a color of choosing ?
Right now, TOS allows you only to plot them as lines ,which adds to the crowd of all other moving averages/levels/channels , making it difficult to quickly distinguish.
Other platforms like TradingView,DasTrader etc do support such visually appealing BBands.

Contacting TOS support did not help, but created an enhancement request to allow that in a future release.

Can someone help do this in a thinkscript?

Thanks
 
Hi
Is there a way to fill-in(ie shade) the BollingerBands, between the lower and upper standard deviation lines, with a color of choosing ?
Right now, TOS allows you only to plot them as lines ,which adds to the crowd of all other moving averages/levels/channels , making it difficult to quickly distinguish.
Other platforms like TradingView,DasTrader etc do support such visually appealing BBands.

Contacting TOS support did not help, but created an enhancement request to allow that in a future release.

Can someone help do this in a thinkscript?

Thanks
Moved your post here. You will find many interesting /fascinating ways to create the Bollinger band clouds.
Here is a simple one to start you off:
https://usethinkscript.com/threads/...el-scan-for-thinkorswim.762/page-4#post-67959
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
580 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