OPEN-SOURCE SCRIPT
Emac ML Adaptive Crossover

The HDAlgos EMAC ML Adaptive Crossover is an adaptive trend reading and crossover system that uses a lightweight machine learning style scoring engine to detect regime shifts in the market. It blends multiple normalised technical features and automatically adjusts EMA lengths based on the detected market regime.
How it works
Feature Engine
The script computes several normalised indicators including RSI, ATR percentage, and Rate of Change. Each feature is converted into a z score so that the values behave consistently across different markets and timeframes. These feature values are then averaged to form a composite regime score.
Regime Detection
The composite score is compared to a dynamic upper and lower threshold. If the score rises above the upper boundary the regime becomes bullish. If the score falls below the lower boundary it becomes bearish. If it stays between the two boundaries the market is classified as neutral.
Adaptive EMAs
The fast and slow EMA lengths are automatically adjusted depending on the detected regime.
• In bullish regimes the fast and slow EMAs shorten.
• In bearish regimes they lengthen.
• In neutral regimes they revert to their base lengths.
This creates an EMA crossover system that responds to market volatility and directional strength rather than using fixed lookback values.
Crossovers
When the adaptive fast EMA crosses above the adaptive slow EMA, a bullish signal appears. When it crosses below, a bearish signal appears.
Visual Aids
• The fast EMA changes color to reflect the current regime.
• Candles can be optionally painted in regime colors.
• A label on the last bar shows the detected regime, score, and active EMA lengths.
• A compact table can be shown in the corner summarizing regime state and metrics.
Alerts
Alerts trigger when the regime changes, when a bullish adaptive crossover occurs, and when a bearish adaptive crossover occurs.
What it is designed for
This indicator is built for traders who want a crossover system that adapts to real market conditions instead of reacting to fixed length EMAs. It provides:
Smoother identification of trend phases
Dynamic sensitivity during strong conditions
Dampened reactions during noise and low conviction periods
Clear and simple signals that remain easy to interpret
How it works
Feature Engine
The script computes several normalised indicators including RSI, ATR percentage, and Rate of Change. Each feature is converted into a z score so that the values behave consistently across different markets and timeframes. These feature values are then averaged to form a composite regime score.
Regime Detection
The composite score is compared to a dynamic upper and lower threshold. If the score rises above the upper boundary the regime becomes bullish. If the score falls below the lower boundary it becomes bearish. If it stays between the two boundaries the market is classified as neutral.
Adaptive EMAs
The fast and slow EMA lengths are automatically adjusted depending on the detected regime.
• In bullish regimes the fast and slow EMAs shorten.
• In bearish regimes they lengthen.
• In neutral regimes they revert to their base lengths.
This creates an EMA crossover system that responds to market volatility and directional strength rather than using fixed lookback values.
Crossovers
When the adaptive fast EMA crosses above the adaptive slow EMA, a bullish signal appears. When it crosses below, a bearish signal appears.
Visual Aids
• The fast EMA changes color to reflect the current regime.
• Candles can be optionally painted in regime colors.
• A label on the last bar shows the detected regime, score, and active EMA lengths.
• A compact table can be shown in the corner summarizing regime state and metrics.
Alerts
Alerts trigger when the regime changes, when a bullish adaptive crossover occurs, and when a bearish adaptive crossover occurs.
What it is designed for
This indicator is built for traders who want a crossover system that adapts to real market conditions instead of reacting to fixed length EMAs. It provides:
Smoother identification of trend phases
Dynamic sensitivity during strong conditions
Dampened reactions during noise and low conviction periods
Clear and simple signals that remain easy to interpret
Script de código abierto
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
hdalgos.com for Trade Analysis and Indicators
Developed by former Goldman Sachs Trader
Developed by former Goldman Sachs Trader
Exención de responsabilidad
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.
Script de código abierto
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
hdalgos.com for Trade Analysis and Indicators
Developed by former Goldman Sachs Trader
Developed by former Goldman Sachs Trader
Exención de responsabilidad
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.