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.
Script open-source
Nello spirito di TradingView, l'autore di questo script lo ha reso open source, in modo che i trader possano esaminarne e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricordiamo che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.
Script open-source
Nello spirito di TradingView, l'autore di questo script lo ha reso open source, in modo che i trader possano esaminarne e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricordiamo che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.