Splinter
Member
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!
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
Last edited by a moderator: