OPEN-SOURCE SCRIPT
Market Condition Oscillator [HexaTrades]

Market Condition Oscillator classifies price action into three simple states: Bullish Trend, Bearish Trend, and Consolidation, and paints them as a color-coded histogram below your chart. It is built to answer one question at a glance: should I be trend-trading right now, or is the market just chopping sideways?
What it shows
🟢 Green histogram above zero → confirmed bullish trend. Taller bars = stronger trend.
🔴 Red histogram below zero → confirmed bearish trend. Deeper bars = stronger trend.
⚪ Gray histogram near zero → consolidation/range (no clear trend).
How it works
The indicator combines four classic, well-understood concepts so that no single signal can produce a false trend on its own:
1. ADX (trend strength): measures how strongly the market is trending. Below the threshold, the market is treated as consolidation regardless of direction.
2. DI+ / DI− (direction) : the Directional Movement pair decides whether strength is to the upside or downside.
3. EMA position + slope (confirmation) : price must be on the correct side of the EMA and the EMA must be sloping the right way. This filters out counter-trend spikes.
4. ATR & EMA-distance (range detection) : consolidation is flagged when volatility compresses or price hugs the EMA, even if ADX hasn't fully dropped yet.
A phase only changes after the condition holds for a configurable number of candles (Confirmation Bars). This is the key to removing the constant flip-flopping that plagues most trend indicators.
Trend rules
✏️ Bullish = ADX above threshold and DI+ > DI− and price above EMA and EMA rising — held for N bars.
✏️Bearish = ADX above threshold and DI− > DI+ and price below EMA and EMA falling — held for N bars.
✏️Consolidation = weak ADX, or compressed ATR, or price hugging the EMA — anything that is not a confirmed trend.
Features
- Bullish, bearish, and consolidation market phase detection.
- Separate oscillator panel for clean chart reading.
- Color-coded histogram.
- Optional histogram smoothing.
- Confirmation bars to reduce false flips.
- Phase label on the latest candle.
- Legend table for easy interpretation.
- Alert conditions for bullish, bearish, consolidation, and trend-flip events.
- Uses confirmed candle data only and does not use future references.
How to use it
- Trend traders: only take longs while the histogram is green, shorts while it is red. Stand aside on gray.
- Mean-reversion traders: the gray phase highlights range conditions where fade/scalp setups work best.
- Filter: combine with your existing entry system and ignore signals that fight the MCO color.
- Works on any market and any timeframe. For higher timeframes, consider raising the ADX threshold and Confirmation Bars.
Alerts
Five ready-to-use alert conditions:
Bullish Trend Started
Bearish Trend Started
Consolidation Started
Bullish → Bearish Shift
Bearish → Bullish Shift
This indicator is designed to help identify market conditions. It should be combined with price action, support and resistance, volume, and proper risk management. No indicator can guarantee profitable trades.
We would love to hear your suggestions. If you have ideas for new features, indicators, analytics, or improvements, please share your feedback. Your input helps guide future updates and improve the indicator for all traders.
This indicator is for educational and analytical purposes only. It should not be considered financial advice. Always use proper risk management and make trading decisions based on your own analysis
What it shows
🟢 Green histogram above zero → confirmed bullish trend. Taller bars = stronger trend.
🔴 Red histogram below zero → confirmed bearish trend. Deeper bars = stronger trend.
⚪ Gray histogram near zero → consolidation/range (no clear trend).
How it works
The indicator combines four classic, well-understood concepts so that no single signal can produce a false trend on its own:
1. ADX (trend strength): measures how strongly the market is trending. Below the threshold, the market is treated as consolidation regardless of direction.
2. DI+ / DI− (direction) : the Directional Movement pair decides whether strength is to the upside or downside.
3. EMA position + slope (confirmation) : price must be on the correct side of the EMA and the EMA must be sloping the right way. This filters out counter-trend spikes.
4. ATR & EMA-distance (range detection) : consolidation is flagged when volatility compresses or price hugs the EMA, even if ADX hasn't fully dropped yet.
A phase only changes after the condition holds for a configurable number of candles (Confirmation Bars). This is the key to removing the constant flip-flopping that plagues most trend indicators.
Trend rules
✏️ Bullish = ADX above threshold and DI+ > DI− and price above EMA and EMA rising — held for N bars.
✏️Bearish = ADX above threshold and DI− > DI+ and price below EMA and EMA falling — held for N bars.
✏️Consolidation = weak ADX, or compressed ATR, or price hugging the EMA — anything that is not a confirmed trend.
Features
- Bullish, bearish, and consolidation market phase detection.
- Separate oscillator panel for clean chart reading.
- Color-coded histogram.
- Optional histogram smoothing.
- Confirmation bars to reduce false flips.
- Phase label on the latest candle.
- Legend table for easy interpretation.
- Alert conditions for bullish, bearish, consolidation, and trend-flip events.
- Uses confirmed candle data only and does not use future references.
How to use it
- Trend traders: only take longs while the histogram is green, shorts while it is red. Stand aside on gray.
- Mean-reversion traders: the gray phase highlights range conditions where fade/scalp setups work best.
- Filter: combine with your existing entry system and ignore signals that fight the MCO color.
- Works on any market and any timeframe. For higher timeframes, consider raising the ADX threshold and Confirmation Bars.
Alerts
Five ready-to-use alert conditions:
Bullish Trend Started
Bearish Trend Started
Consolidation Started
Bullish → Bearish Shift
Bearish → Bullish Shift
This indicator is designed to help identify market conditions. It should be combined with price action, support and resistance, volume, and proper risk management. No indicator can guarantee profitable trades.
We would love to hear your suggestions. If you have ideas for new features, indicators, analytics, or improvements, please share your feedback. Your input helps guide future updates and improve the indicator for all traders.
This indicator is for educational and analytical purposes only. It should not be considered financial advice. Always use proper risk management and make trading decisions based on your own analysis
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
🚀Telegram : t.me/hexatrades
🌐Website: hexatrades.io/
🗣️Twitter(X): twitter.com/HexaTrades
🌐Website: hexatrades.io/
🗣️Twitter(X): twitter.com/HexaTrades
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
🚀Telegram : t.me/hexatrades
🌐Website: hexatrades.io/
🗣️Twitter(X): twitter.com/HexaTrades
🌐Website: hexatrades.io/
🗣️Twitter(X): twitter.com/HexaTrades
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。