PROTECTED SOURCE SCRIPT
AlphaMACD - Adaptive MACD with Efficiency Ratio

OVERVIEW
AlphaMACD is an adaptive implementation of the classic MACD indicator that dynamically adjusts its calculation periods based on market efficiency. Unlike traditional MACD which uses fixed periods (typically 12, 26, 9), this indicator adapts its fast and slow EMA periods in real-time based on how efficiently the market is trending.
WHAT MAKES THIS ORIGINAL
This is not a simple MACD with different settings or colors. The core innovation is the adaptive period calculation using Kaufman's Efficiency Ratio, which was originally developed for the Adaptive Moving Average (AMA). This indicator applies that adaptive logic to MACD itself.
Key Differences from Standard MACD:
- Periods dynamically adjust between user-defined ranges (default: 8-21 for fast, 21-55 for slow)
- Uses Kaufman's Efficiency Ratio to measure market trendiness
- Implements gap protection to prevent extreme spikes from market gaps
- Includes market regime detection to filter signals in choppy conditions
- Provides multi-timeframe trend confirmation
HOW IT WORKS
1. Efficiency Ratio Calculation:
The indicator calculates market efficiency by comparing the absolute price change over a period to the sum of absolute price changes within that period. High efficiency = strong trending market. Low efficiency = choppy/sideways market.
2. Adaptive Period Adjustment:
- In trending markets (high efficiency): Periods move toward the minimum values for faster response
- In choppy markets (low efficiency): Periods move toward the maximum values for slower, more stable signals
- The "Sensitivity" parameter controls how aggressively periods adapt (0.5 to 5.0)
3. Gap Protection:
The custom adaptive EMA function detects abnormal price gaps (moves larger than 3x the typical ATR-based change) and limits their impact on the calculation. This prevents weekends or news gaps from causing extreme MACD spikes.
4. Signal Quality Filtering:
- Market regime detection identifies trending vs sideways conditions
- Momentum filter (RSI-based) prevents signals during overextended moves
- Signal strength calculation helps identify high-confidence setups
- Sideways market signals are marked with warning symbols
5. Multi-Timeframe Analysis:
The indicator compares current timeframe MACD with a higher timeframe (default 60 min) to provide context and filter against-trend signals.
HOW TO USE IT
Settings:
- Core Settings: Define the minimum and maximum periods for fast/slow EMAs
- Sensitivity: Higher values make the indicator more responsive to market changes
- Multi-timeframe: Set a higher timeframe for trend confirmation
- Visual options: Customize appearance and enable/disable features
Signal Interpretation:
- Strong bullish/bearish signals (large triangles): High-confidence entries in trending markets
- Warning signals (small ⚠): Crossovers in sideways markets - use caution or skip
- Divergence labels ("DIV"): Price and MACD diverging - potential reversal
- Background color: Green tint = trending market, Orange tint = sideways market
The Information Table shows:
- Current market regime (trending or sideways)
- Market efficiency percentage (how clean the trend is)
- Current adaptive fast and slow periods
- Higher timeframe trend direction
- Current signal strength
Best Practices:
- In trending markets: Trust strong signals, avoid warning signals
- In sideways markets: Reduce position sizes or skip trades entirely
- Use higher timeframe confirmation for better signal quality
- Adjust sensitivity based on your trading timeframe (higher for intraday, lower for swing)
TECHNICAL DETAILS
Calculation Method:
- Efficiency Ratio = ABS(Close - Close[Period]) / SUM(ABS(Close - Close[1]), Period)
- Smoothed Efficiency = EMA(Efficiency Ratio, 5)
- Fast Period = Fast_Min + (Fast_Max - Fast_Min) × (1 - Smoothed_Efficiency × Sensitivity)
- Slow Period = Slow_Min + (Slow_Max - Slow_Min) × (1 - Smoothed_Efficiency × Sensitivity)
- Adaptive EMA uses standard EMA formula with gap detection and limiting
- MACD = Fast Adaptive EMA - Slow Adaptive EMA
- Signal = EMA(MACD, Signal Period)
- Histogram = MACD - Signal
The adaptive periods are calculated on every bar, so the MACD responds faster in trending conditions and stabilizes during consolidation.
WHAT THIS SOLVES
Standard MACD Problems:
- Fixed periods don't adapt to changing market conditions
- Too many false signals in sideways markets
- Whipsaws during low-volatility consolidation
- Price gaps can cause misleading spikes
AlphaMACD Solutions:
- Periods automatically adjust to market state
- Market regime filter identifies and warns about sideways conditions
- Adaptive smoothing reduces whipsaws
- Gap protection prevents false extremes
LIMITATIONS
- Like all indicators, this does not predict the future
- Requires trending markets for optimal performance
- Adaptive calculation means backtesting results will differ from fixed-period MACD
- More complex than standard MACD - requires understanding of adaptive concepts
- The adaptive periods mean you cannot directly compare this to traditional MACD studies
This indicator is best used as part of a complete trading system, not as a standalone signal generator.
EDUCATIONAL VALUE
For traders learning about:
- Adaptive indicators and market efficiency concepts
- Kaufman's Adaptive Moving Average principles applied to oscillators
- Market regime detection and signal filtering
- Gap handling in technical indicators
- Multi-timeframe analysis integration
Not Financial advice.
AlphaMACD is an adaptive implementation of the classic MACD indicator that dynamically adjusts its calculation periods based on market efficiency. Unlike traditional MACD which uses fixed periods (typically 12, 26, 9), this indicator adapts its fast and slow EMA periods in real-time based on how efficiently the market is trending.
WHAT MAKES THIS ORIGINAL
This is not a simple MACD with different settings or colors. The core innovation is the adaptive period calculation using Kaufman's Efficiency Ratio, which was originally developed for the Adaptive Moving Average (AMA). This indicator applies that adaptive logic to MACD itself.
Key Differences from Standard MACD:
- Periods dynamically adjust between user-defined ranges (default: 8-21 for fast, 21-55 for slow)
- Uses Kaufman's Efficiency Ratio to measure market trendiness
- Implements gap protection to prevent extreme spikes from market gaps
- Includes market regime detection to filter signals in choppy conditions
- Provides multi-timeframe trend confirmation
HOW IT WORKS
1. Efficiency Ratio Calculation:
The indicator calculates market efficiency by comparing the absolute price change over a period to the sum of absolute price changes within that period. High efficiency = strong trending market. Low efficiency = choppy/sideways market.
2. Adaptive Period Adjustment:
- In trending markets (high efficiency): Periods move toward the minimum values for faster response
- In choppy markets (low efficiency): Periods move toward the maximum values for slower, more stable signals
- The "Sensitivity" parameter controls how aggressively periods adapt (0.5 to 5.0)
3. Gap Protection:
The custom adaptive EMA function detects abnormal price gaps (moves larger than 3x the typical ATR-based change) and limits their impact on the calculation. This prevents weekends or news gaps from causing extreme MACD spikes.
4. Signal Quality Filtering:
- Market regime detection identifies trending vs sideways conditions
- Momentum filter (RSI-based) prevents signals during overextended moves
- Signal strength calculation helps identify high-confidence setups
- Sideways market signals are marked with warning symbols
5. Multi-Timeframe Analysis:
The indicator compares current timeframe MACD with a higher timeframe (default 60 min) to provide context and filter against-trend signals.
HOW TO USE IT
Settings:
- Core Settings: Define the minimum and maximum periods for fast/slow EMAs
- Sensitivity: Higher values make the indicator more responsive to market changes
- Multi-timeframe: Set a higher timeframe for trend confirmation
- Visual options: Customize appearance and enable/disable features
Signal Interpretation:
- Strong bullish/bearish signals (large triangles): High-confidence entries in trending markets
- Warning signals (small ⚠): Crossovers in sideways markets - use caution or skip
- Divergence labels ("DIV"): Price and MACD diverging - potential reversal
- Background color: Green tint = trending market, Orange tint = sideways market
The Information Table shows:
- Current market regime (trending or sideways)
- Market efficiency percentage (how clean the trend is)
- Current adaptive fast and slow periods
- Higher timeframe trend direction
- Current signal strength
Best Practices:
- In trending markets: Trust strong signals, avoid warning signals
- In sideways markets: Reduce position sizes or skip trades entirely
- Use higher timeframe confirmation for better signal quality
- Adjust sensitivity based on your trading timeframe (higher for intraday, lower for swing)
TECHNICAL DETAILS
Calculation Method:
- Efficiency Ratio = ABS(Close - Close[Period]) / SUM(ABS(Close - Close[1]), Period)
- Smoothed Efficiency = EMA(Efficiency Ratio, 5)
- Fast Period = Fast_Min + (Fast_Max - Fast_Min) × (1 - Smoothed_Efficiency × Sensitivity)
- Slow Period = Slow_Min + (Slow_Max - Slow_Min) × (1 - Smoothed_Efficiency × Sensitivity)
- Adaptive EMA uses standard EMA formula with gap detection and limiting
- MACD = Fast Adaptive EMA - Slow Adaptive EMA
- Signal = EMA(MACD, Signal Period)
- Histogram = MACD - Signal
The adaptive periods are calculated on every bar, so the MACD responds faster in trending conditions and stabilizes during consolidation.
WHAT THIS SOLVES
Standard MACD Problems:
- Fixed periods don't adapt to changing market conditions
- Too many false signals in sideways markets
- Whipsaws during low-volatility consolidation
- Price gaps can cause misleading spikes
AlphaMACD Solutions:
- Periods automatically adjust to market state
- Market regime filter identifies and warns about sideways conditions
- Adaptive smoothing reduces whipsaws
- Gap protection prevents false extremes
LIMITATIONS
- Like all indicators, this does not predict the future
- Requires trending markets for optimal performance
- Adaptive calculation means backtesting results will differ from fixed-period MACD
- More complex than standard MACD - requires understanding of adaptive concepts
- The adaptive periods mean you cannot directly compare this to traditional MACD studies
This indicator is best used as part of a complete trading system, not as a standalone signal generator.
EDUCATIONAL VALUE
For traders learning about:
- Adaptive indicators and market efficiency concepts
- Kaufman's Adaptive Moving Average principles applied to oscillators
- Market regime detection and signal filtering
- Gap handling in technical indicators
- Multi-timeframe analysis integration
Not Financial advice.
Skrip dilindungi
Skrip ini diterbitkan sebagai sumber tertutup. Akan tetapi, anda boleh menggunakannya dengan percuma dan tanpa had – ketahui lebih lanjut di sini.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.
Skrip dilindungi
Skrip ini diterbitkan sebagai sumber tertutup. Akan tetapi, anda boleh menggunakannya dengan percuma dan tanpa had – ketahui lebih lanjut di sini.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.