With chart real estate being at a premium there are times when combining indicators can be helpful... The code below is a combination of the PriceLine Chart Indicator I use combined with the TTM_Squeeze code I use in my TTM_Squeeze_Clouds Chart Study... Combined they show the current price as a moving line across the chart, colored to show when pricing indicates a squeeze caused by Bollinger Bands "squeezing" inside Keltner Channels, without the need to display the Bollinger Bands and Keltner Channels...
Please note that the Thinkscript code above has been corrected for proper PriceLine color change... The logic indicating current squeeze state was flawed...
Ruby:
# TTM_Squeeze_PriceLine
# Paints a horizontal price line with TTM_Squeeze indication
# Coded by rad14733 for usethinkscript.com
# v1.0 : 2021-01-10 : Original Code
# v1.1 : 2021-01-14 : Made user configurable by adding inputs
# v1.2 : 2021-01-19 : Modified code so when BB & KC bands are equal it is considered a squeeze
# Use reference calls to TOS BB's and plot midline and bands
input bbprice = close;
input displace = 0;
input length = 21;
input numdevdn = -2.0;
input numdevup = 2.0;
input averagetype = AverageType.SIMPLE;
def bb_midline = BollingerBands(bbprice, displace, length, numdevdn, numdevup, averagetype).MidLine;
def bb_upperband = BollingerBands(bbprice, displace, length, numdevdn, numdevup, averagetype).UpperBand;
def bb_lowerband = BollingerBands(bbprice, displace, length, numdevdn, numdevup, averagetype).LowerBand;
# Use reference calls to TOS KC's and plot midline and bands
input kcdisplace = 0;
input kcfactor = 1.5;
input kclength = 20;
input kcprice = close;
input kcaverageType = AverageType.SIMPLE;
input kctrueRangeAverageType = AverageType.SIMPLE;
def kc_midline = KeltnerChannels(kcdisplace, kcfactor, kclength, kcprice, kcaveragetype, kctruerangeaveragetype).Avg;
def kc_upperband = KeltnerChannels(kcdisplace, kcfactor, kclength, kcprice, kcaveragetype, kctruerangeaveragetype).Upper_Band;
def kc_lowerband = KeltnerChannels(kcdisplace, kcfactor, kclength, kcprice, kcaveragetype, kctruerangeaveragetype).Lower_Band;
# When the BB upper and lower bands cross inside the KC's we are in a Squeeze
def squeezed = if bb_upperband <= kc_upperband and bb_lowerband >= kc_lowerband then 1 else if bb_upperband >= kc_upperband and bb_lowerband <= kc_lowerband then -1 else 0;
#Plot the current price across an entire chart
#Also helps determine when price is approaching support and resistance
#Color coded to indicate TTM_Squeeze zones
input price = close;
plot priceLine = HighestAll(if !IsNaN(price) and IsNaN(price[-1]) then price else Double.NaN);
priceLine.DefineColor("squeezed", Color.DARK_RED);
priceLine.DefineColor("unsqueezed", Color.WHITE);
priceLine.AssignValueColor(if squeezed == 1 then priceLine.Color("squeezed") else if squeezed == -1 then priceLine.Color("unsqueezed") else if squeezed == 0 then priceLine.Color("squeezed") else Color.CURRENT);
priceLine.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
priceLine.SetLineWeight(1);
# END - TTM_Squeeze_PriceLine
Please note that the Thinkscript code above has been corrected for proper PriceLine color change... The logic indicating current squeeze state was flawed...
Last edited: