John Carter's Squeeze Pro Indicator for ThinkorSwim (FREE)

New Indicator: Buy the Dip

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.

Download the indicator

SCAN QUESTION
Hello everyone. I'm currently studying and practicing strategies involving volume oscillator indicators and indicators akin to Ready Aim Fire (Made Popular by Simpler Trading). They've been promising but the scan hasn't been showing great results. The scan that they push a lot is TOS's TTM_Squeeze, but that hasn't given me many options with good OI or volume. Are there any adjustments that are recommended or perhaps different scans all together?
Thank you
 
Last edited:
Each 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.
 
Each 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.
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 again :)
 
I've been lurking and amazed at all the great information here, it's helped tremendously with figuring out Thinkscript on my own. I've been toying around with the Squeeze indicator without much results it just didn't seem to resonate with my trading style, but last week while I was waiting for some setups to develop I started to think what if you could create something like a Darvas Box around the squeeze range and would it be possible to trade the breakout of that range.

So I was trying to figure out how to program that and after a day and a half of trying to figure it out I thought I'd ask for some help figuring out the logic needed.

This is a little messy, but it's what I have so far, I was using the code @Shooters_Gotta_Shoot posted.

Is it possible to reference the DarvasBox study? I tried with something like:

plot boxHigh = reference DarvasBox("Upper Band");

But that didn't seem to be kosher with TOS

I'm not too familiar with Case statements yet, I was messing around with them too, but I could figure out how to use them only when the squeeze condition was met.

Any help or a nudge in the right direction would be much appreciated!

Code:
##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);
 
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?
 
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?
They all use the TTM Squeeze with the extended hours off.
 
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);
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.
 
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.
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");
 
TTM waves using a 2 pole butterworth Filter Lines 1 thru 7 , line 9 is the squeeze, Line 10 is the oscillator wave colors
Code:
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);

You can paint the bars by changing the APC input value to whichever line in the indicator


ztWuiNi.png
 
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 :)
 
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 :)
Code:
def presqueeze      = LowerBandBB > LowerBandKCLow and UpperBandBB < UpperBandKCLow;
def originalSqueeze     = LowerBandBB > LowerBandKCMid and UpperBandBB < UpperBandKCMid;
def ExtrSqueeze     = LowerBandBB > LowerBandKCHigh and UpperBandBB < UpperBandKCHigh;
 
Do you mind sharing the updated code. Keep getting an error not sure why when adding those other few lines
 
Last edited by a moderator:
Dnyoi re


Do you mind sharing the updated code. Keep getting an error not sure why when adding those other few lines
Code:
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);

Lines 1 thru 7 are the ABC waves colors, Light red , Green are more bullish, Dark_Green, Dark_Red are more bearish
Line 9 is the squeeze

Line 10 is the Oscillator colors

You can change the Price colors by changing the APC input to which ever line you would like 1 thru 7 & 9 or 10
 
Code:
def presqueeze      = LowerBandBB > LowerBandKCLow and UpperBandBB < UpperBandKCLow;
def originalSqueeze     = LowerBandBB > LowerBandKCMid and UpperBandBB < UpperBandKCMid;
def ExtrSqueeze     = LowerBandBB > LowerBandKCHigh and UpperBandBB < UpperBandKCHigh;
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.

def presqueeze = LowerBandBB > LowerBandKCLow or UpperBandBB < UpperBandKCLow;
def originalSqueeze = LowerBandBB > LowerBandKCMid or UpperBandBB < UpperBandKCMid;
def ExtrSqueeze = LowerBandBB > LowerBandKCHigh or UpperBandBB < UpperBandKCHigh;
 
Hello everyone,

I am new to writing TOS script, I am using the Pre squeeze script found here. I am trying to build a custom scan using Pre squeeze on TOS, since I am new to TOS script, I am having trouble getting the scan done, the scan will help identify tickers that are in 5 dots squeeze (Pre squeeze or Original squeeze or extra squeeze), also most importantly telling you whether it has been fired (dot color change from orange to grey) within 3 bars. However, I could not get this part(fired within 3 bars) done, Can anyone help me with this part of the Scan script please, I really appreciate it!

Please refer to the following script I am working on:
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;

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;
 
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");
Ha cool, Im new here looking for a fix for this and there it is!
 
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);
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?

I already have one that has a count, I believe I got from Hahn-tech... am looking for something that does the same but for the Pro
 
Last edited by a moderator:

Volatility Trading Range

VTR is a momentum indicator that shows if a stock is overbought or oversold based on its Weekly and Monthly average volatility trading range.

Download the indicator

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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