BullCharts Forum Homepage
Forum Home Forum Home > BullCharts > BullScript
  New Posts New Posts RSS Feed: How extreme is a Bollinger Band squeeze?
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

How extreme is a Bollinger Band squeeze?

 Post Reply Post Reply
Author
Message / View First Unread Post
cudderbean View Drop Down
Regular
Regular
Avatar

Joined: 02 Oct 2006
Location: Thailand
Posts: 40
Post Options Post Options   Quote cudderbean Quote  Post ReplyReply Direct Link To This Post Topic: How extreme is a Bollinger Band squeeze?
    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.
Back to Top
maximo View Drop Down
BullCharts Guru
BullCharts Guru
Avatar

Joined: 02 Sep 2006
Location: Australia
Posts: 232
Post Options Post Options   Quote maximo Quote  Post ReplyReply Direct Link To This Post 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;


Edited by maximo - 24 Jan 2018 at 4:25am
Back to Top
cudderbean View Drop Down
Regular
Regular
Avatar

Joined: 02 Oct 2006
Location: Thailand
Posts: 40
Post Options Post Options   Quote cudderbean Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
maximo View Drop Down
BullCharts Guru
BullCharts Guru
Avatar

Joined: 02 Sep 2006
Location: Australia
Posts: 232
Post Options Post Options   Quote maximo Quote  Post ReplyReply Direct Link To This Post Posted: 27 Jan 2018 at 4:46am
I'll see what I can do.


Edited by maximo - 28 Jan 2018 at 5:31pm
Back to Top
maximo View Drop Down
BullCharts Guru
BullCharts Guru
Avatar

Joined: 02 Sep 2006
Location: Australia
Posts: 232
Post Options Post Options   Quote maximo Quote  Post ReplyReply Direct Link To This Post 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;




Edited by maximo - 28 Jan 2018 at 5:35pm
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.69
Copyright ©2001-2010 Web Wiz