Multi Symbol Squeeze

KG3344

New member
Hello,
I am trying to code a multi-symbol squeeze, but am having trouble figuring out how to call a variable from a script. I posted the code below. Please excuse the script's messiness, been copying from a couple of different scripts. The error is the last line of code where it is assigning a color to the squeeze line. I am going to keep trying to figure it out, but any tips would be greatly appreciated.

Code:
declare lower;
input bbprice = close;
input displace = 0;
def Length = 20.0;
input numdevdn = -2.0;
input numdevup = 2.0;
input averagetype = AverageType.SIMPLE;

def bb_midline = BollingerBands(bbprice, displace, Length, numdevdn, numdevup, averagetype).MidLine;
def bb_upperband = BollingerBands(bbprice, displace, Length, numdevdn, numdevup, averagetype).UpperBand;
def bb_lowerband = BollingerBands(bbprice, displace, Length, numdevdn, numdevup, averagetype).LowerBand;


# Use reference calls to TOS KC's and plot midline and bands

input kcdisplace = 0;
input kcfactor = 1.5;
input kclength = 20;
input kcprice = close;
input kcaverageType = AverageType.SIMPLE;
input kctrueRangeAverageType = AverageType.SIMPLE;

def kc_midline = KeltnerChannels(kcdisplace, kcfactor, kclength, kcprice, kcaverageType, kctrueRangeAverageType).Avg;
def kc_upperband = KeltnerChannels(kcdisplace, kcfactor, kclength, kcprice, kcaverageType, kctrueRangeAverageType).Upper_Band;
def kc_lowerband = KeltnerChannels(kcdisplace, kcfactor, kclength, kcprice, kcaverageType, kctrueRangeAverageType).Lower_Band;


# When the BB upper and lower bands cross inside the KC's we are in a Squeeze

input symbol10 = "XLY";
input symbol9 = "XLP";
input symbol8 = "XLE";
input symbol7 = "XLF";
input symbol6 = "XLV";
input symbol5 = "XLI";
input symbol4 = "XLB";
input symbol3 = "XLRE";
input symbol2 = "XLK";
input symbol1 = "XLU";


def nBB = 2.0;

def nK_High = 1.0;
def nK_Mid = 1.5;
def nK_Low = 2.0;
def price = close;

script SymbolSqueeze {
    input symbol = "";
    def nBB = 2.0;
    def Length = 20.0;
    def nK_High = 1.0;
    def nK_Mid = 1.5;
    def nK_Low = 2.0;
    def price = close(symbol);
    def bbprice = close(symbol);
    input displace = 0;

    input numdevdn = -2.0;
    input numdevup = 2.0;
    input averagetype = AverageType.SIMPLE;

    def bb_midline = BollingerBands(price, displace, Length, numdevdn, numdevup, averagetype).MidLine;
    def bb_upperband = BollingerBands(price, displace, Length, numdevdn, numdevup, averagetype).UpperBand;
    def bb_lowerband = BollingerBands(price, displace, Length, numdevdn, numdevup, averagetype).LowerBand;


# Use reference calls to TOS KC's and plot midline and bands

    input kcdisplace = 0;
    input kcfactor = 1.5;
    input kclength = 20;
    def kcprice = close(symbol);
    input kcaverageType = AverageType.SIMPLE;
    input kctrueRangeAverageType = AverageType.SIMPLE;

    def kc_midline = KeltnerChannels(kcdisplace, kcfactor, kclength, kcprice, kcaverageType, kctrueRangeAverageType).Avg;
    def kc_upperband = KeltnerChannels(kcdisplace, kcfactor, kclength, kcprice, kcaverageType, kctrueRangeAverageType).Upper_Band;
    def kc_lowerband = KeltnerChannels(kcdisplace, kcfactor, kclength, kcprice, kcaverageType, kctrueRangeAverageType).Lower_Band;


# When the BB upper and lower bands cross inside the KC's we are in a Squeeze

    def squeezed = if bb_upperband <= kc_upperband and bb_lowerband >= kc_lowerband then 1 else if bb_upperband >= kc_upperband and bb_lowerband <= kc_lowerband then -1 else 0;
    plot squeezed2 = If(IsNaN(price), Double.NaN, 0);

}

#plot squeeze = If(IsNaN(close), Double.NaN, 0);

#squeeze.DefineColor("NoSqueeze", Color.GREEN);
#squeeze.DefineColor("SqueezeLow", Color.black);
#squeeze.DefineColor("SqueezeMid", Color.RED);
#squeeze.DefineColor("SqueezeHigh", Color.orange);
#squeeze.AssignValueColor(if BolKelDelta_High <= 0 then squeeze.Color("SqueezeHigh") #else if BolKelDelta_Mid <= 0 then squeeze.Color("SqueezeMid") else if #BolKelDelta_Low <= 0 then squeeze.Color("SqueezeLow") else #squeeze.color("noSqueeze"));
#squeeze.SetPaintingStrategy(PaintingStrategy.POINTS);
#squeeze.SetLineWeight(3);
def s1 = SymbolSqueeze(symbol1);
def s2 = SymbolSqueeze(symbol2);
def s3 = SymbolSqueeze(symbol3);
def s4 = SymbolSqueeze(symbol4);
def s5 = SymbolSqueeze(symbol5);
def s6 = SymbolSqueeze(symbol6);
def s7 = SymbolSqueeze(symbol7);
def s8 = SymbolSqueeze(symbol8);
def s9 = SymbolSqueeze(symbol9);
def s10 = SymbolSqueeze(symbol10);

plot symb2 = if !IsNaN(close) and !IsNaN(close(symbol2)) then 2 else Double.NaN;
symb2.DefineColor("NoSqueeze", Color.GREEN);
symb2.DefineColor("SqueezeLow", Color.BLACK);
symb2.DefineColor("SqueezeMid", Color.RED);
symb2.DefineColor("SqueezeHigh", Color.ORANGE);

symb2.SetLineWeight(3);


symb2.AssignValueColor(if squeezed >= 0 then symb2.Color("SqueezeMid") else symb2.Color("noSqueeze"));
symb2.SetPaintingStrategy(PaintingStrategy.POINTS);
 
Solution
i started with kg3344 code from post #11 and made some changes.
the changes are listed in comments at the top of the study
the bubble colors change to match the last dot.

EDIT: reword this sentence
this is why the bubble colors were not changing,
the bubbles are shifted, 2 and 5 bars, after the last bar, but the color trigger variable was not offset.

Ruby:
# sqz10symbols_01

# https://usethinkscript.com/threads/multi-symbol-squeeze.6924/
# Multi Symbol Squeeze

# ------------------
# mods by halcyonguy
#  started with kg3344 code from post #11
# ------------------
# bubbles are shifted, 2 and 5 bars, after the last bar, but color trigger is not.
#  the s# var needs to be shifted also
#  add variables for the 2 time shifts, for...

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

@KG3344 squeezed is defined inside the script. You need to take it out.
Doesn't that script need "squeezed" to be defined or plotted for each symbol? This is what I got so far after cleaning it up a bit. I think it's calling the script, but now it only prints a red line.


Code:
declare lower;


input symbol10 = "XLY";
input symbol9 = "XLP";
input symbol8 = "XLE";
input symbol7 = "XLF";
input symbol6 = "XLV";
input symbol5 = "XLI";
input symbol4 = "XLB";
input symbol3 = "XLRE";
input symbol2 = "XLK";
input symbol1 = "XLU";



script SymbolSqueeze {
  

    input symbol = "";
    def Length = 20.0;
    def price = close(symbol);
    def bbprice = close(symbol);
    input displace = 0;
    input numdevdn = -2.0;
    input numdevup = 2.0;
    input averagetype = AverageType.SIMPLE;

    def bb_midline = BollingerBands(price, displace, Length, numdevdn, numdevup, averagetype).MidLine;
    def bb_upperband = BollingerBands(price, displace, Length, numdevdn, numdevup, averagetype).UpperBand;
    def bb_lowerband = BollingerBands(price, displace, Length, numdevdn, numdevup, averagetype).LowerBand;


# Use reference calls to TOS KC's and plot midline and bands

    input kcdisplace = 0;
    input kcfactor = 1.5;
    input kclength = 20;
    def kcprice = (close(symbol));
    input kcaverageType = AverageType.SIMPLE;
    input kctrueRangeAverageType = AverageType.SIMPLE;

    def kc_midline = KeltnerChannels(kcdisplace, kcfactor, kclength, kcprice, kcaverageType, kctrueRangeAverageType).Avg;
    def kc_upperband = KeltnerChannels(kcdisplace, kcfactor, kclength, kcprice, kcaverageType, kctrueRangeAverageType).Upper_Band;
    def kc_lowerband = KeltnerChannels(kcdisplace, kcfactor, kclength, kcprice, kcaverageType, kctrueRangeAverageType).Lower_Band;


# When the BB upper and lower bands cross inside the KC's we are in a Squeeze
    plot squeezed = if bb_upperband <= kc_upperband and bb_lowerband >= kc_lowerband then 1 else if bb_upperband >= kc_upperband and bb_lowerband <= kc_lowerband then -1 else 0;

}

def s1 = SymbolSqueeze(symbol1);
def s2 = SymbolSqueeze(symbol2);
def s3 = SymbolSqueeze(symbol3);
def s4 = SymbolSqueeze(symbol4);
def s5 = SymbolSqueeze(symbol5);
def s6 = SymbolSqueeze(symbol6);
def s7 = SymbolSqueeze(symbol7);
def s8 = SymbolSqueeze(symbol8);
def s9 = SymbolSqueeze(symbol9);
def s10 = SymbolSqueeze(symbol10);

plot symb1 =  if !IsNaN(close) and !isNan(close(symbol1)) then 1 else Double.NaN;

symb1.DefineColor("NoSqueeze", Color.GREEN);
symb1.DefineColor("SqueezeMid", Color.RED);


symb1.AssignValueColor(if s1 == 1 then symb1.Color("SqueezeMid") else if s1 == -1 then symb1.Color("NoSqueeze") else if s1 == 0 then symb1.Color("SqueezeMid") else Color.CURRENT);
symb1.SetLineWeight(3);
symb1.SetPaintingStrategy(PaintingStrategy.POINTS);
 
@KG3344 Ok, I thought you wanted to plot squeezed2. So are you looking for all 10 symbols to be in a squeeze?
Yeah, that's all I was looking to do. Should look like the image below.
7.jpg
 
Fixed the line but some of it is colored blue. Can't figure it out right now but good luck.
Code:
declare lower;

input symbol10 = "XLY";
input symbol9 = "XLP";
input symbol8 = "XLE";
input symbol7 = "XLF";
input symbol6 = "XLV";
input symbol5 = "XLI";
input symbol4 = "XLB";
input symbol3 = "XLRE";
input symbol2 = "XLK";
input symbol1 = "XLU";

script SymbolSqueeze {
input symbol = "";
def price = close(symbol);
def h = high(symbol);
def l = low(symbol);

input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.Simple;

def sDev = stdev(data = price, length = length);

def MidLine = MovingAverage(averageType, data = price, length = length);
def LowerBand = MidLine + num_Dev_Dn * sDev;
def UpperBand = MidLine + num_Dev_Up * sDev;

input factor = 1.5;
input trueRangeAverageType = AverageType.SIMPLE;

def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(h, price, l), length);

def average = MovingAverage(averageType, price, length);

def Avg = average;
def Upper_Band = average + shift;
def Lower_Band = average - shift;

plot return = if !isnan(close(symbol)) then LowerBand >= Lower_Band and UpperBand <= Upper_Band else 0;
}

def s1 = SymbolSqueeze(symbol1);
def s2 = SymbolSqueeze(symbol2);
def s3 = SymbolSqueeze(symbol3);
def s4 = SymbolSqueeze(symbol4);
def s5 = SymbolSqueeze(symbol5);
def s6 = SymbolSqueeze(symbol6);
def s7 = SymbolSqueeze(symbol7);
def s8 = SymbolSqueeze(symbol8);
def s9 = SymbolSqueeze(symbol9);
def s10 = SymbolSqueeze(symbol10);

plot symb1 = 1;
symb1.DefineColor("NoSqueeze", Color.GREEN);
symb1.DefineColor("SqueezeMid", Color.RED);


symb1.AssignValueColor(if s1 == 1 then symb1.Color("SqueezeMid") else symb1.Color("NoSqueeze"));
symb1.SetLineWeight(3);
symb1.SetPaintingStrategy(PaintingStrategy.POINTS);
 
Fixed the line but some of it is colored blue. Can't figure it out right now but good luck.
Code:
declare lower;

input symbol10 = "XLY";
input symbol9 = "XLP";
input symbol8 = "XLE";
input symbol7 = "XLF";
input symbol6 = "XLV";
input symbol5 = "XLI";
input symbol4 = "XLB";
input symbol3 = "XLRE";
input symbol2 = "XLK";
input symbol1 = "XLU";

script SymbolSqueeze {
input symbol = "";
def price = close(symbol);
def h = high(symbol);
def l = low(symbol);

input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.Simple;

def sDev = stdev(data = price, length = length);

def MidLine = MovingAverage(averageType, data = price, length = length);
def LowerBand = MidLine + num_Dev_Dn * sDev;
def UpperBand = MidLine + num_Dev_Up * sDev;

input factor = 1.5;
input trueRangeAverageType = AverageType.SIMPLE;

def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(h, price, l), length);

def average = MovingAverage(averageType, price, length);

def Avg = average;
def Upper_Band = average + shift;
def Lower_Band = average - shift;

plot return = if !isnan(close(symbol)) then LowerBand >= Lower_Band and UpperBand <= Upper_Band else 0;
}

def s1 = SymbolSqueeze(symbol1);
def s2 = SymbolSqueeze(symbol2);
def s3 = SymbolSqueeze(symbol3);
def s4 = SymbolSqueeze(symbol4);
def s5 = SymbolSqueeze(symbol5);
def s6 = SymbolSqueeze(symbol6);
def s7 = SymbolSqueeze(symbol7);
def s8 = SymbolSqueeze(symbol8);
def s9 = SymbolSqueeze(symbol9);
def s10 = SymbolSqueeze(symbol10);

plot symb1 = 1;
symb1.DefineColor("NoSqueeze", Color.GREEN);
symb1.DefineColor("SqueezeMid", Color.RED);


symb1.AssignValueColor(if s1 == 1 then symb1.Color("SqueezeMid") else symb1.Color("NoSqueeze"));
symb1.SetLineWeight(3);
symb1.SetPaintingStrategy(PaintingStrategy.POINTS);
That's awesome, thanks! I will keep working on it and see if I can finish it up.
 
Fixed the line but some of it is colored blue. Can't figure it out right now but good luck.
Code:
declare lower;

input symbol10 = "XLY";
input symbol9 = "XLP";
input symbol8 = "XLE";
input symbol7 = "XLF";
input symbol6 = "XLV";
input symbol5 = "XLI";
input symbol4 = "XLB";
input symbol3 = "XLRE";
input symbol2 = "XLK";
input symbol1 = "XLU";

script SymbolSqueeze {
input symbol = "";
def price = close(symbol);
def h = high(symbol);
def l = low(symbol);

input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.Simple;

def sDev = stdev(data = price, length = length);

def MidLine = MovingAverage(averageType, data = price, length = length);
def LowerBand = MidLine + num_Dev_Dn * sDev;
def UpperBand = MidLine + num_Dev_Up * sDev;

input factor = 1.5;
input trueRangeAverageType = AverageType.SIMPLE;

def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(h, price, l), length);

def average = MovingAverage(averageType, price, length);

def Avg = average;
def Upper_Band = average + shift;
def Lower_Band = average - shift;

plot return = if !isnan(close(symbol)) then LowerBand >= Lower_Band and UpperBand <= Upper_Band else 0;
}

def s1 = SymbolSqueeze(symbol1);
def s2 = SymbolSqueeze(symbol2);
def s3 = SymbolSqueeze(symbol3);
def s4 = SymbolSqueeze(symbol4);
def s5 = SymbolSqueeze(symbol5);
def s6 = SymbolSqueeze(symbol6);
def s7 = SymbolSqueeze(symbol7);
def s8 = SymbolSqueeze(symbol8);
def s9 = SymbolSqueeze(symbol9);
def s10 = SymbolSqueeze(symbol10);

plot symb1 = 1;
symb1.DefineColor("NoSqueeze", Color.GREEN);
symb1.DefineColor("SqueezeMid", Color.RED);


symb1.AssignValueColor(if s1 == 1 then symb1.Color("SqueezeMid") else symb1.Color("NoSqueeze"));
symb1.SetLineWeight(3);
symb1.SetPaintingStrategy(PaintingStrategy.POINTS);
did some testing. when extended hours is visible, i see n/a error on sdev formula. not sure why.
 
The blue (cyan) dots you're seeing are the default plot color being used for dots in the expansion area where there's no data yet to make a decision about color. This will fix it by not showing any dots in the expansion area.

Ruby:
plot symb1 = if !IsNaN(open) then 1 else Double.NaN;
 
The blue (cyan) dots you're seeing are the default plot color being used for dots in the expansion area where there's no data yet to make a decision about color. This will fix it by not showing any dots in the expansion area.

Ruby:
plot symb1 = if !IsNaN(open) then 1 else Double.NaN;
I changed the code but it still seems to plot that way for me. This is what I have so far after messing with it some more. Only other thing that I was hoping to do was to make it so the bubbles change color with the squeeze condition.

Code:
declare lower;

input symbol10 = "XLY";
input symbol9 = "XLP";
input symbol8 = "XLE";
input symbol7 = "XLF";
input symbol6 = "XLV";
input symbol5 = "XLI";
input symbol4 = "XLB";
input symbol3 = "XLRE";
input symbol2 = "XLK";
input symbol1 = "XLU";
input showLabels = yes;

DefineGlobalColor("SQ", Color.GREEN);
DefineGlobalColor("NO", Color.Dark_RED);


script SymbolSqueeze {
    input symbol = "";
    def price = close(symbol);
    def h = high(symbol);
    def l = low(symbol);

    input length = 20;
    input Num_Dev_Dn = -2.0;
    input Num_Dev_up = 2.0;
    input averageType = AverageType.SIMPLE;

    def sDev = StDev(data = price, length = length);

    def MidLine = MovingAverage(averageType, data = price, length = length);
    def LowerBand = MidLine + Num_Dev_Dn * sDev;
    def UpperBand = MidLine + Num_Dev_up * sDev;

    input factor = 1.5;
    input trueRangeAverageType = AverageType.SIMPLE;

    def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(h, price, l), length);

    def average = MovingAverage(averageType, price, length);

    def Avg = average;
    def Upper_Band = average + shift;
    def Lower_Band = average - shift;

    plot return = if !IsNaN(close(symbol)) then LowerBand >= Lower_Band and UpperBand <= Upper_Band else 0;
}

def s1 = SymbolSqueeze(symbol1);
def s2 = SymbolSqueeze(symbol2);
def s3 = SymbolSqueeze(symbol3);
def s4 = SymbolSqueeze(symbol4);
def s5 = SymbolSqueeze(symbol5);
def s6 = SymbolSqueeze(symbol6);
def s7 = SymbolSqueeze(symbol7);
def s8 = SymbolSqueeze(symbol8);
def s9 = SymbolSqueeze(symbol9);
def s10 = SymbolSqueeze(symbol10);

plot symb1 = if !IsNaN(open) then 1 else Double.NaN;
symb1.DefineColor("NoSqueeze", Color.GREEN);
symb1.DefineColor("SqueezeMid", Color.RED);
symb1.AssignValueColor(Color.GREEN);
symb1.AssignValueColor(if s1 == 0 then symb1.Color("NoSqueeze")else  symb1.Color("SqueezeMid"));
symb1.SetLineWeight(3);
symb1.SetPaintingStrategy(PaintingStrategy.POINTS);
addChartBubble(showLabels and isNan(close[1]) and !isNan(close[2]) and !isNan(close(symbol1)[2]),1,symbol1,if s1 == 1 then GlobalColor("SQ") else GlobalColor("NO"));
symb1.HideBubble();



plot symb2 = if !IsNaN(open) then 2 else Double.NaN;
symb2.DefineColor("NoSqueeze", Color.GREEN);
symb2.DefineColor("SqueezeMid", Color.RED);
symb2.AssignValueColor(Color.GREEN);
symb2.AssignValueColor(if s2 == 1 then symb2.Color("SqueezeMid") else symb2.Color("NoSqueeze"));
symb2.SetLineWeight(3);
symb2.SetPaintingStrategy(PaintingStrategy.POINTS);
AddChartBubble(showLabels and isNan(close[4]) and !isNan(close[5]) and !isNan(close(symbol2)[5]), 2, symbol2,if s2 == 1 then GlobalColor("SQ") else GlobalColor("NO"));
symb2.HideBubble();

plot symb3 = if !IsNaN(open) then 3 else Double.NaN;
symb3.DefineColor("NoSqueeze", Color.GREEN);
symb3.DefineColor("SqueezeMid", Color.RED);
symb3.AssignValueColor(Color.GREEN);
symb3.AssignValueColor(if s3 == 1 then symb3.Color("SqueezeMid") else symb3.Color("NoSqueeze"));
symb3.SetLineWeight(3);
symb3.SetPaintingStrategy(PaintingStrategy.POINTS);
AddChartBubble(showLabels and isNan(close[1]) and !isNan(close[2]) and !isNan(close(symbol3)[2]), 3, symbol3,if s3 == 1 then GlobalColor("SQ") else GlobalColor("NO"));
symb3.HideBubble();

plot symb4 = if !IsNaN(open) then 4 else Double.NaN;
symb4.DefineColor("NoSqueeze", Color.GREEN);
symb4.DefineColor("SqueezeMid", Color.RED);
symb4.AssignValueColor(Color.GREEN);
symb4.AssignValueColor(if s4 == 1 then symb4.Color("SqueezeMid") else symb4.Color("NoSqueeze"));
symb4.SetLineWeight(3);
symb4.SetPaintingStrategy(PaintingStrategy.POINTS);
AddChartBubble(showLabels and isNan(close[4]) and !isNan(close[5]) and !isNan(close(symbol4)[5]), 4, symbol4, if s4 == 1 then GlobalColor("SQ") else GlobalColor("NO"));
symb4.HideBubble();

plot symb5 = if !IsNaN(open) then 5 else Double.NaN;
symb5.DefineColor("NoSqueeze", Color.GREEN);
symb5.DefineColor("SqueezeMid", Color.RED);
symb5.AssignValueColor(Color.GREEN);
symb5.AssignValueColor(if s5 == 1 then symb5.Color("SqueezeMid") else symb5.Color("NoSqueeze"));
symb5.SetLineWeight(3);
symb5.SetPaintingStrategy(PaintingStrategy.POINTS);
AddChartBubble(showLabels and isNan(close[1]) and !isNan(close[2]) and !isNan(close(symbol5)[2]), 5, symbol5, if s5 == 1 then GlobalColor("SQ") else GlobalColor("NO"));
symb5.HideBubble();

plot symb6 = if !IsNaN(open) then 6 else Double.NaN;
symb6.DefineColor("NoSqueeze", Color.GREEN);
symb6.DefineColor("SqueezeMid", Color.RED);
symb6.AssignValueColor(Color.GREEN);
symb6.AssignValueColor(if s6 == 1 then symb6.Color("SqueezeMid") else symb6.Color("NoSqueeze"));
symb6.SetLineWeight(3);
symb6.SetPaintingStrategy(PaintingStrategy.POINTS);
AddChartBubble(showLabels and isNan(close[4]) and !isNan(close[5]) and !isNan(close(symbol6)[5]), 6, symbol6,if s6 == 1 then GlobalColor("SQ") else GlobalColor("NO"));
symb6.HideBubble();

plot symb7 = if !IsNaN(open) then 7 else Double.NaN;
symb7.DefineColor("NoSqueeze", Color.GREEN);
symb7.DefineColor("SqueezeMid", Color.RED);
symb7.AssignValueColor(Color.GREEN);
symb7.AssignValueColor(if s7 == 1 then symb7.Color("SqueezeMid") else symb7.Color("NoSqueeze"));
symb7.SetLineWeight(3);
symb7.SetPaintingStrategy(PaintingStrategy.POINTS);
AddChartBubble(showLabels and isNan(close[1]) and !isNan(close[2]) and !isNan(close(symbol7)[2]), 7, symbol7,if s7 == 1 then GlobalColor("SQ") else GlobalColor("NO"));
symb7.HideBubble();

plot symb8 = if !IsNaN(open) then 8 else Double.NaN;
symb8.DefineColor("NoSqueeze", Color.GREEN);
symb8.DefineColor("SqueezeMid", Color.RED);
symb8.AssignValueColor(Color.GREEN);
symb8.AssignValueColor(if s8 == 1 then symb8.Color("SqueezeMid") else symb8.Color("NoSqueeze"));
symb8.SetLineWeight(3);
symb8.SetPaintingStrategy(PaintingStrategy.POINTS);
AddChartBubble(showLabels and isNan(close[4]) and !isNan(close[5]) and !isNan(close(symbol8)[5]), 8, symbol8, if s8 == 1 then GlobalColor("SQ") else GlobalColor("NO"));
symb8.HideBubble();

plot symb9 = if !IsNaN(open) then 9 else Double.NaN;
symb9.DefineColor("NoSqueeze", Color.GREEN);
symb9.DefineColor("SqueezeMid", Color.RED);
symb9.AssignValueColor(Color.GREEN);
symb9.AssignValueColor(if s9 == 1 then symb9.Color("SqueezeMid") else symb9.Color("NoSqueeze"));
symb9.SetLineWeight(3);
symb9.SetPaintingStrategy(PaintingStrategy.POINTS);
AddChartBubble(showLabels and isNan(close[1]) and !isNan(close[2]) and !isNan(close(symbol9)[2]), 9, symbol9,if s9 == 1 then GlobalColor("SQ") else GlobalColor("NO"));
symb9.HideBubble();

plot symb10 = if !IsNaN(open) then 10 else Double.NaN;
symb10.DefineColor("NoSqueeze", Color.GREEN);
symb10.DefineColor("SqueezeMid", Color.RED);
symb10.AssignValueColor(Color.GREEN);
symb10.AssignValueColor(if s10 == 1 then symb10.Color("SqueezeMid") else symb10.Color("NoSqueeze"));
symb10.SetLineWeight(3);
symb10.SetPaintingStrategy(PaintingStrategy.POINTS);
AddChartBubble(showLabels and isNan(close[4]) and !isNan(close[5]) and !isNan(close(symbol10)[5]), 10, symbol10,if s10 == 1 then GlobalColor("SQ") else GlobalColor("NO"));
symb10.HideBubble();
 
I changed the code but it still seems to plot that way for me. This is what I have so far after messing with it some more. Only other thing that I was hoping to do was to make it so the bubbles change color with the squeeze condition.

I see. The code I gave you fixed the expansion area but you can still see colors that seem random at the beginning of the chart for recent IPOs. The issue there is it takes 20 periods of data (length of the averages used in the BB and KC) to determine if there's a squeeze or not. One way to solve that is setting the default color of the plots to match your background color.

Ruby:
symb1.SetDefaultColor(Color.BLACK);

Also, you can avoid having to define red and green for every plot by using global colors instead.

Code:
DefineGlobalColor("NoSqueeze", Color.GREEN);
DefineGlobalColor("SqueezeMid", Color.RED);
symb1.AssignValueColor(if s1 == 0 then GlobalColor("NoSqueeze") else GlobalColor("SqueezeMid"));

You have your global colors reversed (red/green) for SQ vs NO. Aside from that, my eyes aren't catching a reason the logic won't work for setting the colors of the bubbles to match the squeeze state
 
Last edited:
i started with kg3344 code from post #11 and made some changes.
the changes are listed in comments at the top of the study
the bubble colors change to match the last dot.

EDIT: reword this sentence
this is why the bubble colors were not changing,
the bubbles are shifted, 2 and 5 bars, after the last bar, but the color trigger variable was not offset.

Ruby:
# sqz10symbols_01

# https://usethinkscript.com/threads/multi-symbol-squeeze.6924/
# Multi Symbol Squeeze

# ------------------
# mods by halcyonguy
#  started with kg3344 code from post #11
# ------------------
# bubbles are shifted, 2 and 5 bars, after the last bar, but color trigger is not.
#  the s# var needs to be shifted also
#  add variables for the 2 time shifts, for bubbles. also use them for color trigger
#   def evenshift = 5;   def oddshift = 2;

# add vertical shift for bubbles, to lower them, so they are centered on the lines
# change point colors to use global ( like slippage said )
# move plot parameters to be together ( moved ..HideBubble() before addchartbubble)

# not sure why this was in the code? disable it
#symb1.AssignValueColor(Color.GREEN);

# sometimes, first few points are different colors. because the subscript is sending out a NA error.
#  when plotting points, add a check if trigger is an error ( s1, s2,...)
#   add error color , white
#   if isnan(s1) then GlobalColor("err")
#  tried to add it in the subscript, but didn't work. i wanted to output a -1 if an error.

# add option to show test bubbles on #10 points, to display the trigger var, s10
#  with symbols with enough bars of data,
#   with 2hr chart, first 4 candles have NA values , on most symbols, except if one of them is shown in upper chart
#   with 4 hr chart, first 10 candles have NA values,.....
#   with daily chart, first 17 candles have NA values,.....

# add a label message, if there are not enough candles of data

# test symbols, recent IPOs
# https://www.marketwatch.com/tools/ipo-calendar
# CYT  6/14
# FA   6/21
# DDL  6/28



declare lower;

input symbol10 = "XLY";
input symbol9 = "XLP";
input symbol8 = "XLE";
input symbol7 = "XLF";
input symbol6 = "XLV";
input symbol5 = "XLI";
input symbol4 = "XLB";
input symbol3 = "XLRE";
input symbol2 = "XLK";
input symbol1 = "XLU";

input showLabels = yes;
input show_test_bubbles = no;

#DefineGlobalColor("SQ", Color.GREEN);
#DefineGlobalColor("NO", Color.Dark_RED);
DefineGlobalColor("NO", Color.GREEN);
DefineGlobalColor("SQ", Color.Dark_RED);
DefineGlobalColor("err", Color.white);

# add a line, to push chart down, so can read top bubble
# not needed. shifted bubbles down
#plot a = 11;

# add a vertical adjust, so bubbles are lines up with the line
def bubble_vert_adjust = -0.7;

# shift bubbles to the right
def evenshift = 5;
def oddshift = 2;

# DefineGlobalColor("NoSqueeze", Color.GREEN);
# DefineGlobalColor("SqueezeMid", Color.RED);
# symb1.AssignValueColor(if s1 == 0 then GlobalColor("No") else GlobalColor("Sq"));


def len_aux = 5;
#def len_aux = if chartmin == 120 then 5 else if chartmin == 240 then 10 else if chartmin == 1440 then 17 else 0;
input len2 = 20;  #hint len2: set this tha same as length in script
def barCount = HighestAll(If(IsNaN(close), 0, barNumber()));
def nodata = ( barcount <= len2 + len_aux);
addlabel(nodata, " <<<<<<<<<<  not enough candles.  need " + (len2 + len_aux + 1) + ".  pick a lower chart time. >>>>>>>>>>", color.cyan);


script SymbolSqueeze {
    input symbol = "";
    def price = close(symbol);
    def h = high(symbol);
    def l = low(symbol);

    input length = 20;
    input Num_Dev_Dn = -2.0;
    input Num_Dev_up = 2.0;
    input averageType = AverageType.SIMPLE;

    def sDev = StDev(data = price, length = length);

    def MidLine = MovingAverage(averageType, data = price, length = length);
    def LowerBand = MidLine + Num_Dev_Dn * sDev;
    def UpperBand = MidLine + Num_Dev_up * sDev;

    input factor = 1.5;
    input trueRangeAverageType = AverageType.SIMPLE;

    def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(h, price, l), length);

    def average = MovingAverage(averageType, price, length);

    def Avg = average;
    def Upper_Band = average + shift;
    def Lower_Band = average - shift;

#    plot return = if !IsNaN(close(symbol)) then LowerBand >= Lower_Band and UpperBand <= Upper_Band else 0;
    plot return = if !IsNaN(close(symbol)) then LowerBand >= Lower_Band and UpperBand <= Upper_Band else 0;
}

def s1 = SymbolSqueeze(symbol1);
def s2 = SymbolSqueeze(symbol2);
def s3 = SymbolSqueeze(symbol3);
def s4 = SymbolSqueeze(symbol4);
def s5 = SymbolSqueeze(symbol5);
def s6 = SymbolSqueeze(symbol6);
def s7 = SymbolSqueeze(symbol7);
def s8 = SymbolSqueeze(symbol8);
def s9 = SymbolSqueeze(symbol9);
def s10 = SymbolSqueeze(symbol10);

plot symb1 = if !IsNaN(open) then 1 else Double.NaN;
#symb1.DefineColor("NoSqueeze", Color.GREEN);
#symb1.DefineColor("SqueezeMid", Color.RED);
#symb1.AssignValueColor(Color.GREEN);
#symb1.AssignValueColor(if s1 == 0 then symb1.Color("NoSqueeze")else symb1.Color("SqueezeMid"));
#symb1.AssignValueColor(if s1 == 0 then GlobalColor("No") else GlobalColor("Sq"));
symb1.AssignValueColor(if isnan(s1) then GlobalColor("err") else if s1 == 0 then GlobalColor("No") else GlobalColor("Sq"));
symb1.SetLineWeight(3);
symb1.SetPaintingStrategy(PaintingStrategy.POINTS);
symb1.HideBubble();
addChartBubble(showLabels and isNan(close[oddshift-1]) and !isNan(close[oddshift]) and !isNan(close(symbol1)[oddshift]), (1 + bubble_vert_adjust), symbol1, if s1[oddshift] == 1 then GlobalColor("SQ") else GlobalColor("NO"));

# old
# DefineGlobalColor("SQ", Color.GREEN);
# DefineGlobalColor("NO", Color.Dark_RED);


plot symb2 = if !IsNaN(open) then 2 else Double.NaN;
#symb2.DefineColor("NoSqueeze", Color.GREEN);
#symb2.DefineColor("SqueezeMid", Color.RED);
#symb2.AssignValueColor(Color.GREEN);
#symb2.AssignValueColor(if s2 == 1 then symb2.Color("SqueezeMid") else symb2.Color("NoSqueeze"));
symb2.AssignValueColor(if isnan(s2) then GlobalColor("err") else if s2 == 0 then GlobalColor("No") else GlobalColor("Sq"));
symb2.SetLineWeight(3);
symb2.SetPaintingStrategy(PaintingStrategy.POINTS);
symb2.HideBubble();
AddChartBubble(showLabels and isNan(close[evenshift-1]) and !isNan(close[evenshift]) and !isNan(close(symbol2)[evenshift]), (2 + bubble_vert_adjust), symbol2,if s2[evenshift] == 1 then GlobalColor("SQ") else GlobalColor("NO"));


plot symb3 = if !IsNaN(open) then 3 else Double.NaN;
#symb3.DefineColor("NoSqueeze", Color.GREEN);
#symb3.DefineColor("SqueezeMid", Color.RED);
#symb3.AssignValueColor(Color.GREEN);
#symb3.AssignValueColor(if s3 == 1 then symb3.Color("SqueezeMid") else symb3.Color("NoSqueeze"));
symb3.AssignValueColor(if isnan(s3) then GlobalColor("err") else if s3 == 0 then GlobalColor("No") else GlobalColor("Sq"));
symb3.SetLineWeight(3);
symb3.SetPaintingStrategy(PaintingStrategy.POINTS);
symb3.HideBubble();
AddChartBubble(showLabels and isNan(close[oddshift-1]) and !isNan(close[oddshift]) and !isNan(close(symbol3)[oddshift]), (3 + bubble_vert_adjust), symbol3,if s3[oddshift] == 1 then GlobalColor("SQ") else GlobalColor("NO"));


plot symb4 = if !IsNaN(open) then 4 else Double.NaN;
#symb4.DefineColor("NoSqueeze", Color.GREEN);
#symb4.DefineColor("SqueezeMid", Color.RED);
#symb4.AssignValueColor(Color.GREEN);
#symb4.AssignValueColor(if s4 == 1 then symb4.Color("SqueezeMid") else symb4.Color("NoSqueeze"));
symb4.AssignValueColor(if isnan(s4) then GlobalColor("err") else if s4 == 0 then GlobalColor("No") else GlobalColor("Sq"));
symb4.SetLineWeight(3);
symb4.SetPaintingStrategy(PaintingStrategy.POINTS);
symb4.HideBubble();
AddChartBubble(showLabels and isNan(close[evenshift-1]) and !isNan(close[evenshift]) and !isNan(close(symbol4)[evenshift]), (4 + bubble_vert_adjust), symbol4, if s4[evenshift] == 1 then GlobalColor("SQ") else GlobalColor("NO"));


plot symb5 = if !IsNaN(open) then 5 else Double.NaN;
#symb5.DefineColor("NoSqueeze", Color.GREEN);
#symb5.DefineColor("SqueezeMid", Color.RED);
#symb5.AssignValueColor(Color.GREEN);
#symb5.AssignValueColor(if s5 == 1 then symb5.Color("SqueezeMid") else symb5.Color("NoSqueeze"));
symb5.AssignValueColor(if isnan(s5) then GlobalColor("err") else if s5 == 0 then GlobalColor("No") else GlobalColor("Sq"));
symb5.SetLineWeight(3);
symb5.SetPaintingStrategy(PaintingStrategy.POINTS);
symb5.HideBubble();
AddChartBubble(showLabels and isNan(close[oddshift-1]) and !isNan(close[oddshift]) and !isNan(close(symbol5)[oddshift]), (5 + bubble_vert_adjust), symbol5, if s5[oddshift] == 1 then GlobalColor("SQ") else GlobalColor("NO"));


plot symb6 = if !IsNaN(open) then 6 else Double.NaN;
#symb6.DefineColor("NoSqueeze", Color.GREEN);
#symb6.DefineColor("SqueezeMid", Color.RED);
#symb6.AssignValueColor(Color.GREEN);
#symb6.AssignValueColor(if s6 == 1 then symb6.Color("SqueezeMid") else symb6.Color("NoSqueeze"));
symb6.AssignValueColor(if isnan(s6) then GlobalColor("err") else if s6 == 0 then GlobalColor("No") else GlobalColor("Sq"));
symb6.SetLineWeight(3);
symb6.SetPaintingStrategy(PaintingStrategy.POINTS);
symb6.HideBubble();
AddChartBubble(showLabels and isNan(close[evenshift-1]) and !isNan(close[evenshift]) and !isNan(close(symbol6)[evenshift]), (6 + bubble_vert_adjust), symbol6,if s6[evenshift] == 1 then GlobalColor("SQ") else GlobalColor("NO"));


plot symb7 = if !IsNaN(open) then 7 else Double.NaN;
#symb7.DefineColor("NoSqueeze", Color.GREEN);
#symb7.DefineColor("SqueezeMid", Color.RED);
#symb7.AssignValueColor(Color.GREEN);
#symb7.AssignValueColor(if s7 == 1 then symb7.Color("SqueezeMid") else symb7.Color("NoSqueeze"));
symb7.AssignValueColor(if isnan(s7) then GlobalColor("err") else if s7 == 0 then GlobalColor("No") else GlobalColor("Sq"));
symb7.SetLineWeight(3);
symb7.SetPaintingStrategy(PaintingStrategy.POINTS);
symb7.HideBubble();
AddChartBubble(showLabels and isNan(close[oddshift-1]) and !isNan(close[oddshift]) and !isNan(close(symbol7)[oddshift]), (7 + bubble_vert_adjust), symbol7, if s7[oddshift] == 1 then GlobalColor("SQ") else GlobalColor("NO"));


plot symb8 = if !IsNaN(open) then 8 else Double.NaN;
#symb8.DefineColor("NoSqueeze", Color.GREEN);
#symb8.DefineColor("SqueezeMid", Color.RED);
#symb8.AssignValueColor(Color.GREEN);
#symb8.AssignValueColor(if s8 == 1 then symb8.Color("SqueezeMid") else symb8.Color("NoSqueeze"));
symb8.AssignValueColor(if isnan(s8) then GlobalColor("err") else if s8 == 0 then GlobalColor("No") else GlobalColor("Sq"));
symb8.SetLineWeight(3);
symb8.SetPaintingStrategy(PaintingStrategy.POINTS);
symb8.HideBubble();
AddChartBubble(showLabels and isNan(close[evenshift-1]) and !isNan(close[evenshift]) and !isNan(close(symbol8)[evenshift]), (8 + bubble_vert_adjust), symbol8, if s8[evenshift] == 1 then GlobalColor("SQ") else GlobalColor("NO"));


plot symb9 = if !IsNaN(open) then 9 else Double.NaN;
#symb9.DefineColor("NoSqueeze", Color.GREEN);
#symb9.DefineColor("SqueezeMid", Color.RED);
#symb9.AssignValueColor(Color.GREEN);
#symb9.AssignValueColor(if s9 == 1 then symb9.Color("SqueezeMid") else symb9.Color("NoSqueeze"));
symb9.AssignValueColor(if isnan(s9) then GlobalColor("err") else if s9 == 0 then GlobalColor("No") else GlobalColor("Sq"));
symb9.SetLineWeight(3);
symb9.SetPaintingStrategy(PaintingStrategy.POINTS);
symb9.HideBubble();
AddChartBubble(showLabels and isNan(close[oddshift-1]) and !isNan(close[oddshift]) and !isNan(close(symbol9)[oddshift]), (9 + bubble_vert_adjust), symbol9, if s9[oddshift] == 1 then GlobalColor("SQ") else GlobalColor("NO"), yes);


plot symb10 = if !IsNaN(open) then 10 else Double.NaN;
#symb10.DefineColor("NoSqueeze", Color.GREEN);
#symb10.DefineColor("SqueezeMid", Color.RED);
#symb10.AssignValueColor(Color.GREEN);
#symb10.AssignValueColor(if s10 == 1 then symb10.Color("SqueezeMid") else symb10.Color("NoSqueeze"));
symb10.AssignValueColor(if isnan(s10) then GlobalColor("err") else if s10 == 0 then GlobalColor("No") else GlobalColor("Sq"));
symb10.SetLineWeight(3);
symb10.SetPaintingStrategy(PaintingStrategy.POINTS);
symb10.HideBubble();
AddChartBubble(showLabels and isNan(close[evenshift-1]) and !isNan(close[evenshift]) and !isNan(close(symbol10)[evenshift]), (10 + bubble_vert_adjust), symbol10, if s10[evenshift] == 1 then GlobalColor("SQ") else GlobalColor("NO"), yes);



#show_test_bubbles
AddChartBubble(show_test_bubbles, 1, s1, color.cyan, no);


#
 
Last edited:
Solution
#The following is my version of a multi symbol squeeze pro. It calculates a squeeze across the 4 major indexes, several of the sector ETFs and the VIX
Ruby:
declare lower;

def over_bought0 = -10;
plot OverBought0 = over_bought0;
OverBought0.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought0.SetStyle(Curve.LONG_DASH);
OverBought0.SetLineWeight(3);

def over_bought = 0;
plot OverBought = over_bought;
OverBought.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought.SetStyle(Curve.LONG_DASH);
OverBought.SetLineWeight(3);

def over_bought1 = 10;
plot OverBought1 = over_bought1;
OverBought1.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought1.SetStyle(Curve.LONG_DASH);
OverBought1.SetLineWeight(3);


def over_bought2 = 20;
plot OverBought2 = over_bought2;
OverBought2.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought2.SetStyle(Curve.LONG_DASH);
OverBought2.SetLineWeight(3);

def over_bought3 = 30;
plot OverBought3 = over_bought3;
OverBought3.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought3.SetStyle(Curve.LONG_DASH);
OverBought3.SetLineWeight(3);


def over_bought4 = 40;
plot OverBought4 = over_bought4;
OverBought4.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought4.SetStyle(Curve.LONG_DASH);
OverBought4.SetLineWeight(3);


def over_bought5 = 50;
plot OverBought5 = over_bought5;
OverBought5.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought5.SetStyle(Curve.LONG_DASH);
OverBought5.SetLineWeight(3);


def over_bought6 = 60;
plot OverBought6 = over_bought6;
OverBought6.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought6.SetStyle(Curve.LONG_DASH);
OverBought6.SetLineWeight(3);


def over_bought7 = 70;
plot OverBought7 = over_bought7;
OverBought7.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought7.SetStyle(Curve.LONG_DASH);
OverBought7.SetLineWeight(3);


def over_bought8 = 80;
plot OverBought8 = over_bought8;
OverBought8.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought8.SetStyle(Curve.LONG_DASH);
OverBought8.SetLineWeight(3);


def over_bought9 = 90;
plot OverBought9 = over_bought9;
OverBought9.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought9.SetStyle(Curve.LONG_DASH);
OverBought9.SetLineWeight(3);


