Bolling for Soup (by nummy)

By -

So, for at least the past 4 weeks, SPX has maintained itself in a 35 point range.  What this has done to band systems like the Bollinger Bands (red) and Keltner Channels (yellow) has set us up for a fairly rare occurrence.  Firstly, the Bollinger Bands width (upper band – lower band) has dropped below 30 SPX points.  This hasn't happened for several months.  Secondly, the Bollinger bands have turned fairly flat.  Lastly, the Bollinger Bands (BB) have worked their way inside the Keltner Channels (KC).


A good question is, how can one quantify this to look for a similar situation that has occurred in the past?  Ideally, we would like to see where this has happened in the past, and look at the result for clues as to what could happen in the present.  We could do this visually, but it would take a lot time staring at charts.  I will briefly go through how to develop a simple thinkscript indicator to indicate when this situation is occurring.

Firstly, it is fairly easy to check the BB band width.  You just subtract the LowerBand value from the UpperBand to get your width.

Secondly, to describe the flatness of a line, we want to use a derivative, or difference.  If we take the current upper band value and subtract the upper band value of the previous candle, we get the slope of that line.  In the chart above, what is in the lower portion of the chart are the derivatives of each band (upper BB', lower BB', upper KC', lower KC').  We want to find a time in the past where the derivatives are close to 0, implying BB/KC flatness.  We don't really care whether the slope is negative or positive because, since they are so close to 0, they imply flatness.  In order to disregard the sign of the derivative, we can use the AbsValue() function and compare it to a threshold to determine flatness.  Here is some pseudo-code for what we would be looking for:

AbsValue(UpperBBSlope) < threshold and AbsValue(LowerBBSlope) < threshold and 
AbsValue(UpperKCSlope) < threshold and AbsValue(LowerKCSlope) < threshold

If we look at our current BB/KC slope values, we want to check that the AbsValue of the current slopes of upper/lower BB/KC lines are less than a threshold, say, 2.5.  Then, we also want to check that we have been flat for some time.  To do this, we can verify that the slopes of BB/KC lines of the last three periods are less than another threshold, say, 1.  Please note that these thresholds are only applicable to the scale of SPX.  In SPX, the BB width is about 30 SPX points while in SPY, the BB width would be about 3 SPY points.  These thresholds must be adjusted in the code if you intend to use this with another ticker symbol.  If you were going from SPX to SPY, you could multiply the threshold and BB width by approximately 1/10 (since SPY is approximately 1/10 of SPX).  All this checking of band slopes is doing is making sure we are near 0 for the past 4 candles.

Finally, we want to check that the BB is inside the KC.  This is also fairly simple, we can check that UpperKC > UpperBB and LowerKC < LowerBB.

Now we have all of our conditions to give us a signal:

1- BB width is less than or equal to 30 points
2- AbsValue(UpperBBSlope) < 2.5 and AbsValue(LowerBBSlope) < 2.5
3- AbsValue(UpperKCSlope) < 2.5 and AbsValue(LowerKCSlope) < 2.5
4- AbsValue(UpperBBSlope[1]) < 1 and AbsValue(LowerBBSlope[1]) < 1
5- AbsValue(UpperKCSlope[1]) < 1 and AbsValue(LowerKCSlope[1]) < 1
6- AbsValue(UpperBBSlope[2]) < 1 and AbsValue(LowerBBSlope[2]) < 1
7- AbsValue(UpperKCSlope[2]) < 1 and AbsValue(LowerKCSlope[2]) < 1
8- AbsValue(UpperBBSlope[3]) < 1 and AbsValue(LowerBBSlope[3]) < 1
9- AbsValue(UpperKCSlope[3]) < 1 and AbsValue(LowerKCSlope[3]) < 1
10- UpperKC > UpperBB and LowerKC < LowerBB

Note that UpperBBSlope means the current slope of the upper BB while UpperBBSlope[1] means 1 period ago (and [2] for 2 periods ago, [3] for 3 periods ago, etc.).  We can combine this into an if statement in thinkscript and check that all conditions are met.  Again, in pseudo-code:

if condition 1 and conditions 2-9 and condition 10 are all true, return 1, otherwise return 0.

So our signal should be 0 all the time unless our conditions are all true in which case it should spike to 1.  To create this script, I used the existing BollingerBandsSMA and KeltnerChannels scripts that come with TOS.  I combined both BB & KC into one script, so I could use data from each.


So above we have our signal.  Let's look in the past to find similar occurrences.  Look familiar?


So, keep in mind this happened before in December 2005.   The candle action looks almost identical to where we are today.  Three white candles up and above the mid-lines of BB and KC.  Back in December 2005, SPX re-tested the lows of the range it had been in for about a month (like now) and made slightly new lows.  Will history repeat itself?  Probably not, but it would be nice to see a selloff into OPEX week for once.  So take away what you will from this past occurrence and keep in mind there is always the chance of a fake-out on a BB squeeze.  The bulls seem ready to take charge again and break the range to the upside, but a lonely bear can dream of a downside squeeze, right?

If you'd like, you can download the script here Download NewStudy7STUDY.