OPEN-SOURCE SCRIPT
Squeeze Breakout Strategy [KedArc Quant]

Description:
Squeeze Breakout strategy looks for volatility compression (Bollinger Bands inside Keltner Channels = a “squeeze”), then trades the volatility expansion in the direction of a momentum filter.
🧠 How the “Squeeze → Expansion” works
- Markets alternate between quiet (compressed) and active (expanded) phases.
- We call it a squeeze when Bollinger Bands (BB)—which reflect standard deviation around price—shrink inside the Keltner Channels (KC)—which reflect ATR/range.
- This means dispersion (stdev) is small relative to typical range (ATR). Price is coiling; participants are agreeing on value.
- When BB pops back outside KC, the squeeze releases. That’s the first sign that volatility is expanding again.
- A release alone doesn’t tell you direction. That’s why this strategy pairs the release with a momentum filter:
- We estimate momentum using a smoothed linear-regression slope of price (a clean proxy for acceleration).
- If the slope is positive at release, we favor longs; if negative, we favor shorts.
- Optionally, you can require Band Break + Momentum (price closes beyond the BB) for a stricter entry.
- This combination aims to capture the first leg of the range-to-trend transition while avoiding random pokes that often occur during tight consolidations.
💡 Why this is unique
Two entry modes (toggle):
1. Release + Momentum (enter when the squeeze turns off)
2. Band Break + Momentum (enter on a close beyond BB with momentum)
- Momentum = smoothed linear-regression slope, a clean thrust detector that’s less laggy than many oscillators.
- Risk module included: ATR stop, optional 1R partial take-profit, and a Chandelier trailing stop for the runner.
- Practical filters: higher-timeframe EMA trend alignment, volume surge, minimum BB width, and session window—so it adapts across markets/timeframes.
- Backtest-ready: uses TradingView’s `strategy.` framework with commission/slippage controls.
📈 How it helps traders
✅Regime clarity: distinguishes compression vs. expansion so you’re not forcing trades during dead zones.
✅Objective entries: momentum + band logic reduces discretionary “feel” and late chases.
✅Built-in risk plan: stop/targets/trailing defined in inputs—consistent execution across tickers.
✅Adaptable: works across instruments/timeframes; filters let you tailor noise tolerance per market session.
✅Alerts: real-time signals for entry and squeeze release.
✅Not a Mash-Up / Original Work
✅Fully authored in Pine Script v6; no external libraries or copied logic blocks.
✅Uses well-known, documented formulas (BB, KC, ATR, LinReg slope) combined into a new rule set (two entry modes + momentum + structured exits).
✅Code and parameters are transparent and adjustable; the script stands alone.
🧩 Formulas (core)
Bollinger Bands
# Basis = `SMA(close, bbLen)`
# Upper/Lower = `Basis ± bbMult × stdev(close, bbLen)`
# Width% = `(Upper − Lower) / Basis × 100`
Keltner Channels
# Basis = `EMA(close, kcLen)`
# Upper/Lower = `Basis ± kcMult × ATR(kcATR)`
Squeeze state
# ON: `BB_Upper < KC_Upper` and `BB_Lower > KC_Lower`
# Release: `squeeze_on[1]` and `not squeeze_on`
Momentum (this script)
# `lin = linreg(close, momLen, 0)`
# `mom = SMA( lin − lin[1], momSmoothing )`
# Long bias when `mom > 0`; short bias when `mom < 0`.
⚙️ Inputs
Compression
`bbLen`, `bbMult` — BB length & std-dev multiplier
`kcLen`, `kcATR`, `kcMult` — KC lengths & ATR multiplier
`Entry Mode` — Release + Momentum, Band Break + Momentum, or Either
Momentum
`momLen`, `momSmoothing`
Filters (optional)
`Use HTF Trend Filter` + `HTF Timeframe` + `HTF EMA Length`
`Require Volume Surge` (`volLen`, `volMult`)
`Avoid Ultra-Low Vol` (`Min BB Width %`)
`Session` window
Risk / Exits
`ATR Length`, `ATR Stop Multiplier`
`Take Profit at 1R` (with Partial 50%)
`Chandelier` (`chLen`, `chMult`)
Optional `Time Stop (bars)`
🎯 Entry & Exit Rules
Entry (choose one mode):
1. Release + Momentum (default)
Long: on the bar the squeeze releases and `mom > 0`, passing all enabled filters.
Short: on the bar the squeeze releases and `mom < 0`, passing filters.
2. Band Break + Momentum
Long: `close > BB_Upper` and `mom > 0`, with filters.
Short: `close < BB_Lower` and `mom < 0`, with filters.
Initial Stop
ATR-based: `Stop Distance = atrMult × ATR(atrLen)` from entry.
Targets & Runner
TP1 at 1R (optional): take 50% at `entry + 1R` (long) / `entry − 1R` (short).
Runner: remaining position trails a Chandelier stop:
Long trail = `highest(high, chLen) − chMult × ATR`
Short trail = `lowest(low, chLen) + chMult × ATR`
Optional Time Stop: close the trade after N bars in position.
Labels on chart
“Long” / “Short” = entry signals.
“L-TP1 / S-TP1” = partial exits at 1R.
“L-Runner / S-Runner” = trailing-stop exits of the runner.
Alerts
Provided for Long Entry, Short Entry, and Squeeze Release.
💬 How to use
1. Choose your market/timeframe (e.g., NSE 5–15m intraday, 60m–Daily for swing).
2. If you prefer cleaner trends, enable the HTF EMA filter (e.g., 240m/1D).
3. For intraday, consider Band Break + Momentum with Volume Surge and a small Min BB Width.
4. Adjust ATR/Chandelier multipliers to fit your risk tolerance and instrument.
Abbreviations
BB – Bollinger Bands
KC – Keltner Channels
ATR – Average True Range
SMA / EMA – Simple/Exponential Moving Average
HTF – Higher Timeframe
R – Risk unit (equal to the initial stop distance)
⚠️ Disclaimer
This script is for educational purposes only. Past performance ≠ future returns. Always paper trade first. Options trading carries high risk — manage exposure responsibly.
Squeeze Breakout strategy looks for volatility compression (Bollinger Bands inside Keltner Channels = a “squeeze”), then trades the volatility expansion in the direction of a momentum filter.
🧠 How the “Squeeze → Expansion” works
- Markets alternate between quiet (compressed) and active (expanded) phases.
- We call it a squeeze when Bollinger Bands (BB)—which reflect standard deviation around price—shrink inside the Keltner Channels (KC)—which reflect ATR/range.
- This means dispersion (stdev) is small relative to typical range (ATR). Price is coiling; participants are agreeing on value.
- When BB pops back outside KC, the squeeze releases. That’s the first sign that volatility is expanding again.
- A release alone doesn’t tell you direction. That’s why this strategy pairs the release with a momentum filter:
- We estimate momentum using a smoothed linear-regression slope of price (a clean proxy for acceleration).
- If the slope is positive at release, we favor longs; if negative, we favor shorts.
- Optionally, you can require Band Break + Momentum (price closes beyond the BB) for a stricter entry.
- This combination aims to capture the first leg of the range-to-trend transition while avoiding random pokes that often occur during tight consolidations.
💡 Why this is unique
Two entry modes (toggle):
1. Release + Momentum (enter when the squeeze turns off)
2. Band Break + Momentum (enter on a close beyond BB with momentum)
- Momentum = smoothed linear-regression slope, a clean thrust detector that’s less laggy than many oscillators.
- Risk module included: ATR stop, optional 1R partial take-profit, and a Chandelier trailing stop for the runner.
- Practical filters: higher-timeframe EMA trend alignment, volume surge, minimum BB width, and session window—so it adapts across markets/timeframes.
- Backtest-ready: uses TradingView’s `strategy.` framework with commission/slippage controls.
📈 How it helps traders
✅Regime clarity: distinguishes compression vs. expansion so you’re not forcing trades during dead zones.
✅Objective entries: momentum + band logic reduces discretionary “feel” and late chases.
✅Built-in risk plan: stop/targets/trailing defined in inputs—consistent execution across tickers.
✅Adaptable: works across instruments/timeframes; filters let you tailor noise tolerance per market session.
✅Alerts: real-time signals for entry and squeeze release.
✅Not a Mash-Up / Original Work
✅Fully authored in Pine Script v6; no external libraries or copied logic blocks.
✅Uses well-known, documented formulas (BB, KC, ATR, LinReg slope) combined into a new rule set (two entry modes + momentum + structured exits).
✅Code and parameters are transparent and adjustable; the script stands alone.
🧩 Formulas (core)
Bollinger Bands
# Basis = `SMA(close, bbLen)`
# Upper/Lower = `Basis ± bbMult × stdev(close, bbLen)`
# Width% = `(Upper − Lower) / Basis × 100`
Keltner Channels
# Basis = `EMA(close, kcLen)`
# Upper/Lower = `Basis ± kcMult × ATR(kcATR)`
Squeeze state
# ON: `BB_Upper < KC_Upper` and `BB_Lower > KC_Lower`
# Release: `squeeze_on[1]` and `not squeeze_on`
Momentum (this script)
# `lin = linreg(close, momLen, 0)`
# `mom = SMA( lin − lin[1], momSmoothing )`
# Long bias when `mom > 0`; short bias when `mom < 0`.
⚙️ Inputs
Compression
`bbLen`, `bbMult` — BB length & std-dev multiplier
`kcLen`, `kcATR`, `kcMult` — KC lengths & ATR multiplier
`Entry Mode` — Release + Momentum, Band Break + Momentum, or Either
Momentum
`momLen`, `momSmoothing`
Filters (optional)
`Use HTF Trend Filter` + `HTF Timeframe` + `HTF EMA Length`
`Require Volume Surge` (`volLen`, `volMult`)
`Avoid Ultra-Low Vol` (`Min BB Width %`)
`Session` window
Risk / Exits
`ATR Length`, `ATR Stop Multiplier`
`Take Profit at 1R` (with Partial 50%)
`Chandelier` (`chLen`, `chMult`)
Optional `Time Stop (bars)`
🎯 Entry & Exit Rules
Entry (choose one mode):
1. Release + Momentum (default)
Long: on the bar the squeeze releases and `mom > 0`, passing all enabled filters.
Short: on the bar the squeeze releases and `mom < 0`, passing filters.
2. Band Break + Momentum
Long: `close > BB_Upper` and `mom > 0`, with filters.
Short: `close < BB_Lower` and `mom < 0`, with filters.
Initial Stop
ATR-based: `Stop Distance = atrMult × ATR(atrLen)` from entry.
Targets & Runner
TP1 at 1R (optional): take 50% at `entry + 1R` (long) / `entry − 1R` (short).
Runner: remaining position trails a Chandelier stop:
Long trail = `highest(high, chLen) − chMult × ATR`
Short trail = `lowest(low, chLen) + chMult × ATR`
Optional Time Stop: close the trade after N bars in position.
Labels on chart
“Long” / “Short” = entry signals.
“L-TP1 / S-TP1” = partial exits at 1R.
“L-Runner / S-Runner” = trailing-stop exits of the runner.
Alerts
Provided for Long Entry, Short Entry, and Squeeze Release.
💬 How to use
1. Choose your market/timeframe (e.g., NSE 5–15m intraday, 60m–Daily for swing).
2. If you prefer cleaner trends, enable the HTF EMA filter (e.g., 240m/1D).
3. For intraday, consider Band Break + Momentum with Volume Surge and a small Min BB Width.
4. Adjust ATR/Chandelier multipliers to fit your risk tolerance and instrument.
Abbreviations
BB – Bollinger Bands
KC – Keltner Channels
ATR – Average True Range
SMA / EMA – Simple/Exponential Moving Average
HTF – Higher Timeframe
R – Risk unit (equal to the initial stop distance)
⚠️ Disclaimer
This script is for educational purposes only. Past performance ≠ future returns. Always paper trade first. Options trading carries high risk — manage exposure responsibly.
Script de código abierto
Siguiendo fielmente el espíritu de TradingView, el creador de este script lo ha publicado en código abierto, permitiendo que otros traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Puede utilizarlo de forma gratuita, pero tenga en cuenta que la publicación de este código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.
Script de código abierto
Siguiendo fielmente el espíritu de TradingView, el creador de este script lo ha publicado en código abierto, permitiendo que otros traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Puede utilizarlo de forma gratuita, pero tenga en cuenta que la publicación de este código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.