Straight Bollinger Bands Squeeze Scan


Category:
0
0

Pete, I want to create a scan for just a standard Bollinger Bands Squeeze.  Where I get stuck is that TOS lets me reference the BandWidth I can’t figure out how to see if today’s Bandwidth is the lowest range in past x number of days. In a perfect world I would be able to scan for past 20 days, past 6 months etc. This would allow me to pull up the choicest stocks for a volatility breakout. Thank you for all your work on this website. I am learning things from it daily and it has become such a resource for me. You’re a rockstar.

Marked as spam
Posted by (Questions: 2, Answers: 1)
Asked on October 14, 2018 2:45 pm
1952 views
0
Private answer

Thanks so much for your kind words and feedback about our resources. Very glad you have found some valuable tools and knowledge here. And thanks for adding to this vast storehouse of knowledge by posting your question here.

So I tried to build this through the Condition Wizard first. But this is just a tad bit to complex for that. So here is the full code. I just copied the original and added one line that runs the scan.

input averageType = AverageType.Simple;
input price = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_Up = 2.0;
def upperBand = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, averageType).UpperBand;
def lowerBand = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, averageType).LowerBand;
def midLine = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, averageType).MidLine;
def Bandwidth = (upperBand - lowerBand) / midLine * 100;
plot scan = Bandwidth < Lowest(Bandwidth[1], 10);

The number 10 in that last line is the number of bars back to search for a lower value of the Bandwidth plot. Inside the “Lowest()” statement we use an index of [1] so that we ignore the current value of the Bandwidth plot when doing the comparison.

I haven’t tested this. Let us know how it works!

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on October 14, 2018 4:32 pm
0

I think it’s working. I had tried the condition wizard too and got lost quickly. I did save a custom scan, but this code I pasted into “custom” and there was no option to name it. So It;s my Bollinger Band Squeeze scan but the study filter is entitled “custom.” I don’t know if this will cause me problems further out. I did create a study and modified your code to put it in the lower window and added a lookback range function. 10 is giving me wide bands but they are starting to narrow so it bears watching. This all helps a lot Pete. thank you. Awesome site and very very helpful.
declare lower;
input averageType = AverageType.Simple;
input price = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_Up = 2.0;
input lookbackrange = 50;
def upperBand = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, averageType).UpperBand;
def lowerBand = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, averageType).LowerBand;
def midLine = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, averageType).MidLine;
def Bandwidth = (upperBand – lowerBand) / midLine * 100;
plot scan = Bandwidth < Lowest(Bandwidth[1], lookbackrange);

( at October 14, 2018 7:43 pm)