# 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