Question regarding BB SqueezeBreaks Indicator

Splinter

Member
VIP
Hi all,
quick question regarding the BB Squeeze Breaks indicator.

Regarding the line with the colors (that indicate trend/buying selling), what is making that line go up or down. I'm not sure if its trend strength or what.
The code is posted below I was hoping someone might be able to shed some light on this
Thanks for your help!
Ruby:
## BB_SqueezeBreaks_0_3
## linus, 2014-11-21, v0.3

declare lower;

input SqueezePeriod = 90;     #hint SqueezePeriod: Lookback period to find lowest squeeze over that period.
input SqueezeMult = 1.5;      #hint SqueezeMult: Adjust the SqueezeLow trigger line by this multiple. (Higher values raise line, lower values lower line.)
input VLineWarn = 4;     #hint VLineWarn: Vertical line style for when inner bands are squeezed more than the lowest outer band squeeze over the period length.  (1..4 are valid styles, or 0 hides the line.)
input VLineTrigger = 1;  #hint VLineTrigger: Vertical line style for when price crosses the outer Upper or Lower band to trigger a long or short signal. (1..4 are valid styles, or 0 hides the line.)
def sDev = StDev(close, 20);
def atr = Average(TrueRange(high,  close,  low),  20);
def MM = ExpAverage(close, 8);
def MB = Average(close, 20);
def UChan = MB + (atr * 1.5);
def UB2 = MB + 2 * sDev;  # Upper Outer Band
def LB2 = MB - 2 * sDev;  # Lower Outer Band
def UB1 = MB + sDev;  # Upper Inner Band
def LB1 = MB - sDev;  # Upper Inner Band
def SqueezeRatio2 = (UB2 - LB2) / MB;
def SqueezeRatio1 = (UB1 - LB1) / MB;
def rawSqueezeLow = Lowest(SqueezeRatio2[1], SqueezePeriod);
plot SqueezeRatio = (SqueezeRatio1 + SqueezeRatio2) / 2;
SqueezeRatio.SetDefaultColor(Color.YELLOW);
SqueezeRatio.SetLineWeight(2);
SqueezeRatio.AssignValueColor(if close > MM then if close > MB then Color.GREEN else Color.BLUE else if close < MM then if close < MB then Color.RED else Color.MAGENTA else Color.GRAY);
input startBar = 1;
def show = barNumber() >= startBar;
def inKcSqueeze = UChan > UB2;
def multSqueezeLow = rawSqueezeLow * SqueezeMult;

# SqueezeState is 1 when the inner band squeeze becomes less than the lowest outer band squeeze over the period.  SqueezeState is 2 when the outer band squeeze  becomes less than the lowest outer band squeeze over the period. SqueezeState is reset to Zero when both the inner band and outer band squeezes are greater than the lowest outer band squeeze over the period.
def SqueezeState = compoundValue(1, if SqueezeRatio1 crosses below rawSqueezeLow then 1 else if SqueezeRatio2 crosses below multSqueezeLow then 2 else if SqueezeRatio1 > rawSqueezeLow and SqueezeRatio2 > multSqueezeLow then 0 else SqueezeState[1], 0);
def squeezeSignal = if IsNaN(close) then squeezeSignal[1] else if inKcSqueeze and SqueezeState == 2 then 3 else if inKcSqueeze then 1 else if SqueezeState == 2 then 2 else 0;
plot SqueezeLow = multSqueezeLow; #if squeezeSignal != 0 then multSqueezeLow else Double.NaN;
SqueezeLow.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
SqueezeLow.SetLineWeight(1);
SqueezeLow.HideBubble();
SqueezeLow.SetDefaultColor(Color.GRAY);
SqueezeLow.AssignValueColor(if squeezeSignal == 3 then Color.DARK_ORANGE else if squeezeSignal == 1 then Color.ORANGE else if squeezeSignal == 2 then Color.YELLOW else Color.DARK_GRAY);
AddLabel(1, if squeezeSignal == 3 then "In Ratio and KC squeezes." else if squeezeSignal == 2 then "In Ratio squeeze." else if squeezeSignal == 1 then "In KC squeeze." else "Not in squeeze.", SqueezeLow.TakeValueColor());
AddVerticalLine(show and VLineWarn and SqueezeState != SqueezeState[1] and SqueezeState == 1, "", Color.GRAY, VLineWarn);
def highSqueeze = if SqueezeState == 2 then 2 else if inKcSqueeze then 1 else 0;

