• LIMITED TIME OFFER: use coupon code PRIMEDAY at checkout to save $50 off VIP membership (down to $149 / year). Valid through Tuesday 6/22.

ThinkorSwim Bollinger Bands Scanner


New member
Need help for scanning stocks for "Stocks which Touched their Lower Bollinger Band" - Can someone help with the steps or tos script.
Last edited:


Well-known member
The TOS Conditional Wizard gave this as automated code generation...
low crosses below BollingerBandsCrossover("band" = "lower", "crossing type" = "below")


Well-known member
@rad14733 No luck, I cant find any stocks which are touching lower band and or outsider lower band
During regular trading hours...??? I only tested it on GDX because I already had the chart up so I just added the script as a lower study... It fired off more than a few times before I finally removed the study... It was just your code with the two alert lines added... I never bothered to check the semantics of your code, just added the alerts based on your plot conditions...


New member
Hello everyone, First of all, thank you for your response and here is the help that I need:

Can some one help me with an indicator which tells me when "5 minute lower Bollinger Band" is touching "Daily lower Bollinger Band".


Active member
put it on a 5 minute time frame and it should work

# DG_MTFBollingerBands
# Paints Bollinger Bands from higher time period
# onto current time period
#German BUrrito
# Copyright (c) 2017 Daniel Granville
declare lower;
input timeframe = AggregationPeriod.DAY;
input period = 20;
input std = 2.0;
input moving_average_type = {default SMA, EMA};

def data = close(period = timeframe);
def band = StDev(data, period);

plot MidLine;

switch(moving_average_type) {
    case SMA:
        MidLine = Average(data, period);
    case EMA:
        MidLine = ExpAverage(data, period);

plot BBandTop = MidLine + band;

plot BBandBot = MidLine - band;

# TD Ameritrade IP Company, Inc. (c) 2007-2020

input price2 = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.Simple;

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

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


def U = LowerBand <=  BBandBot ;
def D = lowerband >=  BBandBot;

AddLabel( U, " down " , Color.red);
AddLabel( D, " up " , Color.green);


New member
Thank you so much Germanburrito and it is really helpful.
However, my expectation was to have it as a scan and I am getting error while trying to paste this code (by removing addlabel kind of statements in scan. Could you be able to help me here please?
All I need is - at this moment, I would like to know the tickers where the price is below 5 mins Lower Bollinger band and daily Bollinger Band levels.
I am getting error as "Secondary period not allowed" while giving this in scan.
Many thanks in advance!



New member
Thanks for the quick response but it seems I am still getting the same error. Scan is working good when Day is selected (but obviously resulting no rows - which is expected), but when changing it to 5 minutes, I am getting the error as "Secondary period not allowed: Day" because of Day is being considered within the script.

Can you please help me?


New member
Hello Everyone,

I would like to have a scanner that Scans for stocks that fall in the “buy zone,” between one and two standard deviations above the moving average.

can someone help please.

Thank you in advanced.


Well-known member
Is there a way to scan, if a bollinger band is trending upward, (eg midline, midline[2], midline[4] and midline[6] are all trending up) appreciate it.

The Bollinger Band midline is merely a SMA20 so that's all you'd need to find the same trend as the Bollinger Band midline... No need further complicating things by attempting to use Bollinger Bands... 💡


New member
Is there a code, or how do I set up a scanner on ToS that will allow me to pick up first candle back inside of the lower band. Also, is there a way to find when the bands first expand/widen after a squeeze


New member
Guys, would like to seek for advise for below condition Scanner, is it able to scan some BB width? as below condition?
set bb to 40
bb width need to be below 10.... for past "150 (this can be variable)" candle
trigger: price close above bb (normal bb 20)/ macd cross


JE $$

There's a book from LConnors called BollingerBand strategies that work
They outline a strategy as follows:
1. The stock must be above $5 per share.
2. The stock’s average daily volume over the past 21 days (one trading month) must be
at least 250,000 shares per day. This assures we’re in liquid stocks.
3. The stock’s 100‐day historical volatility is above 30. (See the Appendix for a
definition of historical volatility).
4. The stock’s 10 day Average Directional Index (ADX) is above 30. (See the Appendix for
a definition of ADX).
5. The stock closes above its 200‐day moving average.
6. The %b of the stock must be under X (X=0.1, 0, ‐0.1) Y days in a row (Y = 2, 3, 4). A
close under 0 has the stock closing under its lower band.
7. If the above rules are met, buy the stock tomorrow on a further intraday limit Z%
below today’s closing price (Z= 4%, 6%, 8%, or 10%).
8. Exit the position when its %b closes above 1.0 (its upper band), exiting at the closing

I'm trying to modify this to a scan that finds:
1)1 million shares volume
2) BB %b less than or equal to -0.1 for 4 days
3)close > 200 SMA
4)historical vol >30.

My problem is that I cant figure out how to get the BB %b part for 4 days.
I can easily get it for within 1 day, but how do you tell it to satisfy this condition for 4days in a row? (ie the last 4 days)

can anyone help?
attached is the scan i have so far



New member
close from 1 bars ago is greater than or equal to BollingerBands()."UpperBand" from 1 bars ago or close from 1 bars ago is less than or equal to BollingerBands()."LowerBand"[1]

Similar threads