Keltner Channel Squeeze Indicator For ThinkOrSwim

fungus12

Member
Hey guys I need help with this idea I can't figure out how to code. Essentially I'm just using the basic Keltner Channels that comes with thinkorswim. What my idea is is having the upper and lower bands of the Keltner Channel change colors indicating a squeeze when the requirements are met.
 
Last edited by a moderator:

fungus12

Member
Got help from Mobius on the thinkorswim Discord. For those curious, here it is. The upper band and lower band will turn cyan when the difference between the upper band and lower band is 1 or less. Theoretically when this type of compression happens, there is said to be a price squeeze.

Code:
# Keltner_Channels_Bandwidth
# Mobius
# V01.2017
# Edited to upper chart for @fungus12 3/24/22

input displace = 0;
input factor = 1.5;
input length = 20;
input price = close;
input averageType = AverageType.SIMPLE;
input trueRangeAverageType = AverageType.SIMPLE;

def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def average = MovingAverage(averageType, price, length);
plot Avg = average[-displace];
Avg.SetDefaultColor(GetColor(1));
plot Upper_Band = average[-displace] + shift[-displace];
Upper_Band.SetDefaultColor(GetColor(8));
plot Lower_Band = average[-displace] - shift[-displace];
Lower_Band.SetDefaultColor(GetColor(5));
#My code
input squeeze_factor = 1;
input squeeze_on = yes;
def diff = Upper_Band - Lower_Band;
def squeeze = diff <= squeeze_factor;
Upper_Band.assignValueColor(if squeeze then GetColor(1) else color.Red);
Lower_Band.assignValueColor(if squeeze then GetColor(1) else color.Red);
 
Last edited by a moderator:

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
Mobius's Lower Chart Keltner Squeeze Indicator
Ruby:
# Keltner_Channels_Bandwidth
# Mobius
# V01.2017
# Upper and Lower dashed lines plot the bulge and squeeze of the channels
# Squeeze Scan would be (using the name: Keltner_Channels_Bandwidth the scan code is: Keltner_Channels_Bandwidth().InSqueeze is TRUE

declare lower;

input displace = 0;
input factor = 1.5;
input length = 20;
input price = close;
input averageType = AverageType.SIMPLE;
input trueRangeAverageType = AverageType.SIMPLE;
input BulgeLength = 150;
input SqueezeLength = 200;

def shift = factor * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def average = MovingAverage(averageType, price, length);
def midLine = average[-displace];
def UpperBand = average[-displace] + shift[-displace];
def LowerBand = average[-displace] - shift[-displace];
plot Bandwidth = (upperBand - lowerBand) / midLine * 100;
Bandwidth.SetDefaultColor(GetColor(1));
plot Bulge = Highest(Bandwidth, BulgeLength);
Bulge.SetDefaultColor(GetColor(8));
Bulge.SetStyle(Curve.SHORT_DASH);
plot Squeeze = Lowest(Bandwidth, SqueezeLength);
Squeeze.SetDefaultColor(GetColor(8));
Squeeze.SetStyle(Curve.SHORT_DASH);
plot InSqueeze = if(Bandwidth <= Squeeze, Squeeze, double.nan);
InSqueeze.SetStyle(Curve.Points);
InSqueeze.SetLineWeight(3);
InSqueeze.SetDefaultColor(Color.Red);
AddLabel(InSqueeze, "In Squeeze", Color.Red);
# End Code
 

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.
Top