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.
開源腳本
秉持TradingView一貫精神,這個腳本的創作者將其設為開源,以便交易者檢視並驗證其功能。向作者致敬!您可以免費使用此腳本,但請注意,重新發佈代碼需遵守我們的社群規範。
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。
開源腳本
秉持TradingView一貫精神,這個腳本的創作者將其設為開源,以便交易者檢視並驗證其功能。向作者致敬!您可以免費使用此腳本,但請注意,重新發佈代碼需遵守我們的社群規範。
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。