The TTM_Squeeze_Clouds code provided below was originally intended to be for informational purposes only to demonstrate what a TTM_Squeeze means... However, I have found it so helpful that I have been using it on some of my charts because I find it more helpful than using the TTM_Squeeze lower indicator and frees up space for alternate lower indicators... On some charts I actually turn off all of the plots and rely solely on the clouds and vertical Squeeze On/Off lines... Let me know if you find this Study useful...
For anyone who doesn't understand exactly what a TTM_Squeeze is, it is when a Bollinger Bands studies upper and lower bands "squeeze" down to fit inside accompanying Keltner Channel upper and lower bands...
The first image shows the Bollinger Band Study, the Keltner Channels Study, and the TTM_Squeeze_Clouds Study portions of the script... The Second image shows just the TTM_Squeeze_Clouds Study portion of the script... The third image shows just the TTM_Squeeze_Clouds, my 8, 21, 55 EMA Study with breakout and breakdown arrows which, combined, where the clouds would have kept me from taking the indicated potential trades...
For anyone who doesn't understand exactly what a TTM_Squeeze is, it is when a Bollinger Bands studies upper and lower bands "squeeze" down to fit inside accompanying Keltner Channel upper and lower bands...
The first image shows the Bollinger Band Study, the Keltner Channels Study, and the TTM_Squeeze_Clouds Study portions of the script... The Second image shows just the TTM_Squeeze_Clouds Study portion of the script... The third image shows just the TTM_Squeeze_Clouds, my 8, 21, 55 EMA Study with breakout and breakdown arrows which, combined, where the clouds would have kept me from taking the indicated potential trades...
Ruby:
# TTM_Squeeze_Clouds
# Working example of how TTM_Squeeze works
# Coded by rad14733 for usethinkscript.com
# 2020-12-23 v1.0 Original code created
# 2021-01-10 v1.1 Added toggle settings to allow BB's and/or KC's to be turned off
# 2021-01-10 v1.2 Added toggle setting to allow vertical lines to be turned off
input showBBs = yes;
input showKCs = yes;
input showVerticalLines = yes;
# Use reference calls to TOS BB's and plot midline and bands
def bb_midline_value = BollingerBands().MidLine;
plot bb_midline = if showBBs then bb_midline_value else Double.NaN;
bb_midline.AssignValueColor(Color.CYAN);
def bb_upperband_value = BollingerBands().UpperBand;
plot bb_upperband = if showBBs then bb_upperband_value else Double.NaN;
bb_upperband.AssignValueColor(Color.WHITE);
def bb_lowerband_value = BollingerBands().LowerBand;
plot bb_lowerband = if showBBs then bb_lowerband_value else Double.NaN;
bb_upperband.AssignValueColor(Color.WHITE);
# Use reference calls to TOS KC's and plot midline and bands
def kc_midline_value = KeltnerChannels().Avg;
plot kc_midline = if showKCs then kc_midline_value else Double.NaN;
kc_midline.AssignValueColor(Color.CYAN);
def kc_upperband_value = KeltnerChannels().Upper_Band;
plot kc_upperband = if showKCs then kc_upperband_value else Double.NaN;
kc_upperband.AssignValueColor(Color.YELLOW);
def kc_lowerband_value = KeltnerChannels().Lower_Band;
plot kc_lowerband = if showKCs then kc_lowerband_value else Double.NaN;
kc_lowerband.AssignValueColor(Color.YELLOW);
# When the BB upper and lower bands cross inside the KC's we are in a Squeeze
DefineGlobalColor("Squeeze", Color.RED);
DefineGlobalColor("UnSqueezed", Color.CURRENT);
AddCloud(kc_upperband_value, bb_upperband_value, GlobalColor("Squeeze"), GlobalColor("UnSqueezed"));
AddCloud(bb_lowerband_value, kc_lowerband_value, GlobalColor("Squeeze"), GlobalColor("UnSqueezed"));
# Add vertical lines to further demarcate start and end of Squeeze
AddVerticalLine(showVerticalLines and bb_upperband_value crosses below kc_upperband_value and bb_lowerband_value crosses above kc_lowerband_value, "Squeeze On", Color.RED);
AddVerticalLine(showVerticalLines and bb_upperband_value crosses above kc_upperband_value and bb_lowerband_value crosses below kc_lowerband_value, "Squeeze Off", Color.GREEN);
# END - TTM_Squeeze_Clouds
Ruby:
# TTM_Squeeze_Clouds
# Working example of how TTM_Squeeze works
# Coded by rad14733 for usethinkscript.com
# 2020-12-23 v1.0 Original code created
# 2021-01-10 v1.1 Added toggle settings to allow BB's and/or KC's to be turned off
input showBBs = yes;
input showKCs = yes;
# Use reference calls to TOS BB's and plot midline and bands
def bb_midline_value = BollingerBands().MidLine;
plot bb_midline = if showBBs then bb_midline_value else Double.NaN;
bb_midline.AssignValueColor(Color.CYAN);
def bb_upperband_value = BollingerBands().UpperBand;
plot bb_upperband = if showBBs then bb_upperband_value else Double.NaN;
bb_upperband.AssignValueColor(Color.WHITE);
def bb_lowerband_value = BollingerBands().LowerBand;
plot bb_lowerband = if showBBs then bb_lowerband_value else Double.NaN;
bb_upperband.AssignValueColor(Color.WHITE);
# Use reference calls to TOS KC's and plot midline and bands
def kc_midline_value = KeltnerChannels().Avg;
plot kc_midline = if showKCs then kc_midline_value else Double.NaN;
kc_midline.AssignValueColor(Color.CYAN);
def kc_upperband_value = KeltnerChannels().Upper_Band;
plot kc_upperband = if showKCs then kc_upperband_value else Double.NaN;
kc_upperband.AssignValueColor(Color.YELLOW);
def kc_lowerband_value = KeltnerChannels().Lower_Band;
plot kc_lowerband = if showKCs then kc_lowerband_value else Double.NaN;
kc_lowerband.AssignValueColor(Color.YELLOW);
# When the BB upper and lower bands cross inside the KC's we are in a Squeeze
DefineGlobalColor("Squeeze", Color.RED);
DefineGlobalColor("UnSqueezed", Color.CURRENT);
AddCloud(kc_upperband_value, bb_upperband_value, GlobalColor("Squeeze"), GlobalColor("UnSqueezed"));
AddCloud(bb_lowerband_value, kc_lowerband_value, GlobalColor("Squeeze"), GlobalColor("UnSqueezed"));
# Add vertical lines to further demarcate start and end of Squeeze
AddVerticalLine(bb_upperband_value crosses below kc_upperband_value and bb_lowerband_value crosses above kc_lowerband_value, "Squeeze On", Color.RED);
AddVerticalLine(bb_upperband_value crosses above kc_upperband_value and bb_lowerband_value crosses below kc_lowerband_value, "Squeeze Off", Color.GREEN);
# END - TTM_Squeeze_Clouds
Last edited: