Bladeof300
Member
Donchian Channel / Bollinger Bands Squeeze For ThinkOrSwim
This shows fully customizable Donchian Channels, Bollinger Bands, and Keltner Channels. It also shows squeeze as a blue cloud when the Bollinger Band moves into the Keltner Channel. I did it with the help of rad14733.
This shows fully customizable Donchian Channels, Bollinger Bands, and Keltner Channels. It also shows squeeze as a blue cloud when the Bollinger Band moves into the Keltner Channel. I did it with the help of rad14733.
Ruby:
# Working example of how TTM_Squeeze works
# Coded by rad14733 for usethinkscript.com
# Edited by Bladeof300- added Donchian Channels, and made it more customizable.
# Original code created 2020-12-23
# Use reference calls to TOS BB's and plot midline and bands
# Working example of how TTM_Squeeze works
# Coded by rad14733 for usethinkscript.com
# Original code created 2020-12-23
# Use reference calls to TOS BB's and plot midline and bands
input price = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.Simple;
#Donchian Inputs
input length_used_for_calc = 15;
input Use_Other_Time_Frame = yes;
input Time_Frame = AggregationPeriod.DAY;
#Shift is the same as displace, but shift is for the Donchian Channels
input shift = 1;
#Donchian Code
def h = if Use_Other_Time_Frame then high(period = Time_Frame) else high;
def l = if Use_Other_Time_Frame then low(period = Time_Frame) else low;
def highline = Highest(high, length_used_for_calc);
def lowline = Lowest(low, length_used_for_calc);
plot High_Line = (highline[shift]);
High_Line.SetDefaultColor(Color.YELLOW);
Plot Low_Line=(lowline[shift]);
Low_Line.SetDefaultColor(Color.YELLOW);
#BollingerCode
plot bb_midline = BollingerBands().MidLine;
bb_midline.SetDefaultColor(Color.GRAY);
# Tried using gradient colors to help indicate when a squeeze may occur(I recommend using OBV paired w/ a short exp moving average to predict this instead if they trend the same way a breakout should follow)
# AssignNormGradientColor(length, Color.BLACK, Color.GRAY);
# AssignNormGradientColor(length, Color.GRAY, Color.BLACK);
# for selectable color use this SetDefaultColor(Color.GRAY);
plot bb_upperband = BollingerBands().UpperBand;
bb_upperBand.SetDefaultColor(Color.GRAY);
plot bb_lowerband = BollingerBands().LowerBand;
bb_lowerBand.SetDefaultColor(Color.GRAY);
# Use reference calls to TOS KC's and plot midline and bands
plot kc_midline = KeltnerChannels().Avg;
kc_midline.SetDefaultColor(Color.YELLOW);
kc_midline.Hide(); #Both midlines are the same and we only need one
plot kc_upperband = KeltnerChannels().Upper_Band;
kc_upperband.SetDefaultColor(Color.GREEN);
plot kc_lowerband = KeltnerChannels().Lower_Band;
kc_lowerband.SetDefaultColor(Color.GREEN);
# When the BB upper and lower bands cross inside the KC's we are in a Squeeze
DefineGlobalColor("Squeeze", Color.BLUE);
DefineGlobalColor("UnSqueezed", Color.CURRENT);
AddCloud(kc_upperband, bb_upperband, GlobalColor("Squeeze"), GlobalColor("UnSqueezed"));
AddCloud(bb_lowerband, kc_lowerband, GlobalColor("Squeeze"), GlobalColor("UnSqueezed"));
# Add vertical lines to further demarcate start and end of Squeeze
AddVerticalLine(bb_upperband crosses below kc_upperband and bb_lowerband crosses above kc_lowerband, "Squeeze On", Color.RED);
AddVerticalLine(bb_upperband crosses above kc_upperband and bb_lowerband crosses below kc_lowerband, "Squeeze Off", Color.GREEN);
Last edited by a moderator: