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 อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน