What is the displace length and deviation for bb what is that for kc Both are for tos
Displace can be used to play around with moving indicators into the future, or past
Last edited by a moderator:
What is the displace length and deviation for bb what is that for kc Both are for tos
Check out our Buy the Dip indicator and see how it can help you find profitable swing trading ideas. Scanner, watchlist columns, and add-ons are included.
Thank you so much for the in depth response! That makes a lot of sense. It's mainly been the squeeze scan not providing many great results, but you make a very good point about timing. I'll also try changing some filters to see what they give. Thanks againEach indicator-based strategy would be best supported by a scan also based on that indicator. Squeeze scans for squeeze trades, etc. In addition to criteria related to the indicator, you can add volume and open interest filters to the scans. For volume, you probably want to use an average rather than the current period's volume. You can also add requirements for market cap, no earnings report in the next X days and other things that might be useful to reduce results you won't want to trade.
Many traders eventually manually curate a symbol list they scan in and only trade those symbols. I've heard John Carter has such a list. Perhaps you can get access to that if you're in one of his alert subscriptions. Raghee Horner at Simpler prefers stocks that are heavily weighted in the index etfs or sector etfs.
More specifically, for your squeeze scan... If you mean it's not providing many results and the ones it does provide have poor volume and/or open interest then it's one of two things. Either there's more filters besides TTM_Squeeze limiting the scan and maybe some should be removed or not many names worth trading are in a squeeze right now and it's just a timing issue for that particular strategy. If you mean it gives a lot of results but few are worth trading then you'll want to add more filters like I mentioned in the first paragraph to reduce the poor results.
##Used existing code posted by Shooters_Gotta_Shoot with this citation
##Assembled by TheBewb using existing Mobius Squeeze Momentum coding and "squeeze" concept made popular by John Carter.
##Also attempted to use the ST_Darvas code from TOS as inspiration on how to draw the lines, but couldn't figure out how to use the case statements conditionally
##The idea is to draw a box around the highs and lows of the bars inside of a squeeze
#I think there is excess code from the original that can probably be cut
input price = close;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.SIMPLE;
input displace = 0;
def sDev = StDev(data = price[-displace], length = length);
def MidLineBB = MovingAverage(averageType, data = price[-displace], length = length);
def LowerBandBB = MidLineBB + Num_Dev_Dn * sDev;
def UpperBandBB = MidLineBB + Num_Dev_up * sDev;
input factorhigh = 1.0;
input factormid = 1.5;
input factorlow = 2.0;
input trueRangeAverageType = AverageType.SIMPLE;
def shifthigh = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def shiftMid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def shiftlow = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def average = MovingAverage(averageType, price, length);
def Avg = average[-displace];
def UpperBandKCLow = average[-displace] + shiftlow[-displace];
def LowerBandKCLow = average[-displace] - shiftlow[-displace];
def UpperBandKCMid = average[-displace] + shiftMid[-displace];
def LowerBandKCMid = average[-displace] - shiftMid[-displace];
def UpperBandKCHigh = average[-displace] + shifthigh[-displace];
def LowerBandKCHigh = average[-displace] - shifthigh[-displace];
def K = (Highest(high, length) + Lowest(low, length)) /
2 + ExpAverage(close, length);
def momo = Inertia(price - K / 2, length);
def pos = momo >= 0;
def neg = momo < 0;
def up = momo >= momo[1];
def dn = momo < momo[1];
def presqueeze = LowerBandBB > LowerBandKCLow and UpperBandBB < UpperBandKCLow;
def presqueezein = LowerBandBB > LowerBandKCLow and UpperBandBB < UpperBandKCLow and LowerBandBB > LowerBandBB[1];
def presqueezeout = LowerBandBB > LowerBandKCLow and UpperBandBB < UpperBandKCLow and LowerBandBB < LowerBandBB[1];
def originalSqueeze = LowerBandBB > LowerBandKCMid and UpperBandBB < UpperBandKCMid;
def originalSqueezein = LowerBandBB > LowerBandKCMid and UpperBandBB < UpperBandKCMid and LowerBandBB > LowerBandBB[1];
def originalSqueezeout = LowerBandBB > LowerBandKCMid and UpperBandBB < UpperBandKCMid and LowerBandBB < LowerBandBB[1];
def ExtrSqueeze = LowerBandBB > LowerBandKCHigh and UpperBandBB < UpperBandKCHigh;
def ExtrSqueezein = LowerBandBB > LowerBandKCHigh and UpperBandBB < UpperBandKCHigh and LowerBandBB > LowerBandBB[1];
def ExtrSqueezeout = LowerBandBB > LowerBandKCHigh and UpperBandBB < UpperBandKCHigh and LowerBandBB < LowerBandBB[1];
#this checks to see if there is any type of squeeze going on
def squeezeYes = if ExtrSqueezein or ExtrSqueezeout or ExtrSqueeze or originalSqueeze or originalSqueezein or originalSqueezeout or presqueeze or presqueezein or presqueezeout then 1 else 0;
def upper = high;
def lower = low;
def prevLower = CompoundValue(1, lower[1], low);
def prevUpper = CompoundValue(1,high[1], high);
plot highlinestart = if squeezeYes == 1 and squeezeYes[1] == 0 then high else Double.NaN;
plot highlinecont = if squeezeYes == 1 and squeezeYes[1] == 1 and upper >= prevUpper then high else if squeezeYes == 1 and squeezeYes[1] == 1 and upper < prevUpper then prevUpper else double.nan;
plot lowlinestart = if squeezeYes == 1 and squeezeYes[1] == 0 then low else Double.NaN;
plot lowlinecont = if squeezeYes == 1 and squeezeYes[1] == 1 and lower <= prevLower then low else if squeezeYes == 1 and squeezeYes[1] == 1 and lower > prevLower then prevLower else double.nan;
highlinestart.SetPaintingStrategy(PaintingStrategy.Line);
highlinecont.SetPaintingStrategy(PaintingStrategy.Line);
lowlinestart.SetPaintingStrategy(PaintingStrategy.line);
lowlinecont.SetPaintingStrategy(PaintingStrategy.line);
highlinestart.SetDefaultColor(Color.Green);
highlinecont.SetDefaultColor(Color.Green);
lowlinestart.SetDefaultColor(Color.Red);
lowlinecont.SetDefaultColor(Color.Red);
I use this hack to find syntax for TOS indicators: https://usethinkscript.com/threads/reference-syntax-and-indicator-settings-in-thinkorswim.5022/reference DarvasBox()."Upper Band"
They all use the TTM Squeeze with the extended hours off.Hello, are extended hours supposed to be turned on or off for the squeeze? I read somewhere that the results may get skewed in after hours and that's why extended hours trading should not be considered. Wanted to see if anyone has tested this?
Hi, when I add this to watchlist the colors come out right, however there is no "squeeze" text. It shows "preSqueeze" text for both the preSqueeze and squeeze conditions. Not a huge deal but thought others might be curious. I'm admittedly a novice and couldn't figure out how to get the text to show correctly.Here is a watchlist column for those interested: http://tos.mx/c6kSvbk
Code:input price = close; input length = 20; input Num_Dev_Dn = -2.0; input Num_Dev_up = 2.0; input averageType = AverageType.SIMPLE; input displace = 0; def sDev = StDev(data = price[-displace], length = length); def MidLineBB = MovingAverage(averageType, data = price[-displace], length = length); def LowerBandBB = MidLineBB + Num_Dev_Dn * sDev; def UpperBandBB = MidLineBB + Num_Dev_up * sDev; input factorhigh = 1.0; input factormid = 1.5; input factorlow = 2.0; input trueRangeAverageType = AverageType.SIMPLE; def shifthigh = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length); def shiftMid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length); def shiftlow = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length); def average = MovingAverage(averageType, price, length); def Avg = average[-displace]; def UpperBandKCLow = average[-displace] + shiftlow[-displace]; def LowerBandKCLow = average[-displace] - shiftlow[-displace]; def UpperBandKCMid = average[-displace] + shiftMid[-displace]; def LowerBandKCMid = average[-displace] - shiftMid[-displace]; def UpperBandKCHigh = average[-displace] + shifthigh[-displace]; def LowerBandKCHigh = average[-displace] - shifthigh[-displace]; def K = (Highest(high, length) + Lowest(low, length)) / 2 + ExpAverage(close, length); def momo = Inertia(price - K / 2, length); def pos = momo>= 0; def neg = momo< 0; def up = momo >= momo[1]; def dn = momo < momo[1]; def presqueeze = LowerBandBB > LowerBandKCLow and UpperBandBB < UpperBandKCLow; def originalSqueeze = LowerBandBB > LowerBandKCMid and UpperBandBB < UpperBandKCMid; def ExtrSqueeze = LowerBandBB > LowerBandKCHigh and UpperBandBB < UpperBandKCHigh; addlabel(yes, if extrSqueeze then "extraSqueeze" else if presqueeze then "preSqueeze" else if originalSqueeze then "squeeze" else if preSqueeze then "preSqueeze" else "noSqueeze"); assignBackgroundColor(if ExtrSqueeze then Color.red else if originalSqueeze then Color.blue else if presqueeze then color.white else Color.gray);
I figured it out, there was just a little redundancy in the original code. This will display the labels correctly:Hi, when I add this to watchlist the colors come out right, however there is no "squeeze" text. It shows "preSqueeze" text for both the preSqueeze and squeeze conditions. Not a huge deal but thought others might be curious. I'm admittedly a novice and couldn't figure out how to get the text to show correctly.
addlabel(yes, if extrSqueeze then "extraSqueeze" else if originalSqueeze then "squeeze" else if presqueeze then "preSqueeze" else "noSqueeze");
Declare Lower;
input period1 = 8;
Input period2 = 21;
input period3 = 34;
input period4 = 55;
input period5 = 89;
input period6 = 144;
input period7 = 233;
input period8 = 377;
Input Dotsize = 3;
input APC = 0;
Def price = (Open + Close)/2;
def a1A = exp(-1.414 * 3.14159 / Period1);
def b1A = 2 * a1A * Cos(1.414 * 3.14159 / Period1);
def coef2A = b1A;
def coef3A = -a1A * a1A;
def coef1A = (1 – b1A + a1A * a1A) / 4;
rec ButterA = if barNumber() < 3 then Price else coef1A * (Price + 2 * Price[1] + Price[2]) + coef2A * ButterA[1] + coef3A * ButterA[2];
def a1B = exp(-1.414 * 3.14159 / Period2);
def b1B = 2 * a1B * Cos(1.414 * 3.14159 / Period2);
def coef2B = b1B;
def coef3B = -a1B * a1B;
def coef1B = (1 – b1B + a1B * a1B) / 4;
rec ButterB = if barNumber() < 3 then Price else coef1B * (Price + 2 * Price[1] + Price[2]) + coef2B * ButterB[1] + coef3B * ButterB[2];
def a1C = exp(-1.414 * 3.14159 / Period3);
def b1C = 2 * a1C * Cos(1.414 * 3.14159 / Period3);
def coef2C = b1C;
def coef3C = -a1C * a1C;
def coef1C = (1 – b1C + a1C * a1C) / 4;
rec ButterC = if barNumber() < 3 then Price else coef1C * (Price + 2 * Price[1] + Price[2]) + coef2C * ButterC[1] + coef3C * ButterC[2];
def a1D = exp(-1.414 * 3.14159 / Period4);
def b1D = 2 * a1D * Cos(1.414 * 3.14159 / Period4);
def coef2D = b1D;
def coef3D = -a1D * a1D;
def coef1D = (1 – b1D + a1D * a1D) / 4;
rec ButterD= if barNumber() < 3 then Price else coef1D * (Price + 2 * Price[1] + Price[2]) + coef2D * ButterD[1] + coef3D * ButterD[2];
def a1E = exp(-1.414 * 3.14159 / Period5);
def b1E = 2 * a1E * Cos(1.414 * 3.14159 / Period5);
def coef2E =b1E;
def coef3E = -a1E * a1E;
def coef1E = (1 – b1E + a1E * a1E) / 4;
rec ButterE = if barNumber() < 3 then Price else coef1E * (Price + 2 * Price[1] + Price[2]) + coef2E * ButterE[1] + coef3E * ButterE[2];
def a1F = exp(-1.414 * 3.14159 / Period6);
def b1F = 2 * a1F * Cos(1.414 * 3.14159 / Period6);
def coef2F = b1F;
def coef3F = -a1F * a1F;
def coef1F = (1 – b1F + a1F * a1F) / 4;
rec ButterF = if barNumber() < 3 then Price else coef1F * (Price + 2 * Price[1] + Price[2]) + coef2F * ButterF[1] + coef3F * ButterF[2];
def a1G = exp(-1.414 * 3.14159 / Period7);
def b1G = 2 * a1G * Cos(1.414 * 3.14159 / Period7);
def coef2G = b1G;
def coef3G = -a1G * a1G;
def coef1G = (1 – b1G + a1G * a1G) / 4;
rec ButterG = if barNumber() < 3 then Price else coef1G * (Price + 2 * Price[1] + Price[2]) + coef2G * ButterG[1] + coef3G * ButterG[2];
def a1H = exp(-1.414 * 3.14159 / Period8);
def b1H = 2 * a1H * Cos(1.414 * 3.14159 / Period8);
def coef2H = b1H;
def coef3H = -a1H * a1H;
def coef1H = (1 – b1H + a1H * a1H) / 4;
rec ButterH = if barNumber() < 3 then Price else coef1H * (Price + 2 * Price[1] + Price[2]) + coef2H * ButterH[1] + coef3H * ButterH[2];
def Os1 = ButterA – ButterB;
def Os2 = ButterA – ButterC;
def Os3 = ButterA – ButterD;
def Os4 = ButterA – ButterE;
def Os5 = ButterA – ButterF;
def Os6 = ButterA – ButterG;
def Os7 = ButterA – ButterH;
def a1I = exp(-1.414 * 3.14159 / Period2);
def b1I = 2 * a1I * Cos(1.414 * 3.14159 / Period2);
def coef2I = b1I;
def coef3I = -a1I * a1I;
def coef1I = (1 – b1I + a1I * a1I) / 4;
rec ButterI = if barNumber() < 3 then Os1 else coef1I * (Os1 + 2 * Os1[1] + Os1[2]) + coef2I * ButterI[1] + coef3I * ButterI[2];
def a1J = exp(-1.414 * 3.14159 / Period3);
def b1J = 2 * a1J * Cos(1.414 * 3.14159 / Period3);
def coef2J = b1J;
def coef3J = -a1J * a1J;
def coef1J = (1 – b1J + a1J * a1J) / 4;
rec ButterJ = if barNumber() < 3 then Os2 else coef1J * (Os2 + 2 * Os2[1] + Os2[2]) + coef2J * ButterJ[1] + coef3J * ButterJ[2];
def a1K = exp(-1.414 * 3.14159 / Period4);
def b1K = 2 * a1K * Cos(1.414 * 3.14159 / Period4);
def coef2K = b1K;
def coef3K = -a1K * a1K;
def coef1K = (1 – b1K + a1K * a1K) / 4;
rec ButterK = if barNumber() < 3 then Os3 else coef1K * (Os3 + 2 * Os3[1] + Os3[2]) + coef2K * ButterK[1] + coef3K * ButterK[2];
def a1L = exp(-1.414 * 3.14159 / Period5);
def b1L = 2 * a1L * Cos(1.414 * 3.14159 / Period5);
def coef2L = b1L;
def coef3L = -a1L * a1L;
def coef1L = (1 – b1L + a1L * a1L) / 4;
rec ButterL = if barNumber() < 3 then Os4 else coef1L * (Os4 + 2 * Os4[1] + Os4[2]) + coef2L * ButterL[1] + coef3L * ButterL[2];
def a1M = exp(-1.414 * 3.14159 / Period6);
def b1M = 2 * a1M * Cos(1.414 * 3.14159 / Period6);
def coef2M = b1M;
def coef3M = -a1M * a1M;
def coef1M = (1 – b1M + a1M * a1M) / 4;
rec ButterM = if barNumber() < 3 then Os5 else coef1M * (Os5 + 2 * Os5[1] + Os5[2]) + coef2M * ButterM[1] + coef3M * ButterM[2];
def a1N = exp(-1.414 * 3.14159 / Period7);
def b1N = 2 * a1N * Cos(1.414 * 3.14159 / Period7);
def coef2N = b1N;
def coef3N = -a1N * a1N;
def coef1N = (1 – b1N + a1N * a1N) / 4;
rec ButterN = if barNumber() < 3 then Os6 else coef1N * (Os6 + 2 * Os6[1] + Os6[2]) + coef2N * ButterN[1] + coef3N * ButterN[2];
def a1O = exp(-1.414 * 3.14159 / Period8);
def b1O = 2 * a1O * Cos(1.414 * 3.14159 / Period8);
def coef2O = b1O;
def coef3O = -a1O * a1O;
def coef1O = (1 – b1O + a1O * a1O) / 4;
rec ButterO = if barNumber() < 3 then Os7 else coef1O * (Os7 + 2 * Os7[1] + Os7[2]) + coef2O * ButterO[1] + coef3O * ButterO[2];
Def Hist1 = OS1 – ButterI;
Def Hist2 = OS2 – ButterJ;
Def Hist3 = OS3 – ButterK;
Def Hist4 = OS4 – ButterL;
Def Hist5 = OS5 – ButterM;
Def Hist6 = OS6 – ButterN;
Def Hist7 = OS7 – ButterO;
Def H1BullRise = Hist1 >= 0 and Hist1 >= Hist1[1] ;
Def H2BullRise = Hist2 >= 0 and Hist2 >= Hist2[1] ;
Def H3BullRise = Hist3 >= 0 and Hist3 >= Hist3[1] ;
Def H4BullRise = Hist4 >= 0 and Hist4 >= Hist4[1] ;
Def H5BullRise = Hist5 >= 0 and Hist5 >= Hist5[1] ;
Def H6BullRise = Hist6 >= 0 and Hist6 >= Hist6[1] ;
Def H7BullRise = Hist7 >= 0 and Hist7 >= Hist7[1] ;
Def H1BullFall = Hist1 >= 0 and Hist1 < Hist1[1] ;
Def H2BullFall = Hist2 >= 0 and Hist2 < Hist2[1] ;
Def H3BullFall = Hist3 >= 0 and Hist3 < Hist3[1] ;
Def H4BullFall = Hist4 >= 0 and Hist4 < Hist4[1] ;
Def H5BullFall = Hist5 >= 0 and Hist5 < Hist5[1] ;
Def H6BullFall = Hist6 >= 0 and Hist6 < Hist6[1] ;
Def H7BullFall = Hist7 >= 0 and Hist7 < Hist7[1] ;
Def H1BearRise = Hist1 < 0 and Hist1 >= Hist1[1] ;
Def H2BearRise = Hist2 < 0 and Hist2 >= Hist2[1] ;
Def H3BearRise = Hist3 < 0 and Hist3 >= Hist3[1] ;
Def H4BearRise = Hist4 < 0 and Hist4 >= Hist4[1] ;
Def H5BearRise = Hist5 < 0 and Hist5 >= Hist5[1] ;
Def H6BearRise = Hist6 < 0 and Hist6 >= Hist6[1] ;
Def H7BearRise = Hist7 < 0 and Hist7 >= Hist7[1] ;
Def H1BearFall = Hist1 < 0 and Hist1 < Hist1[1] ;
Def H2BearFall = Hist2 < 0 and Hist2 < Hist2[1] ;
Def H3BearFall = Hist3 < 0 and Hist3 < Hist3[1] ;
Def H4BearFall = Hist4 < 0 and Hist4 < Hist4[1] ;
Def H5BearFall = Hist5 < 0 and Hist5 < Hist5[1] ;
Def H6BearFall = Hist6 < 0 and Hist6 < Hist6[1] ;
Def H7BearFall = Hist7 < 0 and Hist7 < Hist7[1] ;
Plot Dot1 = if IsNaN(close) then Double.NaN else 1;
Dot1.SetPaintingStrategy(PaintingStrategy.Squares);
Dot1.SetLineWeight(DotSize);
Dot1.DefineColor("Up", Color.Green);
Dot1.DefineColor("UpDecreasing", Color.Dark_Green);
Dot1.DefineColor("Down", Color.Dark_Red);
Dot1.DefineColor("DownDecreasing", Color.Red);
Dot1.AssignValueColor(
if H1BullRise == 1 then Dot1.Color("Up")
else if H1BullFall == 1 then Dot1.Color("UpDecreasing")
else if H1BearRise == 1 then Dot1.Color(“DownDecreasing”)
else Dot1.Color("Down") );
Plot Dot2 = if IsNaN(close) then Double.NaN else 2;
Dot2.SetPaintingStrategy(PaintingStrategy.Points);
Dot2.SetLineWeight(DotSize);
Dot2.DefineColor("Up", Color.Green);
Dot2.DefineColor("UpDecreasing", Color.Dark_Green);
Dot2.DefineColor("Down", Color.Dark_Red);
Dot2.DefineColor("DownDecreasing", Color.Red);
Dot2.AssignValueColor(
if H2BullRise == 1 then Dot2.Color("Up")
else if H2BullFall == 1 then Dot2.Color("UpDecreasing")
else if H2BearRise == 1 then Dot2.Color(“DownDecreasing”)
else Dot2.Color("Down"));
Plot Dot3 = if IsNaN(close) then Double.NaN else 3;
Dot3.SetPaintingStrategy(PaintingStrategy.Squares);
Dot3.SetLineWeight(DotSize);
Dot3.DefineColor("Up", Color.Green);
Dot3.DefineColor("UpDecreasing", Color.Dark_Green);
Dot3.DefineColor("Down", Color.Dark_Red);
Dot3.DefineColor("DownDecreasing", Color.Red);
Dot3.AssignValueColor(
if H3BullRise == 1 then Dot3.Color("Up")
else if H3BullFall == 1 then Dot3.Color("UpDecreasing")
else if H3BearRise == 1 then Dot3.Color(“DownDecreasing”)
else Dot3.Color("Down"));
Plot Dot4 = if IsNaN(close) then Double.NaN else 4;
Dot4.SetPaintingStrategy(PaintingStrategy.Points);
Dot4.SetLineWeight(DotSize);
Dot4.DefineColor("Up", Color.Green);
Dot4.DefineColor("UpDecreasing", Color.Dark_Green);
Dot4.DefineColor("Down", Color.Dark_Red);
Dot4.DefineColor("DownDecreasing", Color.Red);
Dot4.AssignValueColor(
if H4BullRise == 1 then Dot4.Color("Up")
else if H4BullFall == 1 then Dot4.Color("UpDecreasing")
else if H4BearRise == 1 then Dot4.Color(“DownDecreasing”)
else Dot4.Color("Down"));
Plot Dot5 = if IsNaN(close) then Double.NaN else 5;
Dot5.SetPaintingStrategy(PaintingStrategy.Squares);
Dot5.SetLineWeight(DotSize);
Dot5.DefineColor("Up", Color.Green);
Dot5.DefineColor("UpDecreasing", Color.Dark_Green);
Dot5.DefineColor("Down", Color.Dark_Red);
Dot5.DefineColor("DownDecreasing", Color.Red);
Dot5.AssignValueColor(
if H5BullRise == 1 then Dot5.Color("Up")
else if H5BullFall == 1 then Dot5.Color("UpDecreasing")
else if H5BearRise == 1 then Dot5.Color(“DownDecreasing”)
else Dot5.Color("Down"));
Plot Dot6 = if IsNaN(close) then Double.NaN else 6;
Dot6.SetPaintingStrategy(PaintingStrategy.Points);
Dot6.SetLineWeight(DotSize);
Dot6.DefineColor("Up", Color.Green);
Dot6.DefineColor("UpDecreasing", Color.Dark_Green);
Dot6.DefineColor("Down", Color.Dark_Red);
Dot6.DefineColor("DownDecreasing", Color.Red);
Dot6.AssignValueColor(
if H6BullRise == 1 then Dot6.Color("Up")
else if H6BullFall == 1 then Dot6.Color("UpDecreasing")
else if H6BearRise == 1 then Dot6.Color(“DownDecreasing”)
else Dot6.Color("Down"));
Plot Dot7 = if IsNaN(close) then Double.NaN else 7;
Dot7.SetPaintingStrategy(PaintingStrategy.Squares);
Dot7.SetLineWeight(DotSize);
Dot7.DefineColor("Up", Color.Green);
Dot7.DefineColor("UpDecreasing", Color.Dark_Green);
Dot7.DefineColor("Down", Color.Dark_Red);
Dot7.DefineColor("DownDecreasing", Color.Red);
Dot7.AssignValueColor(
if H7BullRise == 1 then Dot7.Color("Up")
else if H7BullFall == 1 then Dot7.Color("UpDecreasing")
else if H7BearRise == 1 then Dot7.Color(“DownDecreasing”)
else Dot7.Color("Down"));
input Aprice = close;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.SIMPLE;
input displace = 0;
def sDev = StDev(data = Aprice[-displace], length = length);
def MidLineBB = MovingAverage(averageType, data = Aprice[-displace], length = length);
def LowerBandBB = MidLineBB + Num_Dev_Dn * sDev;
def UpperBandBB = MidLineBB + Num_Dev_up * sDev;
input factorhigh = 1.0;
input factormid = 1.5;
input factorlow = 2.0;
input trueRangeAverageType = AverageType.SIMPLE;
def shifthigh = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def shiftMid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def shiftlow = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def average = MovingAverage(averageType, Aprice, length);
def Avg = average[-displace];
def UpperBandKCLow = average[-displace] + shiftlow[-displace];
def LowerBandKCLow = average[-displace] - shiftlow[-displace];
def UpperBandKCMid = average[-displace] + shiftMid[-displace];
def LowerBandKCMid = average[-displace] - shiftMid[-displace];
def UpperBandKCHigh = average[-displace] + shifthigh[-displace];
def LowerBandKCHigh = average[-displace] - shifthigh[-displace];
def K = (Highest(high, length) + Lowest(low, length)) /
2 + ExpAverage(close, length);
def momo = Inertia(Aprice - K / 2, length);
def pos = momo>= 0;
def neg = momo< 0;
def up = momo >= momo[1];
def dn = momo < momo[1];
def presqueeze = LowerBandBB > LowerBandKCLow and UpperBandBB < UpperBandKCLow;
def originalSqueeze = LowerBandBB > LowerBandKCMid and UpperBandBB < UpperBandKCMid;
def ExtrSqueeze = LowerBandBB > LowerBandKCHigh and UpperBandBB < UpperBandKCHigh;
def PosUp = pos and up;
def PosDn = pos and dn;
def NegDn = neg and dn;
def NegUp = neg and up;
plot squeezeline = if IsNaN(close) then Double.NaN else 9;
squeezeline.SetPaintingStrategy(PaintingStrategy.POINTS);
squeezeline.AssignValueColor(if ExtrSqueeze then Color.RED else if originalSqueeze then Color.YELLOW else if presqueeze then Color.DARK_ORANGE else Color.GRAY);
squeezeline.SetLineWeight(Dotsize+1);
plot momentum = if IsNaN(close) then Double.NaN else 10;
momentum.SetPaintingStrategy(PaintingStrategy.Squares);
momentum.AssignValueColor( if PosUp then Color.green else if PosDn then Color.dark_green else if NegDn then Color.dark_orange else if NegUp then Color.yellow else Color.YELLOW);
Momentum.SetLineWeight(Dotsize);
AssignPriceColor( if APC == 1 and H1BullRise == 1 then Dot1.Color("Up")
else if APC == 1 and H1BullFall == 1 then Dot1.Color("UpDecreasing")
else if APC == 1 and H1BearFall == 1 then Dot1.Color(“DownDecreasing”)
else if APC == 1 and H1BearRise == 1 then Dot1.Color("Down")
else if APC == 2 and H2BullRise == 1 then Dot2.Color("Up")
else if APC == 2 and H2BullFall == 1 then Dot2.Color("UpDecreasing")
else if APC == 2 and H2BearFall == 1 then Dot2.Color(“DownDecreasing”)
else if APC == 2 and H2BearRise == 1 then Dot2.Color("Down")
else if APC == 3 and H3BullRise == 1 then Dot3.Color("Up")
else if APC == 3 and H3BullFall == 1 then Dot3.Color("UpDecreasing")
else if APC == 3 and H3BearFall == 1 then Dot3.Color(“DownDecreasing”)
else if APC == 3 and H3BearRise == 1 then Dot3.Color("Down")
else if APC == 4 and H4BullRise == 1 then Dot4.Color("Up")
else if APC == 4 and H4BullFall == 1 then Dot4.Color("UpDecreasing")
else if APC == 4 and H4BearFall == 1 then Dot4.Color(“DownDecreasing”)
else if APC == 4 and H4BearRise == 1 then Dot4.Color("Down")
else if APC == 5 and H5BullRise == 1 then Dot5.Color("Up")
else if APC == 5 and H5BullFall == 1 then Dot5.Color("UpDecreasing")
else if APC == 5 and H5BearFall == 1 then Dot5.Color(“DownDecreasing”)
else if APC == 5 and H5BearRise == 1 then Dot5.Color("Down")
else if APC == 6 and H6BullRise == 1 then Dot6.Color("Up")
else if APC == 6 and H6BullFall == 1 then Dot6.Color("UpDecreasing")
else if APC == 6 and H6BearFall == 1 then Dot6.Color(“DownDecreasing”)
else if APC == 6 and H6BearRise == 1 then Dot6.Color("Down")
else if APC == 7 and H7BullRise == 1 then Dot7.Color("Up")
else if APC == 7 and H7BullFall == 1 then Dot7.Color("UpDecreasing")
else if APC == 7 and H7BearFall == 1 then Dot7.Color(“DownDecreasing”)
else if APC == 7 and H7BearRise == 1 then Dot7.Color("Down")
else if APC == 9 and ExtrSqueeze then Color.RED
else if APC == 9 and originalSqueeze then Color.YELLOW
else if APC == 9 and presqueeze then Color.DARK_ORANGE
else If APC == 9 then Color.GRAY
Else if APC == 10 and PosUp then Color.green
else if APC == 10 and PosDn then Color.dark_green
else if APC == 10 and NegDn then Color.dark_orange
else if APC == 10 and NegUp then Color.yellow else Color.Current);
Looking at the code at the beginning of this thread, it assumes both Bollinger Bands are inside the the Keltner channel to be in a squeeze. Other studies we've looked at (e.g. TradingView,...), use the assumption that "one or both" Bollinger Bands need to be in the respective Keltner channel to be deemed a squeeze. The above algorithm is more restrictive, while the latter assumption will find more squeezes. (Looking at one of John Carter's videos, he seems to make the above assumption.) Is it wrong to make the "one or both" Bollinger Band approach? Thanks in advance
def presqueeze = LowerBandBB > LowerBandKCLow and UpperBandBB < UpperBandKCLow;
def originalSqueeze = LowerBandBB > LowerBandKCMid and UpperBandBB < UpperBandKCMid;
def ExtrSqueeze = LowerBandBB > LowerBandKCHigh and UpperBandBB < UpperBandKCHigh;
Dnyoi re
Do you mind sharing the updated code. Keep getting an error not sure why when adding those other few lines
Declare Lower;
input period1 = 8;
Input period2 = 21;
input period3 = 34;
input period4 = 55;
input period5 = 89;
input period6 = 144;
input period7 = 233;
input period8 = 377;
Input Dotsize = 3;
input APC = 0;
Def price = (Open + Close)/2;
def a1A = exp(-1.414 * 3.14159 / Period1);
def b1A = 2 * a1A * Cos(1.414 * 3.14159 / Period1);
def coef2A = b1A;
def coef3A = -a1A * a1A;
def coef1A = (1 – b1A + a1A * a1A) / 4;
rec ButterA = if barNumber() < 3 then Price else coef1A * (Price + 2 * Price[1] + Price[2]) + coef2A * ButterA[1] + coef3A * ButterA[2];
def a1B = exp(-1.414 * 3.14159 / Period2);
def b1B = 2 * a1B * Cos(1.414 * 3.14159 / Period2);
def coef2B = b1B;
def coef3B = -a1B * a1B;
def coef1B = (1 – b1B + a1B * a1B) / 4;
rec ButterB = if barNumber() < 3 then Price else coef1B * (Price + 2 * Price[1] + Price[2]) + coef2B * ButterB[1] + coef3B * ButterB[2];
def a1C = exp(-1.414 * 3.14159 / Period3);
def b1C = 2 * a1C * Cos(1.414 * 3.14159 / Period3);
def coef2C = b1C;
def coef3C = -a1C * a1C;
def coef1C = (1 – b1C + a1C * a1C) / 4;
rec ButterC = if barNumber() < 3 then Price else coef1C * (Price + 2 * Price[1] + Price[2]) + coef2C * ButterC[1] + coef3C * ButterC[2];
def a1D = exp(-1.414 * 3.14159 / Period4);
def b1D = 2 * a1D * Cos(1.414 * 3.14159 / Period4);
def coef2D = b1D;
def coef3D = -a1D * a1D;
def coef1D = (1 – b1D + a1D * a1D) / 4;
rec ButterD= if barNumber() < 3 then Price else coef1D * (Price + 2 * Price[1] + Price[2]) + coef2D * ButterD[1] + coef3D * ButterD[2];
def a1E = exp(-1.414 * 3.14159 / Period5);
def b1E = 2 * a1E * Cos(1.414 * 3.14159 / Period5);
def coef2E =b1E;
def coef3E = -a1E * a1E;
def coef1E = (1 – b1E + a1E * a1E) / 4;
rec ButterE = if barNumber() < 3 then Price else coef1E * (Price + 2 * Price[1] + Price[2]) + coef2E * ButterE[1] + coef3E * ButterE[2];
def a1F = exp(-1.414 * 3.14159 / Period6);
def b1F = 2 * a1F * Cos(1.414 * 3.14159 / Period6);
def coef2F = b1F;
def coef3F = -a1F * a1F;
def coef1F = (1 – b1F + a1F * a1F) / 4;
rec ButterF = if barNumber() < 3 then Price else coef1F * (Price + 2 * Price[1] + Price[2]) + coef2F * ButterF[1] + coef3F * ButterF[2];
def a1G = exp(-1.414 * 3.14159 / Period7);
def b1G = 2 * a1G * Cos(1.414 * 3.14159 / Period7);
def coef2G = b1G;
def coef3G = -a1G * a1G;
def coef1G = (1 – b1G + a1G * a1G) / 4;
rec ButterG = if barNumber() < 3 then Price else coef1G * (Price + 2 * Price[1] + Price[2]) + coef2G * ButterG[1] + coef3G * ButterG[2];
def a1H = exp(-1.414 * 3.14159 / Period8);
def b1H = 2 * a1H * Cos(1.414 * 3.14159 / Period8);
def coef2H = b1H;
def coef3H = -a1H * a1H;
def coef1H = (1 – b1H + a1H * a1H) / 4;
rec ButterH = if barNumber() < 3 then Price else coef1H * (Price + 2 * Price[1] + Price[2]) + coef2H * ButterH[1] + coef3H * ButterH[2];
def Os1 = ButterA – ButterB;
def Os2 = ButterA – ButterC;
def Os3 = ButterA – ButterD;
def Os4 = ButterA – ButterE;
def Os5 = ButterA – ButterF;
def Os6 = ButterA – ButterG;
def Os7 = ButterA – ButterH;
def a1I = exp(-1.414 * 3.14159 / Period2);
def b1I = 2 * a1I * Cos(1.414 * 3.14159 / Period2);
def coef2I = b1I;
def coef3I = -a1I * a1I;
def coef1I = (1 – b1I + a1I * a1I) / 4;
rec ButterI = if barNumber() < 3 then Os1 else coef1I * (Os1 + 2 * Os1[1] + Os1[2]) + coef2I * ButterI[1] + coef3I * ButterI[2];
def a1J = exp(-1.414 * 3.14159 / Period3);
def b1J = 2 * a1J * Cos(1.414 * 3.14159 / Period3);
def coef2J = b1J;
def coef3J = -a1J * a1J;
def coef1J = (1 – b1J + a1J * a1J) / 4;
rec ButterJ = if barNumber() < 3 then Os2 else coef1J * (Os2 + 2 * Os2[1] + Os2[2]) + coef2J * ButterJ[1] + coef3J * ButterJ[2];
def a1K = exp(-1.414 * 3.14159 / Period4);
def b1K = 2 * a1K * Cos(1.414 * 3.14159 / Period4);
def coef2K = b1K;
def coef3K = -a1K * a1K;
def coef1K = (1 – b1K + a1K * a1K) / 4;
rec ButterK = if barNumber() < 3 then Os3 else coef1K * (Os3 + 2 * Os3[1] + Os3[2]) + coef2K * ButterK[1] + coef3K * ButterK[2];
def a1L = exp(-1.414 * 3.14159 / Period5);
def b1L = 2 * a1L * Cos(1.414 * 3.14159 / Period5);
def coef2L = b1L;
def coef3L = -a1L * a1L;
def coef1L = (1 – b1L + a1L * a1L) / 4;
rec ButterL = if barNumber() < 3 then Os4 else coef1L * (Os4 + 2 * Os4[1] + Os4[2]) + coef2L * ButterL[1] + coef3L * ButterL[2];
def a1M = exp(-1.414 * 3.14159 / Period6);
def b1M = 2 * a1M * Cos(1.414 * 3.14159 / Period6);
def coef2M = b1M;
def coef3M = -a1M * a1M;
def coef1M = (1 – b1M + a1M * a1M) / 4;
rec ButterM = if barNumber() < 3 then Os5 else coef1M * (Os5 + 2 * Os5[1] + Os5[2]) + coef2M * ButterM[1] + coef3M * ButterM[2];
def a1N = exp(-1.414 * 3.14159 / Period7);
def b1N = 2 * a1N * Cos(1.414 * 3.14159 / Period7);
def coef2N = b1N;
def coef3N = -a1N * a1N;
def coef1N = (1 – b1N + a1N * a1N) / 4;
rec ButterN = if barNumber() < 3 then Os6 else coef1N * (Os6 + 2 * Os6[1] + Os6[2]) + coef2N * ButterN[1] + coef3N * ButterN[2];
def a1O = exp(-1.414 * 3.14159 / Period8);
def b1O = 2 * a1O * Cos(1.414 * 3.14159 / Period8);
def coef2O = b1O;
def coef3O = -a1O * a1O;
def coef1O = (1 – b1O + a1O * a1O) / 4;
rec ButterO = if barNumber() < 3 then Os7 else coef1O * (Os7 + 2 * Os7[1] + Os7[2]) + coef2O * ButterO[1] + coef3O * ButterO[2];
Def Hist1 = OS1 – ButterI;
Def Hist2 = OS2 – ButterJ;
Def Hist3 = OS3 – ButterK;
Def Hist4 = OS4 – ButterL;
Def Hist5 = OS5 – ButterM;
Def Hist6 = OS6 – ButterN;
Def Hist7 = OS7 – ButterO;
Def H1BullRise = Hist1 >= 0 and Hist1 >= Hist1[1] ;
Def H2BullRise = Hist2 >= 0 and Hist2 >= Hist2[1] ;
Def H3BullRise = Hist3 >= 0 and Hist3 >= Hist3[1] ;
Def H4BullRise = Hist4 >= 0 and Hist4 >= Hist4[1] ;
Def H5BullRise = Hist5 >= 0 and Hist5 >= Hist5[1] ;
Def H6BullRise = Hist6 >= 0 and Hist6 >= Hist6[1] ;
Def H7BullRise = Hist7 >= 0 and Hist7 >= Hist7[1] ;
Def H1BullFall = Hist1 >= 0 and Hist1 < Hist1[1] ;
Def H2BullFall = Hist2 >= 0 and Hist2 < Hist2[1] ;
Def H3BullFall = Hist3 >= 0 and Hist3 < Hist3[1] ;
Def H4BullFall = Hist4 >= 0 and Hist4 < Hist4[1] ;
Def H5BullFall = Hist5 >= 0 and Hist5 < Hist5[1] ;
Def H6BullFall = Hist6 >= 0 and Hist6 < Hist6[1] ;
Def H7BullFall = Hist7 >= 0 and Hist7 < Hist7[1] ;
Def H1BearRise = Hist1 < 0 and Hist1 >= Hist1[1] ;
Def H2BearRise = Hist2 < 0 and Hist2 >= Hist2[1] ;
Def H3BearRise = Hist3 < 0 and Hist3 >= Hist3[1] ;
Def H4BearRise = Hist4 < 0 and Hist4 >= Hist4[1] ;
Def H5BearRise = Hist5 < 0 and Hist5 >= Hist5[1] ;
Def H6BearRise = Hist6 < 0 and Hist6 >= Hist6[1] ;
Def H7BearRise = Hist7 < 0 and Hist7 >= Hist7[1] ;
Def H1BearFall = Hist1 < 0 and Hist1 < Hist1[1] ;
Def H2BearFall = Hist2 < 0 and Hist2 < Hist2[1] ;
Def H3BearFall = Hist3 < 0 and Hist3 < Hist3[1] ;
Def H4BearFall = Hist4 < 0 and Hist4 < Hist4[1] ;
Def H5BearFall = Hist5 < 0 and Hist5 < Hist5[1] ;
Def H6BearFall = Hist6 < 0 and Hist6 < Hist6[1] ;
Def H7BearFall = Hist7 < 0 and Hist7 < Hist7[1] ;
Plot Dot1 = if IsNaN(close) then Double.NaN else 1;
Dot1.SetPaintingStrategy(PaintingStrategy.Squares);
Dot1.SetLineWeight(DotSize);
Dot1.DefineColor("Up", Color.Green);
Dot1.DefineColor("UpDecreasing", Color.Dark_Green);
Dot1.DefineColor("Down", Color.Dark_Red);
Dot1.DefineColor("DownDecreasing", Color.Red);
Dot1.AssignValueColor(
if H1BullRise == 1 then Dot1.Color("Up")
else if H1BullFall == 1 then Dot1.Color("UpDecreasing")
else if H1BearRise == 1 then Dot1.Color(“DownDecreasing”)
else Dot1.Color("Down") );
Plot Dot2 = if IsNaN(close) then Double.NaN else 2;
Dot2.SetPaintingStrategy(PaintingStrategy.Points);
Dot2.SetLineWeight(DotSize);
Dot2.DefineColor("Up", Color.Green);
Dot2.DefineColor("UpDecreasing", Color.Dark_Green);
Dot2.DefineColor("Down", Color.Dark_Red);
Dot2.DefineColor("DownDecreasing", Color.Red);
Dot2.AssignValueColor(
if H2BullRise == 1 then Dot2.Color("Up")
else if H2BullFall == 1 then Dot2.Color("UpDecreasing")
else if H2BearRise == 1 then Dot2.Color(“DownDecreasing”)
else Dot2.Color("Down"));
Plot Dot3 = if IsNaN(close) then Double.NaN else 3;
Dot3.SetPaintingStrategy(PaintingStrategy.Squares);
Dot3.SetLineWeight(DotSize);
Dot3.DefineColor("Up", Color.Green);
Dot3.DefineColor("UpDecreasing", Color.Dark_Green);
Dot3.DefineColor("Down", Color.Dark_Red);
Dot3.DefineColor("DownDecreasing", Color.Red);
Dot3.AssignValueColor(
if H3BullRise == 1 then Dot3.Color("Up")
else if H3BullFall == 1 then Dot3.Color("UpDecreasing")
else if H3BearRise == 1 then Dot3.Color(“DownDecreasing”)
else Dot3.Color("Down"));
Plot Dot4 = if IsNaN(close) then Double.NaN else 4;
Dot4.SetPaintingStrategy(PaintingStrategy.Points);
Dot4.SetLineWeight(DotSize);
Dot4.DefineColor("Up", Color.Green);
Dot4.DefineColor("UpDecreasing", Color.Dark_Green);
Dot4.DefineColor("Down", Color.Dark_Red);
Dot4.DefineColor("DownDecreasing", Color.Red);
Dot4.AssignValueColor(
if H4BullRise == 1 then Dot4.Color("Up")
else if H4BullFall == 1 then Dot4.Color("UpDecreasing")
else if H4BearRise == 1 then Dot4.Color(“DownDecreasing”)
else Dot4.Color("Down"));
Plot Dot5 = if IsNaN(close) then Double.NaN else 5;
Dot5.SetPaintingStrategy(PaintingStrategy.Squares);
Dot5.SetLineWeight(DotSize);
Dot5.DefineColor("Up", Color.Green);
Dot5.DefineColor("UpDecreasing", Color.Dark_Green);
Dot5.DefineColor("Down", Color.Dark_Red);
Dot5.DefineColor("DownDecreasing", Color.Red);
Dot5.AssignValueColor(
if H5BullRise == 1 then Dot5.Color("Up")
else if H5BullFall == 1 then Dot5.Color("UpDecreasing")
else if H5BearRise == 1 then Dot5.Color(“DownDecreasing”)
else Dot5.Color("Down"));
Plot Dot6 = if IsNaN(close) then Double.NaN else 6;
Dot6.SetPaintingStrategy(PaintingStrategy.Points);
Dot6.SetLineWeight(DotSize);
Dot6.DefineColor("Up", Color.Green);
Dot6.DefineColor("UpDecreasing", Color.Dark_Green);
Dot6.DefineColor("Down", Color.Dark_Red);
Dot6.DefineColor("DownDecreasing", Color.Red);
Dot6.AssignValueColor(
if H6BullRise == 1 then Dot6.Color("Up")
else if H6BullFall == 1 then Dot6.Color("UpDecreasing")
else if H6BearRise == 1 then Dot6.Color(“DownDecreasing”)
else Dot6.Color("Down"));
Plot Dot7 = if IsNaN(close) then Double.NaN else 7;
Dot7.SetPaintingStrategy(PaintingStrategy.Squares);
Dot7.SetLineWeight(DotSize);
Dot7.DefineColor("Up", Color.Green);
Dot7.DefineColor("UpDecreasing", Color.Dark_Green);
Dot7.DefineColor("Down", Color.Dark_Red);
Dot7.DefineColor("DownDecreasing", Color.Red);
Dot7.AssignValueColor(
if H7BullRise == 1 then Dot7.Color("Up")
else if H7BullFall == 1 then Dot7.Color("UpDecreasing")
else if H7BearRise == 1 then Dot7.Color(“DownDecreasing”)
else Dot7.Color("Down"));
input Aprice = close;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.SIMPLE;
input displace = 0;
def sDev = StDev(data = Aprice[-displace], length = length);
def MidLineBB = MovingAverage(averageType, data = Aprice[-displace], length = length);
def LowerBandBB = MidLineBB + Num_Dev_Dn * sDev;
def UpperBandBB = MidLineBB + Num_Dev_up * sDev;
input factorhigh = 1.0;
input factormid = 1.5;
input factorlow = 2.0;
input trueRangeAverageType = AverageType.SIMPLE;
def shifthigh = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def shiftMid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def shiftlow = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def average = MovingAverage(averageType, Aprice, length);
def Avg = average[-displace];
def UpperBandKCLow = average[-displace] + shiftlow[-displace];
def LowerBandKCLow = average[-displace] - shiftlow[-displace];
def UpperBandKCMid = average[-displace] + shiftMid[-displace];
def LowerBandKCMid = average[-displace] - shiftMid[-displace];
def UpperBandKCHigh = average[-displace] + shifthigh[-displace];
def LowerBandKCHigh = average[-displace] - shifthigh[-displace];
def K = (Highest(high, length) + Lowest(low, length)) /
2 + ExpAverage(close, length);
def momo = Inertia(Aprice - K / 2, length);
def pos = momo>= 0;
def neg = momo< 0;
def up = momo >= momo[1];
def dn = momo < momo[1];
def presqueeze = LowerBandBB > LowerBandKCLow and UpperBandBB < UpperBandKCLow;
def originalSqueeze = LowerBandBB > LowerBandKCMid and UpperBandBB < UpperBandKCMid;
def ExtrSqueeze = LowerBandBB > LowerBandKCHigh and UpperBandBB < UpperBandKCHigh;
def PosUp = pos and up;
def PosDn = pos and dn;
def NegDn = neg and dn;
def NegUp = neg and up;
plot squeezeline = if IsNaN(close) then Double.NaN else 9;
squeezeline.SetPaintingStrategy(PaintingStrategy.POINTS);
squeezeline.AssignValueColor(if ExtrSqueeze then Color.RED else if originalSqueeze then Color.YELLOW else if presqueeze then Color.DARK_ORANGE else Color.GRAY);
squeezeline.SetLineWeight(Dotsize+1);
plot momentum = if IsNaN(close) then Double.NaN else 10;
momentum.SetPaintingStrategy(PaintingStrategy.Squares);
momentum.AssignValueColor( if PosUp then Color.green else if PosDn then Color.dark_green else if NegDn then Color.dark_orange else if NegUp then Color.yellow else Color.YELLOW);
Momentum.SetLineWeight(Dotsize);
AssignPriceColor( if APC == 1 and H1BullRise == 1 then Dot1.Color("Up")
else if APC == 1 and H1BullFall == 1 then Dot1.Color("UpDecreasing")
else if APC == 1 and H1BearFall == 1 then Dot1.Color(“DownDecreasing”)
else if APC == 1 and H1BearRise == 1 then Dot1.Color("Down")
else if APC == 2 and H2BullRise == 1 then Dot2.Color("Up")
else if APC == 2 and H2BullFall == 1 then Dot2.Color("UpDecreasing")
else if APC == 2 and H2BearFall == 1 then Dot2.Color(“DownDecreasing”)
else if APC == 2 and H2BearRise == 1 then Dot2.Color("Down")
else if APC == 3 and H3BullRise == 1 then Dot3.Color("Up")
else if APC == 3 and H3BullFall == 1 then Dot3.Color("UpDecreasing")
else if APC == 3 and H3BearFall == 1 then Dot3.Color(“DownDecreasing”)
else if APC == 3 and H3BearRise == 1 then Dot3.Color("Down")
else if APC == 4 and H4BullRise == 1 then Dot4.Color("Up")
else if APC == 4 and H4BullFall == 1 then Dot4.Color("UpDecreasing")
else if APC == 4 and H4BearFall == 1 then Dot4.Color(“DownDecreasing”)
else if APC == 4 and H4BearRise == 1 then Dot4.Color("Down")
else if APC == 5 and H5BullRise == 1 then Dot5.Color("Up")
else if APC == 5 and H5BullFall == 1 then Dot5.Color("UpDecreasing")
else if APC == 5 and H5BearFall == 1 then Dot5.Color(“DownDecreasing”)
else if APC == 5 and H5BearRise == 1 then Dot5.Color("Down")
else if APC == 6 and H6BullRise == 1 then Dot6.Color("Up")
else if APC == 6 and H6BullFall == 1 then Dot6.Color("UpDecreasing")
else if APC == 6 and H6BearFall == 1 then Dot6.Color(“DownDecreasing”)
else if APC == 6 and H6BearRise == 1 then Dot6.Color("Down")
else if APC == 7 and H7BullRise == 1 then Dot7.Color("Up")
else if APC == 7 and H7BullFall == 1 then Dot7.Color("UpDecreasing")
else if APC == 7 and H7BearFall == 1 then Dot7.Color(“DownDecreasing”)
else if APC == 7 and H7BearRise == 1 then Dot7.Color("Down")
else if APC == 9 and ExtrSqueeze then Color.RED
else if APC == 9 and originalSqueeze then Color.YELLOW
else if APC == 9 and presqueeze then Color.DARK_ORANGE
else If APC == 9 then Color.GRAY
Else if APC == 10 and PosUp then Color.green
else if APC == 10 and PosDn then Color.dark_green
else if APC == 10 and NegDn then Color.dark_orange
else if APC == 10 and NegUp then Color.yellow else Color.Current);
Other studies use "OR" statements, which is more inclusive on either BB band. I use the OR version below, but it could be that both legs of the BB band are either both in or both out; I have my doubts though.Code:def presqueeze = LowerBandBB > LowerBandKCLow and UpperBandBB < UpperBandKCLow; def originalSqueeze = LowerBandBB > LowerBandKCMid and UpperBandBB < UpperBandKCMid; def ExtrSqueeze = LowerBandBB > LowerBandKCHigh and UpperBandBB < UpperBandKCHigh;
input price = close;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.SIMPLE;
input displace = 0;
def sDev = StDev(data = price[-displace], length = length);
def MidLineBB = MovingAverage(averageType, data = price[-displace], length = length);
def LowerBandBB = MidLineBB + Num_Dev_Dn * sDev;
def UpperBandBB = MidLineBB + Num_Dev_up * sDev;
input factorhigh = 1.0;
input factormid = 1.5;
input factorlow = 2.0;
input trueRangeAverageType = AverageType.SIMPLE;
def shifthigh = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def shiftMid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def shiftlow = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def average = MovingAverage(averageType, price, length);
def Avg = average[-displace];
def UpperBandKCLow = average[-displace] + shiftlow[-displace];
def LowerBandKCLow = average[-displace] - shiftlow[-displace];
def UpperBandKCMid = average[-displace] + shiftMid[-displace];
def LowerBandKCMid = average[-displace] - shiftMid[-displace];
def UpperBandKCHigh = average[-displace] + shifthigh[-displace];
def LowerBandKCHigh = average[-displace] - shifthigh[-displace];
def K = (Highest(high, length) + Lowest(low, length)) /
2 + ExpAverage(close, length);
def momo = Inertia(price - K / 2, length);
def pos = momo>= 0;
def neg = momo< 0;
def up = momo >= momo[1];
def dn = momo < momo[1];
def presqueeze = LowerBandBB > LowerBandKCLow and UpperBandBB < UpperBandKCLow;
def originalSqueeze = LowerBandBB > LowerBandKCMid and UpperBandBB < UpperBandKCMid;
def ExtrSqueeze = LowerBandBB > LowerBandKCHigh and UpperBandBB < UpperBandKCHigh;
squeezeline = 0;
squeezeline.SetPaintingStrategy(PaintingStrategy.POINTS);
squeezeline.AssignValueColor(if ExtrSqueeze then Color.RED else if originalSqueeze then Color.YELLOW else if presqueeze then Color.dark_orANGE else Color.light_GRAY);
plot scan = sum(presqueeze or originalSqueeze or extrSqueeze,5) == 5;
Ha cool, Im new here looking for a fix for this and there it is!I figured it out, there was just a little redundancy in the original code. This will display the labels correctly:
Code:addlabel(yes, if extrSqueeze then "extraSqueeze" else if originalSqueeze then "squeeze" else if presqueeze then "preSqueeze" else "noSqueeze");
My question pertains to the script above for the watchlist by Sneaky_Swings, is there a way to include a count number for how many bars a stock has been in a pre-, orig- or extra squeeze?Here is a watchlist column for those interested: http://tos.mx/c6kSvbk
Code:input price = close; input length = 20; input Num_Dev_Dn = -2.0; input Num_Dev_up = 2.0; input averageType = AverageType.SIMPLE; input displace = 0; def sDev = StDev(data = price[-displace], length = length); def MidLineBB = MovingAverage(averageType, data = price[-displace], length = length); def LowerBandBB = MidLineBB + Num_Dev_Dn * sDev; def UpperBandBB = MidLineBB + Num_Dev_up * sDev; input factorhigh = 1.0; input factormid = 1.5; input factorlow = 2.0; input trueRangeAverageType = AverageType.SIMPLE; def shifthigh = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length); def shiftMid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length); def shiftlow = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length); def average = MovingAverage(averageType, price, length); def Avg = average[-displace]; def UpperBandKCLow = average[-displace] + shiftlow[-displace]; def LowerBandKCLow = average[-displace] - shiftlow[-displace]; def UpperBandKCMid = average[-displace] + shiftMid[-displace]; def LowerBandKCMid = average[-displace] - shiftMid[-displace]; def UpperBandKCHigh = average[-displace] + shifthigh[-displace]; def LowerBandKCHigh = average[-displace] - shifthigh[-displace]; def K = (Highest(high, length) + Lowest(low, length)) / 2 + ExpAverage(close, length); def momo = Inertia(price - K / 2, length); def pos = momo>= 0; def neg = momo< 0; def up = momo >= momo[1]; def dn = momo < momo[1]; def presqueeze = LowerBandBB > LowerBandKCLow and UpperBandBB < UpperBandKCLow; def originalSqueeze = LowerBandBB > LowerBandKCMid and UpperBandBB < UpperBandKCMid; def ExtrSqueeze = LowerBandBB > LowerBandKCHigh and UpperBandBB < UpperBandKCHigh; addlabel(yes, if extrSqueeze then "extraSqueeze" else if presqueeze then "preSqueeze" else if originalSqueeze then "squeeze" else if preSqueeze then "preSqueeze" else "noSqueeze"); assignBackgroundColor(if ExtrSqueeze then Color.red else if originalSqueeze then Color.blue else if presqueeze then color.white else Color.gray);
I like this indicator. Do you still find it useful? Is there a name to it? if you can explain how this is made, it would be very helpful.ZScore is a good supporting study for deciding which way sqz is going to fire https://tos.mx/4WjebUG
Get access to Ben's watchlist, swing trading strategy, ThinkorSwim setup, and trade examples.
Start a new thread and receive assistance from our community.
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.
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.