Print Page | Close Window

How extreme is a Bollinger Band squeeze?

Printed From: BullCharts Forum
Category: BullCharts
Forum Name: BullScript
Forum Discription: Technical discussion related specifically to the BullScript programming language.
URL: http://www.bullcharts.com.au/forum/forum_posts.asp?TID=1016
Printed Date: 03 May 2024 at 4:09pm
Software Version: Web Wiz Forums 9.69 - http://www.webwizforums.com


Topic: How extreme is a Bollinger Band squeeze?
Posted By: cudderbean
Subject: How extreme is a Bollinger Band squeeze?
Date Posted: 21 Jan 2018 at 4:54pm
I want to show a list of codes that I can sort by the number of bars since the Bollinger Bandwidth was tighter/smaller than it is today. 
The most extreme ones I will then put on a watch list to monitor for breakouts.

If someone would kindly help me with this little bit of coding, I will add a Bollinger Squeeze scan to the forum.

Upper:= bbandtop(c,20,s,2);
Middle:=ma(c,20,s);
Lower:=bbandbot(c,20,s,2);
BandWidth:= (upper-lower)/middle;

bbwextreme := barssince({how many bars ago was the Bollinger Bandwidth was less than/tighter than what it is today});

This {....}is the part I cannot code 

Thank you for your help.



Replies:
Posted By: maximo
Date Posted: 23 Jan 2018 at 10:08pm
I found that substituting 'middle' with 'lower' indicates bandwidth contraction better, since the middle-line does not contract. So you could base the scan on that custom indicator. A scan for X number of days with the percentage getting lower=contracting, and say 6% or less between the bands can also be found. Verify the following indicator against the bollinger bands on a chart to get a baseline on the values required.


expr := expression("Expression");
method := inputma("Method",SIMPLE);
n := input("Time periods",30,1);
sd1 := input("Standard Deviations",2,1);
top:= bbandtop(expr,n,method,sd1);
bot:= bbandbot(expr,n,method,sd1);
((top - bot) / bot) * 100;


Posted By: cudderbean
Date Posted: 26 Jan 2018 at 3:45pm
Thank you kindly for your help, Maximo. I have actually used Bollinger's standard 20,2 settings only because it may come as default on other users' charts, but taken on board your modified Bandwidth formula. As members may or may not know, you can only have fixed parameters in a Scan itself, unlike indicators.

That works fine and gives me a list I can sort by tightest bandwidth.

{Variables}
top := bbandtop(c,20,s,2); {20 SMA, 2*standard deviations}
bot := bbandbot(c,20,s,2); {20 SMA, 2*standard deviations}
bbwidth :=((top - bot) / bot) * 100; {modified Bandwidth formula}

{Condition}
filter := (bbwidth <= 6); {Bandwidth tightened to <=6%}
filter;

{Columns}
[name="BB Bandwidth"; dp="2"] bbwidth;

Additional Bandwidth filter

But, I am still having difficulty with coding an additional different filter that has baffled me:
    When (how many bars ago?) was the last time that the Bollinger Bandwidth was even narrower than it is today. 

I even tried to convert today's bandwidth into an absolute fixed value, but it won't recognise it.

bbwtoday := abs(bbwidth*1);
prevsqueeze := barssince(bbwidth<bbwtoday);

{Variables}

top     := bbandtop(c,20,s,2); {20 SMA, 2*standard deviations}
bot     := bbandbot(c,20,s,2); {20 SMA, 2*standard deviations}
bbwidth :=((top - bot) / bot) * 100; {modified Bandwidth formula}
bbwtoday := abs(bbwidth*1);
prevsqueeze := barssince(bbwidth<bbwtoday); {How many bars ago was the Bandwidth even narrower than it is today?}

{Condition}
filter := (bbwidth <= 6); {Bandwidth tightened to <=6%}
filter;

{Columns}
[name="BB Bandwidth"; dp="2"] bbwidth;
[name="Narrowest since"; dp="0"] prevsqueeze;

Thank you for your help.


Posted By: maximo
Date Posted: 27 Jan 2018 at 4:46am
I'll see what I can do.


Posted By: maximo
Date Posted: 28 Jan 2018 at 5:29pm
I updated the bandwidth indicator with visible numbers to show the output of Barssince(). That may be of help.
Currently it shows a count of the number of barssince the bands were contracting.


expr := expression("Expression");
method := inputma("Method",SIMPLE);
n := input("Time periods",20,1);
sd1 := input("Standard Deviations",2,1);
top:= bbandtop(expr,n,method,sd1);
bot:= bbandbot(expr,n,method,sd1);
bw:=((top - bot) / bot) * 100;
bw;

Counter:=if(bw>=hist(bw,1),0,barssince(bw>=hist(bw,1)));
[color=Black]
[linestyle=Text; textalign=Below,Center]
If(Counter>0, Right(Counter,2) , undefined);
Low;





Print Page | Close Window

Bulletin Board Software by Web Wiz Forums® version 9.69 - http://www.webwizforums.com
Copyright ©2001-2010 Web Wiz - http://www.webwiz.co.uk