Docs

ITMScript

Find a Keltner squeeze

Flag the bars where Bollinger bands sit inside a Keltner channel and hold the flag until price leaves the channel.

Flag a squeeze, where the Bollinger bands sit inside a Keltner channel, and keep the flag on with latch until the close leaves the channel.

itm
//@itmscript 2
study("Keltner squeeze", overlay=true)
len = input.int(20, "Length", min=5, max=100)
kcMult = input.float(1.5, "Keltner width", min=0.5, max=5, step=0.1)
bbMult = input.float(2, "Bollinger width", min=0.5, max=5, step=0.1)
[kcMid, kcUp, kcLo] = ta.kc(close, len, kcMult)
[bbMid, bbUp, bbLo] = ta.bb(close, len, bbMult)
squeeze = bbUp < kcUp and bbLo > kcLo
armed = latch(squeeze, close > kcUp or close < kcLo)
up = plot(kcUp, "Keltner upper", color=color.gray, width=1, style=line)
lo = plot(kcLo, "Keltner lower", color=color.gray, width=1, style=line)
fill(up, lo, color=color.new(color.gray, 94))
plotshape(squeeze, style=circle, location=belowbar, color=color.orange, text="")
bgcolor(armed ? color.new(color.orange, 90) : na)

What you see

A grey Keltner channel is drawn over the candles with a light fill. An orange dot sits below each bar that is a squeeze. An orange tint runs behind the bars from the first squeeze until the close finishes above the upper line or below the lower line.

latch(set, reset) is on from a bar where its first condition is true until a bar where its second is true. When both are true on one bar it is off.

Change these inputs

  • Length. The window of both channels, from 5 to 100 bars.
  • Keltner width. The distance of the Keltner lines from their average, in multiples of the ATR. From 0.5 to 5. A larger number makes a squeeze more common.
  • Bollinger width. The distance of the Bollinger bands, in standard deviations. From 0.5 to 5. A smaller number makes a squeeze more common.