OPEN-SOURCE SCRIPT

Market Regime Detection – Breakout/down w/ ADX & EMA Filter

192
Market Regime Detection – Breakout/down w/ ADX & EMA Filter
By: alphainvestor123

This indicator helps you visually detect whether the market is in a trending or mean-reverting regime by combining:

Core Logic:
Breakouts: Price exceeds recent highs (or lows), suggesting trending behavior.

EMA Filter: Confirms bullish or bearish bias based on price vs. EMA.

VHF (Vertical Horizontal Filter): Measures the trend strength.

VHF value is multiplied by 1000 in the event you wish to display it onto your
BTC
or Crypto chart, it will be visible on your chart, no need to scroll down to see.

VHF ≥ 3333 = Trending Regime

VHF ≤ 3333 = Mean-Reverting / Rangebound

Key Features:
- Plot of recent high/low breakout levels.

- Background highlights breakout signals (trending market).

- Optional background for breakdown signals (non-trending market).

- Optional VHF and EMA plots for further confirmation.

- Adjustable inputs to control signal sensitivity and chart visuals.

Inputs:
Lookback Periods for breakout/breakdown

EMA Length and Line Thickness

Toggle VHF/EMA/Signal Display

Custom Colors for bullish/bearish trends

Ideal Use Cases:
Determining market regime

Filtering for momentum/trend continuation setups

Avoiding false signals in mean-reverting market conditions

*Best used on 1D chart as seen on the sample display, I find this most useful for detecting long term trend breakouts/breakdowns and mean reverting regimes.

*to clarify:
breakouts/trend regimes can only be marked if:
1. Candle has the highest high out of the last 40 bars (default indicator setting, can be customized by user)
2. EMA on the desired asset is bullish
3. ADX is >= a value of 3,333

Visa versa logic for breakdowns/mean reverting regime detection.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.