# If outer bands are squeezed (SqueezeState == 2), and outer bands are both moving away from each other, then check if price is crossing an outer band:
# -  Trigger is 1 (LONG) if price crosses above the upper band
# -  Trigger is -1 (SHORT) if price crosses below the lower band
# -  Trigger is 0 otherwise (No trigger occurred, or not in squeeze.)
def Trigger = if (SqueezeState == 2 or inKcSqueeze) and UB2 > UB2[1] and LB2 < LB2[1] then if close crosses below LB2 then -1 else if close crosses above UB2 then 1 else 0 else 0;
AddVerticalLine(show and VLineTrigger and Trigger > 0, "", Color.GREEN, VLineTrigger);
AddVerticalLine(show and VLineTrigger and Trigger < 0, "", Color.RED, VLineTrigger);
## END STUDY

xlMN9xe.jpg
 
Last edited by a moderator:
Regarding the line with the colors (that indicate trend/buying selling), what is making that line go up or down.
That line indicates how far apart the Bollinger Bands are. Up is farther apart.

At first glance, that study seems to work pretty well. However, the vertical lines are a little misleading. Once the condition is met the vertical line appears BEFORE the candle that creates the trigger condition. If arrows were used instead, the arrow would always be on the candle following the line, not the candle before the line. The script still seems to work well. Just not quite as well as it first appears.

For instance, append this to the script to get arrows:
Ruby:
plot Long = if Trigger == 1 then SqueezeRatio else Double.NaN;
Long.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Long.SetDefaultColor(Color.WHITE);
Long.SetLineWeight(3);

plot Short = if Trigger == -1 then SqueezeRatio else Double.NaN;
Short.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Short.SetDefaultColor(Color.WHITE);
Short.SetLineWeight(3);
 
Last edited:
That line indicates how far apart the Bollinger Bands are. Up is farther apart.

At first glance, that study seems to work pretty well. However, the vertical lines are a little misleading. Once the condition is met the vertical line appears BEFORE the candle that creates the trigger condition. If arrows were used instead, the arrow would always be on the candle following the line, not the candle before the line. The script still seems to work well. Just not quite as well as it first appears.

For instance, append this to the script to get arrows:
Ruby:
plot Long = if Trigger == 1 then SqueezeRatio else Double.NaN;
Long.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Long.SetDefaultColor(Color.WHITE);
Long.SetLineWeight(3);

plot Short = if Trigger == -1 then SqueezeRatio else Double.NaN;
Short.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Short.SetDefaultColor(Color.WHITE);
Short.SetLineWeight(3);
Thank very much for responding!
So in essence as the line moves up the bands are widening which is denoting more volatility and while the line is decreasing the price action is heading towards consolidation?

thank you for the appended code, greatly appreciated!
 
This Indicator Compared To John Carter TTM Squeeze
Both Indicators look for consolidation. They use different formula to get there.
a2.png
 
Last edited:
This Indicator Compared To John Carter TTM Squeeze
Both Indicators look for consolidation. They use different formula to get there.
Those two indicators on the bottom. Is one an inverse? Is that an alternative to the regular squeeze?
 
Last edited by a moderator:
@Rob B Not an inverse at all. The TTM Squeeze is an Oscillator. This Linus Squeeze displays volatility. I guess it is best when plotted as a line:
As the line moves up the bands are widening which is denoting more volatility and while the line is decreasing the price action is heading towards consolidation
Both have middle dashboards that display squeezed and not squeezed.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
623 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top