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 " ,;
AddLabel( D, " up " ,;


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


Similar threads