Welkin
Active member
I saw a video with John F. Carter explaining that the squeeze is when the Bollinger Bands cross inside of Keltner Channels. I decided to script it into cloud form. It appears this would have great applications for finding ranges to scalp as well.
Shareable Link: https://tos.mx/SZGo6Qe
clouds with ttm_squeeze to show correspondence
thinkScript Code
Code:
#MTF Squeeze Clouds
#[email protected]
declare weak_volume_dependency;
input EnableAggregation2 = yes;
input EnableAggregation3 = yes;
input Aggregation1 = AggregationPeriod.FIVE_MIN;
input Aggregation2 = AggregationPeriod.THIRTY_MIN;
input Aggregation3 = AggregationPeriod.HOUR;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.SIMPLE;
input factor = 1.5;
input trueRangeAverageType = AverageType.SIMPLE;
def NA = Double.NaN;
def price1 = close("Period" = Aggregation1);
def price2 = close("Period" = Aggregation2);
def price3 = close("Period" = Aggregation3);
#BollingerBands
def sDev1 = StDev(data = price1[-displace], length = length);
def sDev2 = StDev(data = price2[-displace], length = length);
def sDev3 = StDev(data = price3[-displace], length = length);
def MidLine1 = MovingAverage(averageType, data = price1[-displace], length = length);
def MidLine2 = MovingAverage(averageType, data = price2[-displace], length = length);
def MidLine3 = MovingAverage(averageType, data = price3[-displace], length = length);
def BLowerBand1 = MidLine1 + Num_Dev_Dn * sDev1;
def BLowerBand2 = MidLine2 + Num_Dev_Dn * sDev2;
def BLowerBand3 = MidLine3 + Num_Dev_Dn * sDev3;
def BUpperBand1 = MidLine1 + Num_Dev_up * sDev1;
def BUpperBand2 = MidLine2 + Num_Dev_up * sDev2;
def BUpperBand3 = MidLine3 + Num_Dev_up * sDev3;
#Keltner Channels
def shift1 = factor * MovingAverage(trueRangeAverageType, TrueRange(high("Period" = Aggregation1), close("Period" = Aggregation1), low("Period" = Aggregation1)), length);
def shift2 = factor * MovingAverage(trueRangeAverageType, TrueRange(high("Period" = Aggregation2), close("Period" = Aggregation2), low("Period" = Aggregation2)), length);
def shift3 = factor * MovingAverage(trueRangeAverageType, TrueRange(high("Period" = Aggregation3), close("Period" = Aggregation3), low("Period" = Aggregation3)), length);
def average1 = MovingAverage(averageType, price1, length);
def average2 = MovingAverage(averageType, price2, length);
def average3 = MovingAverage(averageType, price3, length);
def Avg1 = average1[-displace];
def Avg2 = average2[-displace];
def Avg3 = average3[-displace];
def KUpperBand1 = average1[-displace] + shift1[-displace];
def kUpperBand2 = average2[-displace] + shift2[-displace];
def kUpperBand3 = average3[-displace] + shift3[-displace];
def KLowerBand1 = average1[-displace] - shift1[-displace];
def KLowerBand2 = average2[-displace] - shift2[-displace];
def KLowerBand3 = average3[-displace] - shift3[-displace];
#Squeeze upper and lower crossovers
def BollKeltUB1DiffH = if KUpperBand1 - BUpperBand1 <= 0 then NA else KUpperBand1;
def BollKeltUB1DiffL = if KUpperBand1 - BUpperBand1 <= 0 then NA else BUpperBand1;
def BollKeltLB1DiffH = if BLowerBand1 - KLowerBand1 <= 0 then NA else BLowerBand1;
def BollKeltLB1DiffL = if BLowerBand1 - KLowerBand1 <= 0 then NA else KLowerBand1;
def BollKeltUB2DiffH = if !EnableAggregation2 then NA else if KUpperBand2 - BUpperBand2 <= 0 then NA else KUpperBand2;
def BollKeltUB2DiffL = if !EnableAggregation2 then NA else if KUpperBand2 - BUpperBand2 <= 0 then NA else BUpperBand2;
def BollKeltLB2DiffH = if !EnableAggregation2 then NA else if BLowerBand2 - KLowerBand2 <= 0 then NA else BLowerBand2;
def BollKeltLB2DiffL = if !EnableAggregation2 then NA else if BLowerBand2 - KLowerBand2 <= 0 then NA else KLowerBand2;
def BollKeltUB3DiffH = if !EnableAggregation3 then NA else if KUpperBand3 - BUpperBand3 <= 0 then NA else KUpperBand3;
def BollKeltUB3DiffL = if !EnableAggregation3 then NA else if KUpperBand3 - BUpperBand3 <= 0 then NA else BUpperBand3;
def BollKeltLB3DiffH = if !EnableAggregation3 then NA else if BLowerBand3 - KLowerBand3 <= 0 then NA else BLowerBand3;
def BollKeltLB3DiffL = if !EnableAggregation3 then NA else if BLowerBand3 - KLowerBand3 <= 0 then NA else KLowerBand3;
#Cloud shading
AddCloud(BollKeltUB1DiffH, BollKeltUB1DiffL, Color.YELLOW, Color.YELLOW);
AddCloud(BollKeltLB1DiffH, BollKeltLB1DiffL, Color.YELLOW, Color.YELLOW);
AddCloud(BollKeltUB2DiffH, BollKeltUB2DiffL, Color.DARK_ORANGE, Color.DARK_ORANGE);
AddCloud(BollKeltLB2DiffH, BollKeltLB2DiffL, Color.DARK_ORANGE, Color.DARK_ORANGE);
AddCloud(BollKeltUB3DiffH, BollKeltUB3DiffL, Color.RED, Color.RED);
AddCloud(BollKeltLB3DiffH, BollKeltLB3DiffL, Color.RED, Color.RED);
Shareable Link: https://tos.mx/SZGo6Qe
clouds with ttm_squeeze to show correspondence
Last edited: