MACD Advanced: Trend-Weighted MomentumMACD Advanced Overview
MACD Advanced is a refined version of the classic Moving Average Convergence Divergence. While the standard MACD identifies changes in momentum, it often produces false signals in ranging markets or against a strong higher-timeframe trend. This script addresses that by "tilting" the MACD calculation based on the slope of a Higher Timeframe (HTF) Moving Average.
How it Works
The script integrates a Trend Bias Factor derived from the rate of change of a long-period EMA (default 200) from a user-defined timeframe.
The Math: It calculates the ratio between the current HTF EMA and its value $n$ bars ago. This ratio is then used to offset the MACD line.
Bullish Bias: If the HTF EMA is sloping upward, the MACD is shifted higher, making bearish crossovers harder to trigger and bullish ones more sensitive.
Bearish Bias: If the HTF EMA is sloping downward, the MACD is dragged lower, prioritizing short-side momentum.
Key Features
MTF Integration: Analyze the daily trend while trading on the 5m or 15m chart.
Dynamic Histogram: The visual fill between the MACD and its momentum provides a clear look at when momentum is accelerating or exhausting relative to the trend.
Customizable Sensitivity: Adjust the lookback period for the trend slope to match your specific asset’s volatility.
How to Trade
Trend Confirmation: Look for the MACD line (the columns) to cross the zero line. This indicates that both short-term momentum and long-term trend are in alignment.
Momentum Exhaustion: When the inner histogram (the fill) begins to shrink back toward the MACD columns, it suggests a potential pull-back or profit-taking zone.
Divergences: Look for price making a new high while the MACD Advanced makes a lower high; the trend-weighting makes these divergences more prominent during trend exhaustion.
Technical Approach
Normalization of MTF Data: The script uses request.security with barmerge.gaps_off to ensure that higher timeframe data is mapped correctly to the current chart bars without creating visual "steps" or "staircases."
The Delta Calculation: Instead of a simple boolean filter,
we calculate a relative value r = EMA_ current/EMA_ lookback
By adding r - 1 to the standard MACD calculation, we create a non-linear offset. This means the more aggressive the trend, the more the MACD is displaced.
Visual Architecture: The script uses two plot outputs (g1 and g2) and a fill() function. This creates a "ribbon" effect that is more intuitive than the standard "centered" histogram, as it shows momentum relative to the trend-weighted line rather than a static zero axis.
Since this version of the MACD is "weighted" by a higher-timeframe trend, it changes how you read common signals. On a standard chart, the MACD just shows momentum; here, it shows momentum relative to the "big picture" slope.
Here is how to effectively use the MACD Advanced on a live chart:
1. Finding the "Trend-Momentum" Alignment
The most powerful signal from this indicator occurs when the Trend Factor and the Momentum Histogram both agree.
The Bullish Setup: Look for the MACD columns (the "base") to be above the zero line, while the inner fill (the "histogram") is bright green.
Interpretation: The Daily trend is up, and the intraday momentum is also accelerating.The
Bearish Setup: Look for the MACD columns to be below the zero line, while the inner fill is bright red.
Interpretation: The Daily trend is down, and intraday selling pressure is increasing.
2. Reading the "Hidden" Divergence
Because we’ve added a trend offset r-1, this indicator identifies "Trend Exhaustion" better than a standard MACD.
Standard Divergence: Price makes a higher high, but MACD makes a lower high.
Advanced Divergence: If the price makes a higher high, but the MACD Advanced is flat or lower, it means the Higher Timeframe EMA is losing its slope. Even if the price looks strong, the "Big Picture" is flattening out. This is often a precursor to a major reversal.
3. The "Snap-Back" Trade (Mean Reversion)
Since you are using a 200 EMA as the trend filter, the indicator will naturally pull back toward zero when the price gets too far from that average.
The Signal: If the MACD Advanced is "overextended" (very high or very low relative to its recent history) and the inner histogram crosses back toward the zero line, it’s a sign that the price is likely to "snap back" to the mean.
Application: This is great for exiting a trend trade before the actual trend reversal happens.
Pro Tip: The "Zero-Cross" Filter
In a strong uptrend (Daily EMA 200 is rising), the MACD Advanced will rarely cross below zero. If you see the histogram dip into the red while the MACD columns stay green/above zero, treat that as a "Buy the Dip" opportunity rather than a "Sell" signal.
The Chart shows regular MACD vs ADVANCED MACD one can easily observe the difference between them and the trend is identified easily.
Wskaźnik Pine Script®






