def over_bought10 = 100;
plot OverBought10 = over_bought10;
OverBought10.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought10.SetStyle(Curve.LONG_DASH);
OverBought10.SetLineWeight(3);

def over_bought11 = 110;
plot OverBought11 = over_bought11;
OverBought11.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought11.SetStyle(Curve.LONG_DASH);
OverBought11.SetLineWeight(3);


def over_bought12 = 120;
plot OverBought12 = over_bought12;
OverBought12.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought12.SetStyle(Curve.LONG_DASH);
OverBought12.SetLineWeight(3);

def over_bought13 = 130;
plot OverBought13 = over_bought13;
OverBought13.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought13.SetStyle(Curve.LONG_DASH);
OverBought13.SetLineWeight(3);


def over_bought14 = 140;
plot OverBought14 = over_bought14;
OverBought14.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought14.SetStyle(Curve.LONG_DASH);
OverBought14.SetLineWeight(3);

def over_bought15 = 150;
plot OverBought15 = over_bought15;
OverBought15.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought15.SetStyle(Curve.LONG_DASH);
OverBought15.SetLineWeight(3);

def over_bought16 = 160;
plot OverBought16 = over_bought16;
OverBought16.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought16.SetStyle(Curve.LONG_DASH);
OverBought16.SetLineWeight(3);


input symbol0 = "DIA";
input symbol = "SPY";
input symbol1 = "QQQ";
input symbol2 = "IWM";
input symbol3 = "XLB";
input symbol4 = "XLC";
input symbol5 = "XLE";
input symbol6 = "XLF";
input symbol7 = "XLI";
input symbol8 = "XLK";
input symbol9 = "XLP";
input symbol10 = "XLU";
input symbol11 = "XLV";
input symbol12 = "XLY";
input symbol13 = "XRT";
input symbol14 = "XHB";
input symbol15 = "IYT";
input symbol16 = "VIX";

def length = 20;
def Num_Dev_Dn = -2.0;
def Num_Dev_up = 2.0;
def averageType = AverageType.SIMPLE;
def factorhigh = 1.0;
def factormid = 1.5;
def factorlow = 2.0;
def trueRangeAverageType = AverageType.SIMPLE;


#def displace = 0;
def sDev0 = StDev(data = close(symbol0), length = length);
def MidLineBB0 = MovingAverage(averageType, data = close(symbol0), length = length);
def LowerBand0BB0 = MidLineBB0 + Num_Dev_Dn * sDev0;
def UpperBand0BB0 = MidLineBB0 + Num_Dev_up * sDev0;

def shift0high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol0), close(symbol0), low(symbol0)), length);
def shift0Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol0), close(symbol0), low(symbol0)), length);
def shift0low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol0), close(symbol0), low(symbol0)), length);
def average0 = MovingAverage(averageType, close(symbol0), length);

def Avg0 = average0;

def UpperBand0KCLow = average0 + shift0low;
def LowerBand0KCLow = average0 - shift0low;

def UpperBand0KCMid = average0 + shift0Mid;
def LowerBand0KCMid = average0 - shift0Mid;
def UpperBand0KCHigh = average0 + shift0high;
def LowerBand0KCHigh = average0 - shift0high;

def preSqueeze0 = LowerBand0BB0 > LowerBand0KCLow and UpperBand0BB0 < UpperBand0KCLow;
def originalSqueeze0 = LowerBand0BB0 > LowerBand0KCMid and UpperBand0BB0 < UpperBand0KCMid;
def ExtrSqueeze0 = LowerBand0BB0 > LowerBand0KCHigh and UpperBand0BB0 < UpperBand0KCHigh;

OverBought0.AssignValueColor(if ExtrSqueeze0 then Color.Cyan else if originalSqueeze0 then Color.Magenta else if preSqueeze0 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "DIA", if ExtrSqueeze0 then Color.Cyan else if originalSqueeze0 then Color.Magenta else if preSqueeze0 then Color.DARK_ORANGE else Color.GRAY);

##########SPY
def sDev = StDev(data = close(symbol), length = length);
def MidLineBB = MovingAverage(averageType, data = close(symbol), length = length);
def LowerBandBB = MidLineBB + Num_Dev_Dn * sDev;
def UpperBandBB = MidLineBB + Num_Dev_up * sDev;

def shifthigh = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol), close(symbol), low(symbol)), length);
def shiftMid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol), close(symbol), low(symbol)), length);
def shiftlow = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol), close(symbol), low(symbol)), length);
def average = MovingAverage(averageType, close(symbol), length);


def Avg = average;

def UpperBandKCLow = average + shiftlow;
def LowerBandKCLow = average - shiftlow;

def UpperBandKCMid = average + shiftMid;
def LowerBandKCMid = average - shiftMid;

def UpperBandKCHigh = average + shifthigh;
def LowerBandKCHigh = average - shifthigh;


def presqueeze = LowerBandBB > LowerBandKCLow and UpperBandBB < UpperBandKCLow;
def originalSqueeze = LowerBandBB > LowerBandKCMid and UpperBandBB < UpperBandKCMid;
def ExtrSqueeze = LowerBandBB > LowerBandKCHigh and UpperBandBB < UpperBandKCHigh;

OverBought.AssignValueColor(if ExtrSqueeze then Color.Cyan else if originalSqueeze then Color.Magenta else if presqueeze then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "SPY", if ExtrSqueeze then Color.Cyan else if originalSqueeze then Color.Magenta else if presqueeze then Color.DARK_ORANGE else Color.GRAY);

def sDev1 = StDev(data = close(symbol1), length = length);
def MidLineBB1 = MovingAverage(averageType, data = close(symbol1), length = length);
def LowerBand1BB1 = MidLineBB1 + Num_Dev_Dn * sDev1;
def UpperBand1BB1 = MidLineBB1 + Num_Dev_up * sDev1;

def shift1high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol1), close(symbol1), low(symbol1)), length);
def shift1Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol1), close(symbol1), low(symbol1)), length);
def shift1low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol1), close(symbol1), low(symbol1)), length);
def average1 = MovingAverage(averageType, close(symbol1), length);

def Avg1 = average1;

def UpperBand1KCLow = average1 + shift1low;
def LowerBand1KCLow = average1 - shift1low;

def UpperBand1KCMid = average1 + shift1Mid;
def LowerBand1KCMid = average1 - shift1Mid;
def UpperBand1KCHigh = average1 + shift1high;
def LowerBand1KCHigh = average1 - shift1high;

def preSqueeze1 = LowerBand1BB1 > LowerBand1KCLow and UpperBand1BB1 < UpperBand1KCLow;
def originalSqueeze1 = LowerBand1BB1 > LowerBand1KCMid and UpperBand1BB1 < UpperBand1KCMid;
def ExtrSqueeze1 = LowerBand1BB1 > LowerBand1KCHigh and UpperBand1BB1 < UpperBand1KCHigh;

OverBought1.AssignValueColor(if ExtrSqueeze1 then Color.Cyan else if originalSqueeze1 then Color.Magenta else if preSqueeze1 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "QQQ", if ExtrSqueeze1 then Color.Cyan else if originalSqueeze1 then Color.Magenta else if preSqueeze1 then Color.DARK_ORANGE else Color.GRAY);


def sDev2 = StDev(data = close(symbol2), length = length);
def MidLineBB2 = MovingAverage(averageType, data = close(symbol2), length = length);
def LowerBand2BB2 = MidLineBB2 + Num_Dev_Dn * sDev2;
def UpperBand2BB2 = MidLineBB2 + Num_Dev_up * sDev2;

def shift2high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol2), close(symbol2), low(symbol2)), length);
def shift2Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol2), close(symbol2), low(symbol2)), length);
def shift2low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol2), close(symbol2), low(symbol2)), length);
def average2 = MovingAverage(averageType, close(symbol2), length);

def Avg2 = average2;

def UpperBand2KCLow = average2 + shift2low;
def LowerBand2KCLow = average2 - shift2low;

def UpperBand2KCMid = average2 + shift2Mid;
def LowerBand2KCMid = average2 - shift2Mid;
def UpperBand2KCHigh = average2 + shift2high;
def LowerBand2KCHigh = average2 - shift2high;

def preSqueeze2 = LowerBand2BB2 > LowerBand2KCLow and UpperBand2BB2 < UpperBand2KCLow;
def originalSqueeze2 = LowerBand2BB2 > LowerBand2KCMid and UpperBand2BB2 < UpperBand2KCMid;
def ExtrSqueeze2 = LowerBand2BB2 > LowerBand2KCHigh and UpperBand2BB2 < UpperBand2KCHigh;

OverBought2.AssignValueColor(if ExtrSqueeze2 then Color.Cyan else if originalSqueeze2 then Color.Magenta else if preSqueeze2 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "IWM", if ExtrSqueeze2 then Color.Cyan else if originalSqueeze2 then Color.Magenta else if preSqueeze2 then Color.DARK_ORANGE else Color.GRAY);


def sDev3 = StDev(data = close(symbol3), length = length);
def MidLineBB3 = MovingAverage(averageType, data = close(symbol3), length = length);
def LowerBand3BB3 = MidLineBB3 + Num_Dev_Dn * sDev3;
def UpperBand3BB3 = MidLineBB3 + Num_Dev_up * sDev3;

def shift3high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol3), close(symbol3), low(symbol3)), length);
def shift3Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol3), close(symbol3), low(symbol3)), length);
def shift3low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol3), close(symbol3), low(symbol3)), length);
def average3 = MovingAverage(averageType, close(symbol3), length);

def Avg3 = average3;

def UpperBand3KCLow = average3 + shift3low;
def LowerBand3KCLow = average3 - shift3low;

def UpperBand3KCMid = average3 + shift3Mid;
def LowerBand3KCMid = average3 - shift3Mid;
def UpperBand3KCHigh = average3 + shift3high;
def LowerBand3KCHigh = average3 - shift3high;

def preSqueeze3 = LowerBand3BB3 > LowerBand3KCLow and UpperBand3BB3 < UpperBand3KCLow;
def originalSqueeze3 = LowerBand3BB3 > LowerBand3KCMid and UpperBand3BB3 < UpperBand3KCMid;
def ExtrSqueeze3 = LowerBand3BB3 > LowerBand3KCHigh and UpperBand3BB3 < UpperBand3KCHigh;

OverBought3.AssignValueColor(if ExtrSqueeze3 then Color.Cyan else if originalSqueeze3 then Color.Magenta else if preSqueeze3 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "XLB", if ExtrSqueeze3 then Color.Cyan else if originalSqueeze3 then Color.Magenta else if preSqueeze3 then Color.DARK_ORANGE else Color.GRAY);


def sDev4 = StDev(data = close(symbol4), length = length);
def MidLineBB4 = MovingAverage(averageType, data = close(symbol4), length = length);
def LowerBand4BB4 = MidLineBB4 + Num_Dev_Dn * sDev4;
def UpperBand4BB4 = MidLineBB4 + Num_Dev_up * sDev4;

def shift4high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol4), close(symbol4), low(symbol4)), length);
def shift4Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol4), close(symbol4), low(symbol4)), length);
def shift4low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol4), close(symbol4), low(symbol4)), length);
def average4 = MovingAverage(averageType, close(symbol4), length);

def Avg4 = average4;

def UpperBand4KCLow = average4 + shift4low;
def LowerBand4KCLow = average4 - shift4low;

def UpperBand4KCMid = average4 + shift4Mid;
def LowerBand4KCMid = average4 - shift4Mid;
def UpperBand4KCHigh = average4 + shift4high;
def LowerBand4KCHigh = average4 - shift4high;

def preSqueeze4 = LowerBand4BB4 > LowerBand4KCLow and UpperBand4BB4 < UpperBand4KCLow;
def originalSqueeze4 = LowerBand4BB4 > LowerBand4KCMid and UpperBand4BB4 < UpperBand4KCMid;
def ExtrSqueeze4 = LowerBand4BB4 > LowerBand4KCHigh and UpperBand4BB4 < UpperBand4KCHigh;

OverBought4.AssignValueColor(if ExtrSqueeze4 then Color.Cyan else if originalSqueeze4 then Color.Magenta else if preSqueeze4 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "XLC", if ExtrSqueeze4 then Color.Cyan else if originalSqueeze4 then Color.Magenta else if preSqueeze4 then Color.DARK_ORANGE else Color.GRAY);


def sDev5 = StDev(data = close(symbol5), length = length);
def MidLineBB5 = MovingAverage(averageType, data = close(symbol5), length = length);
def LowerBand5BB5 = MidLineBB5 + Num_Dev_Dn * sDev5;
def UpperBand5BB5 = MidLineBB5 + Num_Dev_up * sDev5;

def shift5high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol5), close(symbol5), low(symbol5)), length);
def shift5Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol5), close(symbol5), low(symbol5)), length);
def shift5low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol5), close(symbol5), low(symbol5)), length);
def average5 = MovingAverage(averageType, close(symbol5), length);

def Avg5 = average5;

def UpperBand5KCLow = average5 + shift5low;
def LowerBand5KCLow = average5 - shift5low;

def UpperBand5KCMid = average5 + shift5Mid;
def LowerBand5KCMid = average5 - shift5Mid;
def UpperBand5KCHigh = average5 + shift5high;
def LowerBand5KCHigh = average5 - shift5high;

def preSqueeze5 = LowerBand5BB5 > LowerBand5KCLow and UpperBand5BB5 < UpperBand5KCLow;
def originalSqueeze5 = LowerBand5BB5 > LowerBand5KCMid and UpperBand5BB5 < UpperBand5KCMid;
def ExtrSqueeze5 = LowerBand5BB5 > LowerBand5KCHigh and UpperBand5BB5 < UpperBand5KCHigh;

OverBought5.AssignValueColor(if ExtrSqueeze5 then Color.Cyan else if originalSqueeze5 then Color.Magenta else if preSqueeze5 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "XLE", if ExtrSqueeze5 then Color.Cyan else if originalSqueeze5 then Color.Magenta else if preSqueeze5 then Color.DARK_ORANGE else Color.GRAY);


def sDev6 = StDev(data = close(symbol6), length = length);
def MidLineBB6 = MovingAverage(averageType, data = close(symbol6), length = length);
def LowerBand6BB6 = MidLineBB6 + Num_Dev_Dn * sDev6;
def UpperBand6BB6 = MidLineBB6 + Num_Dev_up * sDev6;

def shift6high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol6), close(symbol6), low(symbol6)), length);
def shift6Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol6), close(symbol6), low(symbol6)), length);
def shift6low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol6), close(symbol6), low(symbol6)), length);
def average6 = MovingAverage(averageType, close(symbol6), length);

def Avg6 = average6;

def UpperBand6KCLow = average6 + shift6low;
def LowerBand6KCLow = average6 - shift6low;

def UpperBand6KCMid = average6 + shift6Mid;
def LowerBand6KCMid = average6 - shift6Mid;
def UpperBand6KCHigh = average6 + shift6high;
def LowerBand6KCHigh = average6 - shift6high;

