OPEN-SOURCE SCRIPT
EMA Squeeze and Market State Engine

EMA Squeeze & Market State Engine
I wanted to create a trend indicator that was all encompassing for Trend Analysis and Market state using identified methods for distinguishing Ranging Markets and areas that are in a Squeeze to filter out signals from my other indicators.
Default EMA of 21 is used as I scalp on a 1 minute chart.
EMA Squeeze & Market State is designed to classify market behaviour rather than generate buy or sell signals.
Instead of relying solely on a moving average crossover, the indicator evaluates:
• 21 EMA trend direction
• EMA slope strength
• Bollinger Band compression
• Keltner Channel compression
• ATR-normalised price movement
• Price distance from the EMA
The result is a continuously changing market-state engine that helps identify when the market is:
🟢 Bullish
🔴 Bearish
🟡 Volatility Squeeze
⚪ Range / Neutral
Features:
✓ 21 EMA with automatic state colouring
✓ Bollinger/Keltner squeeze detection
✓ ATR-normalised EMA slope
✓ Range detection using EMA flatness
✓ Bottom squeeze markers
✓ Bottom range markers
✓ Optional background colouring
✓ TradingView alerts
Market States
Bullish (Green):
The EMA is rising with sufficient slope and price is positioned correctly relative to the EMA.
Suitable for long-biased strategies.
Bearish (Red):
The EMA is falling with sufficient slope and price is positioned correctly relative to the EMA.
Suitable for short-biased strategies.
Squeeze (Yellow):
Occurs when the Bollinger Bands contract inside the Keltner Channel.
Typically represents volatility compression before expansion.
Range / Neutral (Grey):
The EMA is relatively flat and price remains close to the EMA.
Useful for avoiding trades during sideways conditions.
Inputs
The indicator includes adjustable parameters for
• EMA Length
• Bollinger Bands
• Keltner Channels
• ATR Length
• EMA Slope
• Range Detection
• Trend Detection
• Display Options
Alerts
Alerts are available for:
• Squeeze Started
• Squeeze Ended
• Range Started
• Bullish State Started
• Bearish State Started
Intended Use
This indicator is intended as a market-state filter and works well alongside trend-following systems, breakout strategies and discretionary analysis.
It does not generate trade entries.
Future Development:
Future versions may include
• Multi-timeframe confirmation
• Trend strength scoring
• Adaptive EMA length
• Institutional participation filters
• Strategy mode
Attribution:
This indicator implements well-known technical analysis concepts including the Exponential Moving Average (EMA), Bollinger Bands, Keltner Channels and Average True Range (ATR). The implementation and market-state engine are original.
I wanted to create a trend indicator that was all encompassing for Trend Analysis and Market state using identified methods for distinguishing Ranging Markets and areas that are in a Squeeze to filter out signals from my other indicators.
Default EMA of 21 is used as I scalp on a 1 minute chart.
EMA Squeeze & Market State is designed to classify market behaviour rather than generate buy or sell signals.
Instead of relying solely on a moving average crossover, the indicator evaluates:
• 21 EMA trend direction
• EMA slope strength
• Bollinger Band compression
• Keltner Channel compression
• ATR-normalised price movement
• Price distance from the EMA
The result is a continuously changing market-state engine that helps identify when the market is:
🟢 Bullish
🔴 Bearish
🟡 Volatility Squeeze
⚪ Range / Neutral
Features:
✓ 21 EMA with automatic state colouring
✓ Bollinger/Keltner squeeze detection
✓ ATR-normalised EMA slope
✓ Range detection using EMA flatness
✓ Bottom squeeze markers
✓ Bottom range markers
✓ Optional background colouring
✓ TradingView alerts
Market States
Bullish (Green):
The EMA is rising with sufficient slope and price is positioned correctly relative to the EMA.
Suitable for long-biased strategies.
Bearish (Red):
The EMA is falling with sufficient slope and price is positioned correctly relative to the EMA.
Suitable for short-biased strategies.
Squeeze (Yellow):
Occurs when the Bollinger Bands contract inside the Keltner Channel.
Typically represents volatility compression before expansion.
Range / Neutral (Grey):
The EMA is relatively flat and price remains close to the EMA.
Useful for avoiding trades during sideways conditions.
Inputs
The indicator includes adjustable parameters for
• EMA Length
• Bollinger Bands
• Keltner Channels
• ATR Length
• EMA Slope
• Range Detection
• Trend Detection
• Display Options
Alerts
Alerts are available for:
• Squeeze Started
• Squeeze Ended
• Range Started
• Bullish State Started
• Bearish State Started
Intended Use
This indicator is intended as a market-state filter and works well alongside trend-following systems, breakout strategies and discretionary analysis.
It does not generate trade entries.
Future Development:
Future versions may include
• Multi-timeframe confirmation
• Trend strength scoring
• Adaptive EMA length
• Institutional participation filters
• Strategy mode
Attribution:
This indicator implements well-known technical analysis concepts including the Exponential Moving Average (EMA), Bollinger Bands, Keltner Channels and Average True Range (ATR). The implementation and market-state engine are original.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.