def preSqueeze6 = LowerBand6BB6 > LowerBand6KCLow and UpperBand6BB6 < UpperBand6KCLow;
def originalSqueeze6 = LowerBand6BB6 > LowerBand6KCMid and UpperBand6BB6 < UpperBand6KCMid;
def ExtrSqueeze6 = LowerBand6BB6 > LowerBand6KCHigh and UpperBand6BB6 < UpperBand6KCHigh;

OverBought6.AssignValueColor(if ExtrSqueeze6 then Color.Cyan else if originalSqueeze6 then Color.Magenta else if preSqueeze6 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "XLF", if ExtrSqueeze6 then Color.Cyan else if originalSqueeze6 then Color.Magenta else if preSqueeze6 then Color.DARK_ORANGE else Color.GRAY);

def sDev7 = StDev(data = close(symbol7), length = length);
def MidLineBB7 = MovingAverage(averageType, data = close(symbol7), length = length);
def LowerBand7BB7 = MidLineBB7 + Num_Dev_Dn * sDev7;
def UpperBand7BB7 = MidLineBB7 + Num_Dev_up * sDev7;

def shift7high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol7), close(symbol7), low(symbol7)), length);
def shift7Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol7), close(symbol7), low(symbol7)), length);
def shift7low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol7), close(symbol7), low(symbol7)), length);
def average7 = MovingAverage(averageType, close(symbol7), length);

def Avg7 = average7;

def UpperBand7KCLow = average7 + shift7low;
def LowerBand7KCLow = average7 - shift7low;

def UpperBand7KCMid = average7 + shift7Mid;
def LowerBand7KCMid = average7 - shift7Mid;
def UpperBand7KCHigh = average7 + shift7high;
def LowerBand7KCHigh = average7 - shift7high;

def preSqueeze7 = LowerBand7BB7 > LowerBand7KCLow and UpperBand7BB7 < UpperBand7KCLow;
def originalSqueeze7 = LowerBand7BB7 > LowerBand7KCMid and UpperBand7BB7 < UpperBand7KCMid;
def ExtrSqueeze7 = LowerBand7BB7 > LowerBand7KCHigh and UpperBand7BB7 < UpperBand7KCHigh;

OverBought7.AssignValueColor(if ExtrSqueeze7 then Color.Cyan else if originalSqueeze7 then Color.Magenta else if preSqueeze7 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "XLI", if ExtrSqueeze7 then Color.Cyan else if originalSqueeze7 then Color.Magenta else if preSqueeze7 then Color.DARK_ORANGE else Color.GRAY);

def sDev8 = StDev(data = close(symbol8), length = length);
def MidLineBB8 = MovingAverage(averageType, data = close(symbol8), length = length);
def LowerBand8BB8 = MidLineBB8 + Num_Dev_Dn * sDev8;
def UpperBand8BB8 = MidLineBB8 + Num_Dev_up * sDev8;

def shift8high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol8), close(symbol8), low(symbol8)), length);
def shift8Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol8), close(symbol8), low(symbol8)), length);
def shift8low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol8), close(symbol8), low(symbol8)), length);
def average8 = MovingAverage(averageType, close(symbol8), length);

def Avg8 = average8;

def UpperBand8KCLow = average8 + shift8low;
def LowerBand8KCLow = average8 - shift8low;

def UpperBand8KCMid = average8 + shift8Mid;
def LowerBand8KCMid = average8 - shift8Mid;
def UpperBand8KCHigh = average8 + shift8high;
def LowerBand8KCHigh = average8 - shift8high;

def preSqueeze8 = LowerBand8BB8 > LowerBand8KCLow and UpperBand8BB8 < UpperBand8KCLow;
def originalSqueeze8 = LowerBand8BB8 > LowerBand8KCMid and UpperBand8BB8 < UpperBand8KCMid;
def ExtrSqueeze8 = LowerBand8BB8 > LowerBand8KCHigh and UpperBand8BB8 < UpperBand8KCHigh;

OverBought8.AssignValueColor(if ExtrSqueeze8 then Color.Cyan else if originalSqueeze8 then Color.Magenta else if preSqueeze8 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "XLK", if ExtrSqueeze8 then Color.Cyan else if originalSqueeze8 then Color.Magenta else if preSqueeze8 then Color.DARK_ORANGE else Color.GRAY);

def sDev9 = StDev(data = close(symbol9), length = length);
def MidLineBB9 = MovingAverage(averageType, data = close(symbol9), length = length);
def LowerBand9BB9 = MidLineBB9 + Num_Dev_Dn * sDev9;
def UpperBand9BB9 = MidLineBB9 + Num_Dev_up * sDev9;

def shift9high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol9), close(symbol9), low(symbol9)), length);
def shift9Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol9), close(symbol9), low(symbol9)), length);
def shift9low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol9), close(symbol9), low(symbol9)), length);
def average9 = MovingAverage(averageType, close(symbol9), length);

def Avg9 = average9;

def UpperBand9KCLow = average9 + shift9low;
def LowerBand9KCLow = average9 - shift9low;

def UpperBand9KCMid = average9 + shift9Mid;
def LowerBand9KCMid = average9 - shift9Mid;
def UpperBand9KCHigh = average9 + shift9high;
def LowerBand9KCHigh = average9 - shift9high;

def preSqueeze9 = LowerBand9BB9 > LowerBand9KCLow and UpperBand9BB9 < UpperBand9KCLow;
def originalSqueeze9 = LowerBand9BB9 > LowerBand9KCMid and UpperBand9BB9 < UpperBand9KCMid;
def ExtrSqueeze9 = LowerBand9BB9 > LowerBand9KCHigh and UpperBand9BB9 < UpperBand9KCHigh;

OverBought9.AssignValueColor(if ExtrSqueeze9 then Color.Cyan else if originalSqueeze9 then Color.Magenta else if preSqueeze9 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "XLP", if ExtrSqueeze9 then Color.Cyan else if originalSqueeze9 then Color.Magenta else if preSqueeze9 then Color.DARK_ORANGE else Color.GRAY);


def sDev10 = StDev(data = close(symbol10), length = length);
def MidLineBB10 = MovingAverage(averageType, data = close(symbol10), length = length);
def LowerBand10BB10 = MidLineBB10 + Num_Dev_Dn * sDev10;
def UpperBand10BB10 = MidLineBB10 + Num_Dev_up * sDev10;

def shift10high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol10), close(symbol10), low(symbol10)), length);
def shift10Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol10), close(symbol10), low(symbol10)), length);
def shift10low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol10), close(symbol10), low(symbol10)), length);
def average10 = MovingAverage(averageType, close(symbol10), length);

def Avg10 = average10;

def UpperBand10KCLow = average10 + shift10low;
def LowerBand10KCLow = average10 - shift10low;

def UpperBand10KCMid = average10 + shift10Mid;
def LowerBand10KCMid = average10 - shift10Mid;
def UpperBand10KCHigh = average10 + shift10high;
def LowerBand10KCHigh = average10 - shift10high;

def preSqueeze10 = LowerBand10BB10 > LowerBand10KCLow and UpperBand10BB10 < UpperBand10KCLow;
def originalSqueeze10 = LowerBand10BB10 > LowerBand10KCMid and UpperBand10BB10 < UpperBand10KCMid;
def ExtrSqueeze10 = LowerBand10BB10 > LowerBand10KCHigh and UpperBand10BB10 < UpperBand10KCHigh;

OverBought10.AssignValueColor(if ExtrSqueeze10 then Color.Cyan else if originalSqueeze10 then Color.Magenta else if preSqueeze10 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "XLU", if ExtrSqueeze10 then Color.Cyan else if originalSqueeze10 then Color.Magenta else if preSqueeze10 then Color.DARK_ORANGE else Color.GRAY);

def sDev11 = StDev(data = close(symbol11), length = length);
def MidLineBB11 = MovingAverage(averageType, data = close(symbol11), length = length);
def LowerBand11BB11 = MidLineBB11 + Num_Dev_Dn * sDev11;
def UpperBand11BB11 = MidLineBB11 + Num_Dev_up * sDev11;

def shift11high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol11), close(symbol11), low(symbol11)), length);
def shift11Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol11), close(symbol11), low(symbol11)), length);
def shift11low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol11), close(symbol11), low(symbol11)), length);
def average11 = MovingAverage(averageType, close(symbol11), length);

def Avg11 = average11;

def UpperBand11KCLow = average11 + shift11low;
def LowerBand11KCLow = average11 - shift11low;

def UpperBand11KCMid = average11 + shift11Mid;
def LowerBand11KCMid = average11 - shift11Mid;
def UpperBand11KCHigh = average11 + shift11high;
def LowerBand11KCHigh = average11 - shift11high;

def preSqueeze11 = LowerBand11BB11 > LowerBand11KCLow and UpperBand11BB11 < UpperBand11KCLow;
def originalSqueeze11 = LowerBand11BB11 > LowerBand11KCMid and UpperBand11BB11 < UpperBand11KCMid;
def ExtrSqueeze11 = LowerBand11BB11 > LowerBand11KCHigh and UpperBand11BB11 < UpperBand11KCHigh;

OverBought11.AssignValueColor(if ExtrSqueeze11 then Color.Cyan else if originalSqueeze11 then Color.Magenta else if preSqueeze11 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "XLV", if ExtrSqueeze11 then Color.Cyan else if originalSqueeze11 then Color.Magenta else if preSqueeze11 then Color.DARK_ORANGE else Color.GRAY);


def sDev12 = StDev(data = close(symbol12), length = length);
def MidLineBB12 = MovingAverage(averageType, data = close(symbol12), length = length);
def LowerBand12BB12 = MidLineBB12 + Num_Dev_Dn * sDev12;
def UpperBand12BB12 = MidLineBB12 + Num_Dev_up * sDev12;

def shift12high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol12), close(symbol12), low(symbol12)), length);
def shift12Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol12), close(symbol12), low(symbol12)), length);
def shift12low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol12), close(symbol12), low(symbol12)), length);
def average12 = MovingAverage(averageType, close(symbol12), length);

def Avg12 = average12;

def UpperBand12KCLow = average12 + shift12low;
def LowerBand12KCLow = average12 - shift12low;

def UpperBand12KCMid = average12 + shift12Mid;
def LowerBand12KCMid = average12 - shift12Mid;
def UpperBand12KCHigh = average12 + shift12high;
def LowerBand12KCHigh = average12 - shift12high;

def preSqueeze12 = LowerBand12BB12 > LowerBand12KCLow and UpperBand12BB12 < UpperBand12KCLow;
def originalSqueeze12 = LowerBand12BB12 > LowerBand12KCMid and UpperBand12BB12 < UpperBand12KCMid;
def ExtrSqueeze12 = LowerBand12BB12 > LowerBand12KCHigh and UpperBand12BB12 < UpperBand12KCHigh;

OverBought12.AssignValueColor(if ExtrSqueeze12 then Color.Cyan else if originalSqueeze12 then Color.Magenta else if preSqueeze12 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "XLY", if ExtrSqueeze12 then Color.Cyan else if originalSqueeze12 then Color.Magenta else if preSqueeze12 then Color.DARK_ORANGE else Color.GRAY);

def sDev13 = StDev(data = close(symbol13), length = length);
def MidLineBB13 = MovingAverage(averageType, data = close(symbol13), length = length);
def LowerBand13BB13 = MidLineBB13 + Num_Dev_Dn * sDev13;
def UpperBand13BB13 = MidLineBB13 + Num_Dev_up * sDev13;

def shift13high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol13), close(symbol13), low(symbol13)), length);
def shift13Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol13), close(symbol13), low(symbol13)), length);
def shift13low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol13), close(symbol13), low(symbol13)), length);
def average13 = MovingAverage(averageType, close(symbol13), length);

def Avg13 = average13;

def UpperBand13KCLow = average13 + shift13low;
def LowerBand13KCLow = average13 - shift13low;

def UpperBand13KCMid = average13 + shift13Mid;
def LowerBand13KCMid = average13 - shift13Mid;
def UpperBand13KCHigh = average13 + shift13high;
def LowerBand13KCHigh = average13 - shift13high;

def preSqueeze13 = LowerBand13BB13 > LowerBand13KCLow and UpperBand13BB13 < UpperBand13KCLow;
def originalSqueeze13 = LowerBand13BB13 > LowerBand13KCMid and UpperBand13BB13 < UpperBand13KCMid;
def ExtrSqueeze13 = LowerBand13BB13 > LowerBand13KCHigh and UpperBand13BB13 < UpperBand13KCHigh;

OverBought13.AssignValueColor(if ExtrSqueeze13 then Color.Cyan else if originalSqueeze13 then Color.Magenta else if preSqueeze13 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "XRT", if ExtrSqueeze13 then Color.Cyan else if originalSqueeze13 then Color.Magenta else if preSqueeze13 then Color.DARK_ORANGE else Color.GRAY);

def sDev14 = StDev(data = close(symbol14), length = length);
def MidLineBB14 = MovingAverage(averageType, data = close(symbol14), length = length);
def LowerBand14BB14 = MidLineBB14 + Num_Dev_Dn * sDev14;
def UpperBand14BB14 = MidLineBB14 + Num_Dev_up * sDev14;

def shift14high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol14), close(symbol14), low(symbol14)), length);
def shift14Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol14), close(symbol14), low(symbol14)), length);
def shift14low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol14), close(symbol14), low(symbol14)), length);
def average14 = MovingAverage(averageType, close(symbol14), length);

def Avg14 = average14;

def UpperBand14KCLow = average14 + shift14low;
def LowerBand14KCLow = average14 - shift14low;

def UpperBand14KCMid = average14 + shift14Mid;
def LowerBand14KCMid = average14 - shift14Mid;
def UpperBand14KCHigh = average14 + shift14high;
def LowerBand14KCHigh = average14 - shift14high;

def preSqueeze14 = LowerBand14BB14 > LowerBand14KCLow and UpperBand14BB14 < UpperBand14KCLow;
def originalSqueeze14 = LowerBand14BB14 > LowerBand14KCMid and UpperBand14BB14 < UpperBand14KCMid;
def ExtrSqueeze14 = LowerBand14BB14 > LowerBand14KCHigh and UpperBand14BB14 < UpperBand14KCHigh;

OverBought14.AssignValueColor(if ExtrSqueeze14 then Color.Cyan else if originalSqueeze14 then Color.Magenta else if preSqueeze14 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "XHB", if ExtrSqueeze14 then Color.Cyan else if originalSqueeze14 then Color.Magenta else if preSqueeze14 then Color.DARK_ORANGE else Color.GRAY);

def sDev15 = StDev(data = close(symbol15), length = length);
def MidLineBB15 = MovingAverage(averageType, data = close(symbol15), length = length);
def LowerBand15BB15 = MidLineBB15 + Num_Dev_Dn * sDev15;
def UpperBand15BB15 = MidLineBB15 + Num_Dev_up * sDev15;

def shift15high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol15), close(symbol15), low(symbol15)), length);
def shift15Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol15), close(symbol15), low(symbol15)), length);
def shift15low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol15), close(symbol15), low(symbol15)), length);
def average15 = MovingAverage(averageType, close(symbol15), length);

def Avg15 = average15;

def UpperBand15KCLow = average15 + shift15low;
def LowerBand15KCLow = average15 - shift15low;

def UpperBand15KCMid = average15 + shift15Mid;
def LowerBand15KCMid = average15 - shift15Mid;
def UpperBand15KCHigh = average15 + shift15high;
def LowerBand15KCHigh = average15 - shift15high;

def preSqueeze15 = LowerBand15BB15 > LowerBand15KCLow and UpperBand15BB15 < UpperBand15KCLow;
def originalSqueeze15 = LowerBand15BB15 > LowerBand15KCMid and UpperBand15BB15 < UpperBand15KCMid;
def ExtrSqueeze15 = LowerBand15BB15 > LowerBand15KCHigh and UpperBand15BB15 < UpperBand15KCHigh;

OverBought15.AssignValueColor(if ExtrSqueeze15 then Color.Cyan else if originalSqueeze15 then Color.Magenta else if preSqueeze15 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "IYT", if ExtrSqueeze15 then Color.Cyan else if originalSqueeze15 then Color.Magenta else if preSqueeze15 then Color.DARK_ORANGE else Color.GRAY);

def sDev16 = StDev(data = close(symbol16), length = length);
def MidLineBB16 = MovingAverage(averageType, data = close(symbol16), length = length);
def LowerBand16BB16 = MidLineBB16 + Num_Dev_Dn * sDev16;
def UpperBand16BB16 = MidLineBB16 + Num_Dev_up * sDev16;

def shift16high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol16), close(symbol16), low(symbol16)), length);
def shift16Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol16), close(symbol16), low(symbol16)), length);
def shift16low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol16), close(symbol16), low(symbol16)), length);
def average16 = MovingAverage(averageType, close(symbol16), length);

def Avg16 = average16;

def UpperBand16KCLow = average16 + shift16low;
def LowerBand16KCLow = average16 - shift16low;

def UpperBand16KCMid = average16 + shift16Mid;
def LowerBand16KCMid = average16 - shift16Mid;
def UpperBand16KCHigh = average16 + shift16high;
def LowerBand16KCHigh = average16 - shift16high;

def preSqueeze16 = LowerBand16BB16 > LowerBand16KCLow and UpperBand16BB16 < UpperBand16KCLow;
def originalSqueeze16 = LowerBand16BB16 > LowerBand16KCMid and UpperBand16BB16 < UpperBand16KCMid;
def ExtrSqueeze16 = LowerBand16BB16 > LowerBand16KCHigh and UpperBand16BB16 < UpperBand16KCHigh;

OverBought16.AssignValueColor(if ExtrSqueeze16 then Color.Cyan else if originalSqueeze16 then Color.Magenta else if preSqueeze16 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "VIX", if ExtrSqueeze16 then Color.Cyan else if originalSqueeze16 then Color.Magenta else if preSqueeze16 then Color.DARK_ORANGE else Color.GRAY);
 
Last edited by a moderator:
#The following is my version of a multi symbol squeeze pro. It calculates a squeeze across the 4 major indexes, several of the sector ETFs and the VIX


declare lower;

def over_bought0 = -10;
plot OverBought0 = over_bought0;
OverBought0.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought0.SetStyle(Curve.LONG_DASH);
OverBought0.SetLineWeight(3);

def over_bought = 0;
plot OverBought = over_bought;
OverBought.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought.SetStyle(Curve.LONG_DASH);
OverBought.SetLineWeight(3);

def over_bought1 = 10;
plot OverBought1 = over_bought1;
OverBought1.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought1.SetStyle(Curve.LONG_DASH);
OverBought1.SetLineWeight(3);


def over_bought2 = 20;
plot OverBought2 = over_bought2;
OverBought2.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought2.SetStyle(Curve.LONG_DASH);
OverBought2.SetLineWeight(3);

def over_bought3 = 30;
plot OverBought3 = over_bought3;
OverBought3.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought3.SetStyle(Curve.LONG_DASH);
OverBought3.SetLineWeight(3);


def over_bought4 = 40;
plot OverBought4 = over_bought4;
OverBought4.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought4.SetStyle(Curve.LONG_DASH);
OverBought4.SetLineWeight(3);


def over_bought5 = 50;
plot OverBought5 = over_bought5;
OverBought5.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought5.SetStyle(Curve.LONG_DASH);
OverBought5.SetLineWeight(3);


def over_bought6 = 60;
plot OverBought6 = over_bought6;
OverBought6.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought6.SetStyle(Curve.LONG_DASH);
OverBought6.SetLineWeight(3);


def over_bought7 = 70;
plot OverBought7 = over_bought7;
OverBought7.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought7.SetStyle(Curve.LONG_DASH);
OverBought7.SetLineWeight(3);


def over_bought8 = 80;
plot OverBought8 = over_bought8;
OverBought8.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought8.SetStyle(Curve.LONG_DASH);
OverBought8.SetLineWeight(3);


def over_bought9 = 90;
plot OverBought9 = over_bought9;
OverBought9.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought9.SetStyle(Curve.LONG_DASH);
OverBought9.SetLineWeight(3);


def over_bought10 = 100;
plot OverBought10 = over_bought10;
OverBought10.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought10.SetStyle(Curve.LONG_DASH);
OverBought10.SetLineWeight(3);

def over_bought11 = 110;
plot OverBought11 = over_bought11;
OverBought11.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought11.SetStyle(Curve.LONG_DASH);
OverBought11.SetLineWeight(3);


def over_bought12 = 120;
plot OverBought12 = over_bought12;
OverBought12.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought12.SetStyle(Curve.LONG_DASH);
OverBought12.SetLineWeight(3);

def over_bought13 = 130;
plot OverBought13 = over_bought13;
OverBought13.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought13.SetStyle(Curve.LONG_DASH);
OverBought13.SetLineWeight(3);


def over_bought14 = 140;
plot OverBought14 = over_bought14;
OverBought14.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought14.SetStyle(Curve.LONG_DASH);
OverBought14.SetLineWeight(3);

def over_bought15 = 150;
plot OverBought15 = over_bought15;
OverBought15.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought15.SetStyle(Curve.LONG_DASH);
OverBought15.SetLineWeight(3);

def over_bought16 = 160;
plot OverBought16 = over_bought16;
OverBought16.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
OverBought16.SetStyle(Curve.LONG_DASH);
OverBought16.SetLineWeight(3);


input symbol0 = "DIA";
input symbol = "SPY";
input symbol1 = "QQQ";
input symbol2 = "IWM";
input symbol3 = "XLB";
input symbol4 = "XLC";
input symbol5 = "XLE";
input symbol6 = "XLF";
input symbol7 = "XLI";
input symbol8 = "XLK";
input symbol9 = "XLP";
input symbol10 = "XLU";
input symbol11 = "XLV";
input symbol12 = "XLY";
input symbol13 = "XRT";
input symbol14 = "XHB";
input symbol15 = "IYT";
input symbol16 = "VIX";

def length = 20;
def Num_Dev_Dn = -2.0;
def Num_Dev_up = 2.0;
def averageType = AverageType.SIMPLE;
def factorhigh = 1.0;
def factormid = 1.5;
def factorlow = 2.0;
def trueRangeAverageType = AverageType.SIMPLE;


#def displace = 0;
def sDev0 = StDev(data = close(symbol0), length = length);
def MidLineBB0 = MovingAverage(averageType, data = close(symbol0), length = length);
def LowerBand0BB0 = MidLineBB0 + Num_Dev_Dn * sDev0;
def UpperBand0BB0 = MidLineBB0 + Num_Dev_up * sDev0;

def shift0high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol0), close(symbol0), low(symbol0)), length);
def shift0Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol0), close(symbol0), low(symbol0)), length);
def shift0low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol0), close(symbol0), low(symbol0)), length);
def average0 = MovingAverage(averageType, close(symbol0), length);

def Avg0 = average0;

def UpperBand0KCLow = average0 + shift0low;
def LowerBand0KCLow = average0 - shift0low;

def UpperBand0KCMid = average0 + shift0Mid;
def LowerBand0KCMid = average0 - shift0Mid;
def UpperBand0KCHigh = average0 + shift0high;
def LowerBand0KCHigh = average0 - shift0high;

def preSqueeze0 = LowerBand0BB0 > LowerBand0KCLow and UpperBand0BB0 < UpperBand0KCLow;
def originalSqueeze0 = LowerBand0BB0 > LowerBand0KCMid and UpperBand0BB0 < UpperBand0KCMid;
def ExtrSqueeze0 = LowerBand0BB0 > LowerBand0KCHigh and UpperBand0BB0 < UpperBand0KCHigh;

OverBought0.AssignValueColor(if ExtrSqueeze0 then Color.Cyan else if originalSqueeze0 then Color.Magenta else if preSqueeze0 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "DIA", if ExtrSqueeze0 then Color.Cyan else if originalSqueeze0 then Color.Magenta else if preSqueeze0 then Color.DARK_ORANGE else Color.GRAY);

##########SPY
def sDev = StDev(data = close(symbol), length = length);
def MidLineBB = MovingAverage(averageType, data = close(symbol), length = length);
def LowerBandBB = MidLineBB + Num_Dev_Dn * sDev;
def UpperBandBB = MidLineBB + Num_Dev_up * sDev;

def shifthigh = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol), close(symbol), low(symbol)), length);
def shiftMid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol), close(symbol), low(symbol)), length);
def shiftlow = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol), close(symbol), low(symbol)), length);
def average = MovingAverage(averageType, close(symbol), length);


def Avg = average;

def UpperBandKCLow = average + shiftlow;
def LowerBandKCLow = average - shiftlow;

def UpperBandKCMid = average + shiftMid;
def LowerBandKCMid = average - shiftMid;

def UpperBandKCHigh = average + shifthigh;
def LowerBandKCHigh = average - shifthigh;


def presqueeze = LowerBandBB > LowerBandKCLow and UpperBandBB < UpperBandKCLow;
def originalSqueeze = LowerBandBB > LowerBandKCMid and UpperBandBB < UpperBandKCMid;
def ExtrSqueeze = LowerBandBB > LowerBandKCHigh and UpperBandBB < UpperBandKCHigh;

OverBought.AssignValueColor(if ExtrSqueeze then Color.Cyan else if originalSqueeze then Color.Magenta else if presqueeze then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "SPY", if ExtrSqueeze then Color.Cyan else if originalSqueeze then Color.Magenta else if presqueeze then Color.DARK_ORANGE else Color.GRAY);

def sDev1 = StDev(data = close(symbol1), length = length);
def MidLineBB1 = MovingAverage(averageType, data = close(symbol1), length = length);
def LowerBand1BB1 = MidLineBB1 + Num_Dev_Dn * sDev1;
def UpperBand1BB1 = MidLineBB1 + Num_Dev_up * sDev1;

def shift1high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol1), close(symbol1), low(symbol1)), length);
def shift1Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol1), close(symbol1), low(symbol1)), length);
def shift1low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol1), close(symbol1), low(symbol1)), length);
def average1 = MovingAverage(averageType, close(symbol1), length);

def Avg1 = average1;

def UpperBand1KCLow = average1 + shift1low;
def LowerBand1KCLow = average1 - shift1low;

def UpperBand1KCMid = average1 + shift1Mid;
def LowerBand1KCMid = average1 - shift1Mid;
def UpperBand1KCHigh = average1 + shift1high;
def LowerBand1KCHigh = average1 - shift1high;

def preSqueeze1 = LowerBand1BB1 > LowerBand1KCLow and UpperBand1BB1 < UpperBand1KCLow;
def originalSqueeze1 = LowerBand1BB1 > LowerBand1KCMid and UpperBand1BB1 < UpperBand1KCMid;
def ExtrSqueeze1 = LowerBand1BB1 > LowerBand1KCHigh and UpperBand1BB1 < UpperBand1KCHigh;

OverBought1.AssignValueColor(if ExtrSqueeze1 then Color.Cyan else if originalSqueeze1 then Color.Magenta else if preSqueeze1 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "QQQ", if ExtrSqueeze1 then Color.Cyan else if originalSqueeze1 then Color.Magenta else if preSqueeze1 then Color.DARK_ORANGE else Color.GRAY);


def sDev2 = StDev(data = close(symbol2), length = length);
def MidLineBB2 = MovingAverage(averageType, data = close(symbol2), length = length);
def LowerBand2BB2 = MidLineBB2 + Num_Dev_Dn * sDev2;
def UpperBand2BB2 = MidLineBB2 + Num_Dev_up * sDev2;

def shift2high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol2), close(symbol2), low(symbol2)), length);
def shift2Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol2), close(symbol2), low(symbol2)), length);
def shift2low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol2), close(symbol2), low(symbol2)), length);
def average2 = MovingAverage(averageType, close(symbol2), length);

def Avg2 = average2;

def UpperBand2KCLow = average2 + shift2low;
def LowerBand2KCLow = average2 - shift2low;

def UpperBand2KCMid = average2 + shift2Mid;
def LowerBand2KCMid = average2 - shift2Mid;
def UpperBand2KCHigh = average2 + shift2high;
def LowerBand2KCHigh = average2 - shift2high;

def preSqueeze2 = LowerBand2BB2 > LowerBand2KCLow and UpperBand2BB2 < UpperBand2KCLow;
def originalSqueeze2 = LowerBand2BB2 > LowerBand2KCMid and UpperBand2BB2 < UpperBand2KCMid;
def ExtrSqueeze2 = LowerBand2BB2 > LowerBand2KCHigh and UpperBand2BB2 < UpperBand2KCHigh;

OverBought2.AssignValueColor(if ExtrSqueeze2 then Color.Cyan else if originalSqueeze2 then Color.Magenta else if preSqueeze2 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "IWM", if ExtrSqueeze2 then Color.Cyan else if originalSqueeze2 then Color.Magenta else if preSqueeze2 then Color.DARK_ORANGE else Color.GRAY);


def sDev3 = StDev(data = close(symbol3), length = length);
def MidLineBB3 = MovingAverage(averageType, data = close(symbol3), length = length);
def LowerBand3BB3 = MidLineBB3 + Num_Dev_Dn * sDev3;
def UpperBand3BB3 = MidLineBB3 + Num_Dev_up * sDev3;

def shift3high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol3), close(symbol3), low(symbol3)), length);
def shift3Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol3), close(symbol3), low(symbol3)), length);
def shift3low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol3), close(symbol3), low(symbol3)), length);
def average3 = MovingAverage(averageType, close(symbol3), length);

def Avg3 = average3;

def UpperBand3KCLow = average3 + shift3low;
def LowerBand3KCLow = average3 - shift3low;

def UpperBand3KCMid = average3 + shift3Mid;
def LowerBand3KCMid = average3 - shift3Mid;
def UpperBand3KCHigh = average3 + shift3high;
def LowerBand3KCHigh = average3 - shift3high;

def preSqueeze3 = LowerBand3BB3 > LowerBand3KCLow and UpperBand3BB3 < UpperBand3KCLow;
def originalSqueeze3 = LowerBand3BB3 > LowerBand3KCMid and UpperBand3BB3 < UpperBand3KCMid;
def ExtrSqueeze3 = LowerBand3BB3 > LowerBand3KCHigh and UpperBand3BB3 < UpperBand3KCHigh;

OverBought3.AssignValueColor(if ExtrSqueeze3 then Color.Cyan else if originalSqueeze3 then Color.Magenta else if preSqueeze3 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "XLB", if ExtrSqueeze3 then Color.Cyan else if originalSqueeze3 then Color.Magenta else if preSqueeze3 then Color.DARK_ORANGE else Color.GRAY);


def sDev4 = StDev(data = close(symbol4), length = length);
def MidLineBB4 = MovingAverage(averageType, data = close(symbol4), length = length);
def LowerBand4BB4 = MidLineBB4 + Num_Dev_Dn * sDev4;
def UpperBand4BB4 = MidLineBB4 + Num_Dev_up * sDev4;

def shift4high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol4), close(symbol4), low(symbol4)), length);
def shift4Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol4), close(symbol4), low(symbol4)), length);
def shift4low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol4), close(symbol4), low(symbol4)), length);
def average4 = MovingAverage(averageType, close(symbol4), length);

def Avg4 = average4;

def UpperBand4KCLow = average4 + shift4low;
def LowerBand4KCLow = average4 - shift4low;

def UpperBand4KCMid = average4 + shift4Mid;
def LowerBand4KCMid = average4 - shift4Mid;
def UpperBand4KCHigh = average4 + shift4high;
def LowerBand4KCHigh = average4 - shift4high;

def preSqueeze4 = LowerBand4BB4 > LowerBand4KCLow and UpperBand4BB4 < UpperBand4KCLow;
def originalSqueeze4 = LowerBand4BB4 > LowerBand4KCMid and UpperBand4BB4 < UpperBand4KCMid;
def ExtrSqueeze4 = LowerBand4BB4 > LowerBand4KCHigh and UpperBand4BB4 < UpperBand4KCHigh;

OverBought4.AssignValueColor(if ExtrSqueeze4 then Color.Cyan else if originalSqueeze4 then Color.Magenta else if preSqueeze4 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "XLC", if ExtrSqueeze4 then Color.Cyan else if originalSqueeze4 then Color.Magenta else if preSqueeze4 then Color.DARK_ORANGE else Color.GRAY);


def sDev5 = StDev(data = close(symbol5), length = length);
def MidLineBB5 = MovingAverage(averageType, data = close(symbol5), length = length);
def LowerBand5BB5 = MidLineBB5 + Num_Dev_Dn * sDev5;
def UpperBand5BB5 = MidLineBB5 + Num_Dev_up * sDev5;

def shift5high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol5), close(symbol5), low(symbol5)), length);
def shift5Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol5), close(symbol5), low(symbol5)), length);
def shift5low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol5), close(symbol5), low(symbol5)), length);
def average5 = MovingAverage(averageType, close(symbol5), length);

def Avg5 = average5;

def UpperBand5KCLow = average5 + shift5low;
def LowerBand5KCLow = average5 - shift5low;

def UpperBand5KCMid = average5 + shift5Mid;
def LowerBand5KCMid = average5 - shift5Mid;
def UpperBand5KCHigh = average5 + shift5high;
def LowerBand5KCHigh = average5 - shift5high;

def preSqueeze5 = LowerBand5BB5 > LowerBand5KCLow and UpperBand5BB5 < UpperBand5KCLow;
def originalSqueeze5 = LowerBand5BB5 > LowerBand5KCMid and UpperBand5BB5 < UpperBand5KCMid;
def ExtrSqueeze5 = LowerBand5BB5 > LowerBand5KCHigh and UpperBand5BB5 < UpperBand5KCHigh;

OverBought5.AssignValueColor(if ExtrSqueeze5 then Color.Cyan else if originalSqueeze5 then Color.Magenta else if preSqueeze5 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "XLE", if ExtrSqueeze5 then Color.Cyan else if originalSqueeze5 then Color.Magenta else if preSqueeze5 then Color.DARK_ORANGE else Color.GRAY);


def sDev6 = StDev(data = close(symbol6), length = length);
def MidLineBB6 = MovingAverage(averageType, data = close(symbol6), length = length);
def LowerBand6BB6 = MidLineBB6 + Num_Dev_Dn * sDev6;
def UpperBand6BB6 = MidLineBB6 + Num_Dev_up * sDev6;

def shift6high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol6), close(symbol6), low(symbol6)), length);
def shift6Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol6), close(symbol6), low(symbol6)), length);
def shift6low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol6), close(symbol6), low(symbol6)), length);
def average6 = MovingAverage(averageType, close(symbol6), length);

def Avg6 = average6;

def UpperBand6KCLow = average6 + shift6low;
def LowerBand6KCLow = average6 - shift6low;

def UpperBand6KCMid = average6 + shift6Mid;
def LowerBand6KCMid = average6 - shift6Mid;
def UpperBand6KCHigh = average6 + shift6high;
def LowerBand6KCHigh = average6 - shift6high;

def preSqueeze6 = LowerBand6BB6 > LowerBand6KCLow and UpperBand6BB6 < UpperBand6KCLow;
def originalSqueeze6 = LowerBand6BB6 > LowerBand6KCMid and UpperBand6BB6 < UpperBand6KCMid;
def ExtrSqueeze6 = LowerBand6BB6 > LowerBand6KCHigh and UpperBand6BB6 < UpperBand6KCHigh;

OverBought6.AssignValueColor(if ExtrSqueeze6 then Color.Cyan else if originalSqueeze6 then Color.Magenta else if preSqueeze6 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "XLF", if ExtrSqueeze6 then Color.Cyan else if originalSqueeze6 then Color.Magenta else if preSqueeze6 then Color.DARK_ORANGE else Color.GRAY);

def sDev7 = StDev(data = close(symbol7), length = length);
def MidLineBB7 = MovingAverage(averageType, data = close(symbol7), length = length);
def LowerBand7BB7 = MidLineBB7 + Num_Dev_Dn * sDev7;
def UpperBand7BB7 = MidLineBB7 + Num_Dev_up * sDev7;

def shift7high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol7), close(symbol7), low(symbol7)), length);
def shift7Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol7), close(symbol7), low(symbol7)), length);
def shift7low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol7), close(symbol7), low(symbol7)), length);
def average7 = MovingAverage(averageType, close(symbol7), length);

def Avg7 = average7;

def UpperBand7KCLow = average7 + shift7low;
def LowerBand7KCLow = average7 - shift7low;

def UpperBand7KCMid = average7 + shift7Mid;
def LowerBand7KCMid = average7 - shift7Mid;
def UpperBand7KCHigh = average7 + shift7high;
def LowerBand7KCHigh = average7 - shift7high;

def preSqueeze7 = LowerBand7BB7 > LowerBand7KCLow and UpperBand7BB7 < UpperBand7KCLow;
def originalSqueeze7 = LowerBand7BB7 > LowerBand7KCMid and UpperBand7BB7 < UpperBand7KCMid;
def ExtrSqueeze7 = LowerBand7BB7 > LowerBand7KCHigh and UpperBand7BB7 < UpperBand7KCHigh;

OverBought7.AssignValueColor(if ExtrSqueeze7 then Color.Cyan else if originalSqueeze7 then Color.Magenta else if preSqueeze7 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "XLI", if ExtrSqueeze7 then Color.Cyan else if originalSqueeze7 then Color.Magenta else if preSqueeze7 then Color.DARK_ORANGE else Color.GRAY);

def sDev8 = StDev(data = close(symbol8), length = length);
def MidLineBB8 = MovingAverage(averageType, data = close(symbol8), length = length);
def LowerBand8BB8 = MidLineBB8 + Num_Dev_Dn * sDev8;
def UpperBand8BB8 = MidLineBB8 + Num_Dev_up * sDev8;

def shift8high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol8), close(symbol8), low(symbol8)), length);
def shift8Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol8), close(symbol8), low(symbol8)), length);
def shift8low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol8), close(symbol8), low(symbol8)), length);
def average8 = MovingAverage(averageType, close(symbol8), length);

def Avg8 = average8;

def UpperBand8KCLow = average8 + shift8low;
def LowerBand8KCLow = average8 - shift8low;

def UpperBand8KCMid = average8 + shift8Mid;
def LowerBand8KCMid = average8 - shift8Mid;
def UpperBand8KCHigh = average8 + shift8high;
def LowerBand8KCHigh = average8 - shift8high;

def preSqueeze8 = LowerBand8BB8 > LowerBand8KCLow and UpperBand8BB8 < UpperBand8KCLow;
def originalSqueeze8 = LowerBand8BB8 > LowerBand8KCMid and UpperBand8BB8 < UpperBand8KCMid;
def ExtrSqueeze8 = LowerBand8BB8 > LowerBand8KCHigh and UpperBand8BB8 < UpperBand8KCHigh;

OverBought8.AssignValueColor(if ExtrSqueeze8 then Color.Cyan else if originalSqueeze8 then Color.Magenta else if preSqueeze8 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "XLK", if ExtrSqueeze8 then Color.Cyan else if originalSqueeze8 then Color.Magenta else if preSqueeze8 then Color.DARK_ORANGE else Color.GRAY);

def sDev9 = StDev(data = close(symbol9), length = length);
def MidLineBB9 = MovingAverage(averageType, data = close(symbol9), length = length);
def LowerBand9BB9 = MidLineBB9 + Num_Dev_Dn * sDev9;
def UpperBand9BB9 = MidLineBB9 + Num_Dev_up * sDev9;

def shift9high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol9), close(symbol9), low(symbol9)), length);
def shift9Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol9), close(symbol9), low(symbol9)), length);
def shift9low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol9), close(symbol9), low(symbol9)), length);
def average9 = MovingAverage(averageType, close(symbol9), length);

def Avg9 = average9;

def UpperBand9KCLow = average9 + shift9low;
def LowerBand9KCLow = average9 - shift9low;

def UpperBand9KCMid = average9 + shift9Mid;
def LowerBand9KCMid = average9 - shift9Mid;
def UpperBand9KCHigh = average9 + shift9high;
def LowerBand9KCHigh = average9 - shift9high;

def preSqueeze9 = LowerBand9BB9 > LowerBand9KCLow and UpperBand9BB9 < UpperBand9KCLow;
def originalSqueeze9 = LowerBand9BB9 > LowerBand9KCMid and UpperBand9BB9 < UpperBand9KCMid;
def ExtrSqueeze9 = LowerBand9BB9 > LowerBand9KCHigh and UpperBand9BB9 < UpperBand9KCHigh;

OverBought9.AssignValueColor(if ExtrSqueeze9 then Color.Cyan else if originalSqueeze9 then Color.Magenta else if preSqueeze9 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "XLP", if ExtrSqueeze9 then Color.Cyan else if originalSqueeze9 then Color.Magenta else if preSqueeze9 then Color.DARK_ORANGE else Color.GRAY);


def sDev10 = StDev(data = close(symbol10), length = length);
def MidLineBB10 = MovingAverage(averageType, data = close(symbol10), length = length);
def LowerBand10BB10 = MidLineBB10 + Num_Dev_Dn * sDev10;
def UpperBand10BB10 = MidLineBB10 + Num_Dev_up * sDev10;

def shift10high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol10), close(symbol10), low(symbol10)), length);
def shift10Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol10), close(symbol10), low(symbol10)), length);
def shift10low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol10), close(symbol10), low(symbol10)), length);
def average10 = MovingAverage(averageType, close(symbol10), length);

def Avg10 = average10;

def UpperBand10KCLow = average10 + shift10low;
def LowerBand10KCLow = average10 - shift10low;

def UpperBand10KCMid = average10 + shift10Mid;
def LowerBand10KCMid = average10 - shift10Mid;
def UpperBand10KCHigh = average10 + shift10high;
def LowerBand10KCHigh = average10 - shift10high;

def preSqueeze10 = LowerBand10BB10 > LowerBand10KCLow and UpperBand10BB10 < UpperBand10KCLow;
def originalSqueeze10 = LowerBand10BB10 > LowerBand10KCMid and UpperBand10BB10 < UpperBand10KCMid;
def ExtrSqueeze10 = LowerBand10BB10 > LowerBand10KCHigh and UpperBand10BB10 < UpperBand10KCHigh;

OverBought10.AssignValueColor(if ExtrSqueeze10 then Color.Cyan else if originalSqueeze10 then Color.Magenta else if preSqueeze10 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "XLU", if ExtrSqueeze10 then Color.Cyan else if originalSqueeze10 then Color.Magenta else if preSqueeze10 then Color.DARK_ORANGE else Color.GRAY);

def sDev11 = StDev(data = close(symbol11), length = length);
def MidLineBB11 = MovingAverage(averageType, data = close(symbol11), length = length);
def LowerBand11BB11 = MidLineBB11 + Num_Dev_Dn * sDev11;
def UpperBand11BB11 = MidLineBB11 + Num_Dev_up * sDev11;

def shift11high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol11), close(symbol11), low(symbol11)), length);
def shift11Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol11), close(symbol11), low(symbol11)), length);
def shift11low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol11), close(symbol11), low(symbol11)), length);
def average11 = MovingAverage(averageType, close(symbol11), length);

def Avg11 = average11;

def UpperBand11KCLow = average11 + shift11low;
def LowerBand11KCLow = average11 - shift11low;

def UpperBand11KCMid = average11 + shift11Mid;
def LowerBand11KCMid = average11 - shift11Mid;
def UpperBand11KCHigh = average11 + shift11high;
def LowerBand11KCHigh = average11 - shift11high;

def preSqueeze11 = LowerBand11BB11 > LowerBand11KCLow and UpperBand11BB11 < UpperBand11KCLow;
def originalSqueeze11 = LowerBand11BB11 > LowerBand11KCMid and UpperBand11BB11 < UpperBand11KCMid;
def ExtrSqueeze11 = LowerBand11BB11 > LowerBand11KCHigh and UpperBand11BB11 < UpperBand11KCHigh;

OverBought11.AssignValueColor(if ExtrSqueeze11 then Color.Cyan else if originalSqueeze11 then Color.Magenta else if preSqueeze11 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "XLV", if ExtrSqueeze11 then Color.Cyan else if originalSqueeze11 then Color.Magenta else if preSqueeze11 then Color.DARK_ORANGE else Color.GRAY);


def sDev12 = StDev(data = close(symbol12), length = length);
def MidLineBB12 = MovingAverage(averageType, data = close(symbol12), length = length);
def LowerBand12BB12 = MidLineBB12 + Num_Dev_Dn * sDev12;
def UpperBand12BB12 = MidLineBB12 + Num_Dev_up * sDev12;

def shift12high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol12), close(symbol12), low(symbol12)), length);
def shift12Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol12), close(symbol12), low(symbol12)), length);
def shift12low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol12), close(symbol12), low(symbol12)), length);
def average12 = MovingAverage(averageType, close(symbol12), length);

def Avg12 = average12;

def UpperBand12KCLow = average12 + shift12low;
def LowerBand12KCLow = average12 - shift12low;

def UpperBand12KCMid = average12 + shift12Mid;
def LowerBand12KCMid = average12 - shift12Mid;
def UpperBand12KCHigh = average12 + shift12high;
def LowerBand12KCHigh = average12 - shift12high;

def preSqueeze12 = LowerBand12BB12 > LowerBand12KCLow and UpperBand12BB12 < UpperBand12KCLow;
def originalSqueeze12 = LowerBand12BB12 > LowerBand12KCMid and UpperBand12BB12 < UpperBand12KCMid;
def ExtrSqueeze12 = LowerBand12BB12 > LowerBand12KCHigh and UpperBand12BB12 < UpperBand12KCHigh;

OverBought12.AssignValueColor(if ExtrSqueeze12 then Color.Cyan else if originalSqueeze12 then Color.Magenta else if preSqueeze12 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "XLY", if ExtrSqueeze12 then Color.Cyan else if originalSqueeze12 then Color.Magenta else if preSqueeze12 then Color.DARK_ORANGE else Color.GRAY);

def sDev13 = StDev(data = close(symbol13), length = length);
def MidLineBB13 = MovingAverage(averageType, data = close(symbol13), length = length);
def LowerBand13BB13 = MidLineBB13 + Num_Dev_Dn * sDev13;
def UpperBand13BB13 = MidLineBB13 + Num_Dev_up * sDev13;

def shift13high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol13), close(symbol13), low(symbol13)), length);
def shift13Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol13), close(symbol13), low(symbol13)), length);
def shift13low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol13), close(symbol13), low(symbol13)), length);
def average13 = MovingAverage(averageType, close(symbol13), length);

def Avg13 = average13;

def UpperBand13KCLow = average13 + shift13low;
def LowerBand13KCLow = average13 - shift13low;

def UpperBand13KCMid = average13 + shift13Mid;
def LowerBand13KCMid = average13 - shift13Mid;
def UpperBand13KCHigh = average13 + shift13high;
def LowerBand13KCHigh = average13 - shift13high;

def preSqueeze13 = LowerBand13BB13 > LowerBand13KCLow and UpperBand13BB13 < UpperBand13KCLow;
def originalSqueeze13 = LowerBand13BB13 > LowerBand13KCMid and UpperBand13BB13 < UpperBand13KCMid;
def ExtrSqueeze13 = LowerBand13BB13 > LowerBand13KCHigh and UpperBand13BB13 < UpperBand13KCHigh;

OverBought13.AssignValueColor(if ExtrSqueeze13 then Color.Cyan else if originalSqueeze13 then Color.Magenta else if preSqueeze13 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "XRT", if ExtrSqueeze13 then Color.Cyan else if originalSqueeze13 then Color.Magenta else if preSqueeze13 then Color.DARK_ORANGE else Color.GRAY);

def sDev14 = StDev(data = close(symbol14), length = length);
def MidLineBB14 = MovingAverage(averageType, data = close(symbol14), length = length);
def LowerBand14BB14 = MidLineBB14 + Num_Dev_Dn * sDev14;
def UpperBand14BB14 = MidLineBB14 + Num_Dev_up * sDev14;

def shift14high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol14), close(symbol14), low(symbol14)), length);
def shift14Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol14), close(symbol14), low(symbol14)), length);
def shift14low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol14), close(symbol14), low(symbol14)), length);
def average14 = MovingAverage(averageType, close(symbol14), length);

def Avg14 = average14;

def UpperBand14KCLow = average14 + shift14low;
def LowerBand14KCLow = average14 - shift14low;

def UpperBand14KCMid = average14 + shift14Mid;
def LowerBand14KCMid = average14 - shift14Mid;
def UpperBand14KCHigh = average14 + shift14high;
def LowerBand14KCHigh = average14 - shift14high;

def preSqueeze14 = LowerBand14BB14 > LowerBand14KCLow and UpperBand14BB14 < UpperBand14KCLow;
def originalSqueeze14 = LowerBand14BB14 > LowerBand14KCMid and UpperBand14BB14 < UpperBand14KCMid;
def ExtrSqueeze14 = LowerBand14BB14 > LowerBand14KCHigh and UpperBand14BB14 < UpperBand14KCHigh;

OverBought14.AssignValueColor(if ExtrSqueeze14 then Color.Cyan else if originalSqueeze14 then Color.Magenta else if preSqueeze14 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "XHB", if ExtrSqueeze14 then Color.Cyan else if originalSqueeze14 then Color.Magenta else if preSqueeze14 then Color.DARK_ORANGE else Color.GRAY);

def sDev15 = StDev(data = close(symbol15), length = length);
def MidLineBB15 = MovingAverage(averageType, data = close(symbol15), length = length);
def LowerBand15BB15 = MidLineBB15 + Num_Dev_Dn * sDev15;
def UpperBand15BB15 = MidLineBB15 + Num_Dev_up * sDev15;

def shift15high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol15), close(symbol15), low(symbol15)), length);
def shift15Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol15), close(symbol15), low(symbol15)), length);
def shift15low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol15), close(symbol15), low(symbol15)), length);
def average15 = MovingAverage(averageType, close(symbol15), length);

def Avg15 = average15;

def UpperBand15KCLow = average15 + shift15low;
def LowerBand15KCLow = average15 - shift15low;

def UpperBand15KCMid = average15 + shift15Mid;
def LowerBand15KCMid = average15 - shift15Mid;
def UpperBand15KCHigh = average15 + shift15high;
def LowerBand15KCHigh = average15 - shift15high;

def preSqueeze15 = LowerBand15BB15 > LowerBand15KCLow and UpperBand15BB15 < UpperBand15KCLow;
def originalSqueeze15 = LowerBand15BB15 > LowerBand15KCMid and UpperBand15BB15 < UpperBand15KCMid;
def ExtrSqueeze15 = LowerBand15BB15 > LowerBand15KCHigh and UpperBand15BB15 < UpperBand15KCHigh;

OverBought15.AssignValueColor(if ExtrSqueeze15 then Color.Cyan else if originalSqueeze15 then Color.Magenta else if preSqueeze15 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "IYT", if ExtrSqueeze15 then Color.Cyan else if originalSqueeze15 then Color.Magenta else if preSqueeze15 then Color.DARK_ORANGE else Color.GRAY);

def sDev16 = StDev(data = close(symbol16), length = length);
def MidLineBB16 = MovingAverage(averageType, data = close(symbol16), length = length);
def LowerBand16BB16 = MidLineBB16 + Num_Dev_Dn * sDev16;
def UpperBand16BB16 = MidLineBB16 + Num_Dev_up * sDev16;

def shift16high = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high(symbol16), close(symbol16), low(symbol16)), length);
def shift16Mid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(symbol16), close(symbol16), low(symbol16)), length);
def shift16low = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(symbol16), close(symbol16), low(symbol16)), length);
def average16 = MovingAverage(averageType, close(symbol16), length);

def Avg16 = average16;

def UpperBand16KCLow = average16 + shift16low;
def LowerBand16KCLow = average16 - shift16low;

def UpperBand16KCMid = average16 + shift16Mid;
def LowerBand16KCMid = average16 - shift16Mid;
def UpperBand16KCHigh = average16 + shift16high;
def LowerBand16KCHigh = average16 - shift16high;

def preSqueeze16 = LowerBand16BB16 > LowerBand16KCLow and UpperBand16BB16 < UpperBand16KCLow;
def originalSqueeze16 = LowerBand16BB16 > LowerBand16KCMid and UpperBand16BB16 < UpperBand16KCMid;
def ExtrSqueeze16 = LowerBand16BB16 > LowerBand16KCHigh and UpperBand16BB16 < UpperBand16KCHigh;

OverBought16.AssignValueColor(if ExtrSqueeze16 then Color.Cyan else if originalSqueeze16 then Color.Magenta else if preSqueeze16 then Color.DARK_ORANGE else Color.GRAY);
AddLabel(yes, "VIX", if ExtrSqueeze16 then Color.Cyan else if originalSqueeze16 then Color.Magenta else if preSqueeze16 then Color.DARK_ORANGE else Color.GRAY);
http://tos.mx/IVMGI2Q
 
Can anyone write the squeeze code so the lower indicator will show up to 5 stock/etf and weather they are in a squeeze.
Example: looking at spy (30 minutes) on upper
And on lower it displays xlv, xlk etc…30 minutes and whether they are in a squeeze
see my make shift work around
 

Attachments

  • squeeze.JPG
    squeeze.JPG
    244.8 KB · Views: 137
Last edited:
Last edited:
Can anyone write the squeeze code so the lower indicator will show up to 5 stock/etf and weather they are in a squeeze.
Example: looking at spy (30 minutes) on upper
And on lower it displays xlv, xlk etc…30 minutes and whether they are in a squeeze
see my make shift work around

1, This seems to work during RTHrs for most of the 9 symbols you were using.
2, Since some of these symbols do not trade the same times during non-RTHrs is the reason for the differences between the TTM_Squeeze on these individual charts and this indicator.
3. Used the script function that @halcyonguy posted. The problem that I had originally was that the high, low and close needed to be redefined to handle 'isnan' instances of those by defining h, l and c in their places. Also, found by doing this without the script, that the RTHrs are the only squeeze dots that are reliable.
4. There is an optional bubblemover color coded to the color of the last dot displayed.
5. There is a line10 that keeps all 9 dot lines visible.

Screenshot 2024-03-16 094731.png

Code:
# TTM_Squeeze_Replica_Multi_Symbols
#

declare lower;

input sym1 = "TSLA";
input sym2 = "NVDA";
input sym3 = "GOOGL";
input sym4 = "AMZN";
input sym5 = "META";
input sym6 = "MSFT";
input sym7 = "XLC";
input sym8 = "XLK";
input sym9 = "QQQ";

script s{
input sym    = "TSLA";
input length = 20;
input nBB    = 2.0;
input nK     = 1.5;

########
def h1 = if isnan(high(sym)) then h1[1] else high(sym);
def l1 = if isnan(low(sym)) then l1[1] else low(sym);
def c1 = if isnan(close(sym)) then c1[1] else close(sym);

def sDev1        = StDev(c1, length);
def MidLine1     = Average(c1, length);
def BBUpperBand1 = MidLine1 + nBB * sDev1;

def shift1       = nK * Average(TrueRange(h1, c1,  l1),  length);
def KCUpperBand1 = MidLine1 + shift1;

plot sq1    = BBUpperBand1 < KCUpperBand1;
}
#######

def sq1 = s(sym1);
def sq2 = s(sym2);
def sq3 = s(sym3);
def sq4 = s(sym4);
def sq5 = s(sym5);
def sq6 = s(sym6);
def sq7 = s(sym7);
def sq8 = s(sym8);
def sq9 = s(sym9);

##############################
plot line10 = 10;
line10.setdefaultColor(color.black);
plot line1 = if IsNaN(close) then Double.NaN else 1;
line1.AssignValueColor(if sq1 == 0 then Color.GREEN else if sq1 == 1 then Color.RED else Color.GREEN);
line1.SetPaintingStrategy(PaintingStrategy.POINTS);
plot line2 = if IsNaN(close) then Double.NaN else 2;
line2.AssignValueColor(if sq2 == 0 then Color.GREEN else if sq2 == 1 then Color.RED else Color.GREEN);
line2.SetPaintingStrategy(PaintingStrategy.POINTS);
plot line3 = if IsNaN(close) then Double.NaN else 3;
line3.AssignValueColor(if sq3 == 0 then Color.GREEN else if sq3 == 1 then Color.RED else Color.GREEN);
line3.SetPaintingStrategy(PaintingStrategy.POINTS);
plot line4 = if IsNaN(close) then Double.NaN else 4;
line4.AssignValueColor(if sq4 == 0 then Color.GREEN else if sq4 == 1 then Color.RED else Color.GREEN);
line4.SetPaintingStrategy(PaintingStrategy.POINTS);
plot line5 = if IsNaN(close) then Double.NaN else 5;
line5.AssignValueColor(if sq5 == 0 then Color.GREEN else if sq5 == 1 then Color.RED else Color.GREEN);
line5.SetPaintingStrategy(PaintingStrategy.POINTS);
plot line6 = if IsNaN(close) then Double.NaN else 6;
line6.AssignValueColor(if sq6 == 0 then Color.GREEN else if sq6 == 1 then Color.RED else Color.GREEN);
line6.SetPaintingStrategy(PaintingStrategy.POINTS);
plot line7 = if IsNaN(close) then Double.NaN else 7;
line7.AssignValueColor(if sq7 == 0 then Color.GREEN else if sq7 == 1 then Color.RED else Color.GREEN);
line7.SetPaintingStrategy(PaintingStrategy.POINTS);
plot line8 = if IsNaN(close) then Double.NaN else 8;
line8.AssignValueColor(if sq8 == 0 then Color.GREEN else if sq8 == 1 then Color.RED else Color.GREEN);
line8.SetPaintingStrategy(PaintingStrategy.POINTS);
plot line9 = if IsNaN(close) then Double.NaN else 9;
line9.AssignValueColor(if sq9 == 0 then Color.GREEN else if sq9 == 1 then Color.RED else Color.GREEN);
line9.SetPaintingStrategy(PaintingStrategy.POINTS);

#Bubbles
input showbubbles = yes;
input bubblemover = 4;
def bm  = bubblemover;
def bm1 = bm + 1;
def last = IsNaN(close[bm]) and !IsNaN(close[bm1]);
AddChartBubble(showbubbles and last, line1[bm1], sym1, (if sq1[bm1] == 0 then Color.GREEN else if sq1[bm1] == 1 then Color.RED else Color.YELLOW));
AddChartBubble(showbubbles and last, line2[bm1], sym2, (if sq2[bm1] == 0 then Color.GREEN else if sq2[bm1] == 1 then Color.RED else Color.YELLOW));
AddChartBubble(showbubbles and last, line3[bm1], sym3, (if sq3[bm1] == 0 then Color.GREEN else if sq3[bm1] == 1 then Color.RED else Color.YELLOW));
AddChartBubble(showbubbles and last, line4[bm1], sym4, (if sq4[bm1] == 0 then Color.GREEN else if sq4[bm1] == 1 then Color.RED else Color.YELLOW));
AddChartBubble(showbubbles and last, line5[bm1], sym5, (if sq5[bm1] == 0 then Color.GREEN else if sq5[bm1] == 1 then Color.RED else Color.YELLOW));
AddChartBubble(showbubbles and last, line6[bm1], sym6, (if sq6[bm1] == 0 then Color.GREEN else if sq6[bm1] == 1 then Color.RED else Color.YELLOW));
AddChartBubble(showbubbles and last, line7[bm1], sym7, (if sq7[bm1] == 0 then Color.GREEN else if sq7[bm1] == 1 then Color.RED else Color.YELLOW));
AddChartBubble(showbubbles and last, line8[bm1], sym8, (if sq8[bm1] == 0 then Color.GREEN else if sq8[bm1] == 1 then Color.RED else Color.YELLOW));
AddChartBubble(showbubbles and last, line9[bm1], sym9, (if sq9[bm1] == 0 then Color.GREEN else if sq9[bm1] == 1 then Color.RED else Color.YELLOW));

#
 
Last edited:
I’m trying to see if someone can do a code for me

Looking for the squeeze and then showing squeezes for different company on the chart.
The chart let’s say is SPy then also want to see squeeze for Dis and others can that be done ?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
143 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