OPEN-SOURCE SCRIPT
Eight Moving Average Cross with Macro Divergences

Credits and acknowledgment
The percentage-based moving average difference concept that powers the core oscillator in this script was inspired by the open-source "MA difference" indicator created by cereallarceny
I am grateful for that foundation and have expanded it into an eight-layer system with cascade alignment logic, macro divergence detection, additional filters, a non-repainting framework, and a publication-ready alert suite. This credit appears first to clarify lineage, and the rest of the description focuses on the specific additions and behavioral logic in this version.
Indicator name and purpose
Eight Moving Average Cross with Macro Divergences is a multi-layer trend alignment and macro reversal map. It converts eight moving averages into a percentage-difference oscillator so you can read how far each layer of the trend structure is positioned relative to a base reference. The script then adds two complementary decision layers: a Cascade signal to detect synchronized momentum shifts across the trend stack, and a Macro Divergence map that highlights early warning signs of trend exhaustion or trend continuation.

What it does
You receive a clean oscillator pane that shows when short-term momentum aligns with the long-term structure, and when the price action is losing strength at meaningful pivots. The Cascade layer provides a filtered trigger for momentum shifts, while the divergence layer provides a higher-timeframe context for reversals or continuation. The result is an indicator that can be used as a standalone oscillator for structure analysis, or as a confirmation layer in a broader trading plan. If you already use moving averages in your workflow, this script turns them into an objective percentage-based structure map that is easier to compare across markets and timeframes.
How it works in detail
The engine calculates the percentage distance between a base moving average and seven additional moving averages. Every layer expresses whether it is above or below the base, and by how much. These percentage differences are plotted and can be filled against the zero line to visualize bullish and bearish structure. The Cascade logic looks for a cross of the zero line from the short, medium, or long layer, but only allows a signal when the extra long-term layers are already aligned in the same direction. This ensures that a short-term shift is supported by the broader trend stack instead of being a simple noise move.
The Macro Divergence module is built from confirmed pivot swings. It uses a long-term reference, defined by the long moving average, to find price pivots and compares those pivots with a smoothed oscillator derived from the extra long-term averages. Classic divergences are detected when price makes a higher high while the oscillator makes a lower high, or when price makes a lower low while the oscillator makes a higher low. Hidden divergences are detected when price retains trend structure but the oscillator counter-swings, often signaling trend continuation. To reduce random signals, the algorithm enforces a minimum spacing between pivots and a minimum amplitude for divergence strength. This makes the divergence layer a macro view rather than a noisy micro-signal engine.

How to use it
Use the zero line as the structural boundary. When the short, medium, and long layers move above zero, the short-term structure is bullish. When they move below zero, the short-term structure is bearish. Cascade signals are intentionally strict: they appear only when a base layer crosses zero and all extra long-term layers are aligned. This is a momentum confirmation event rather than a prediction. Divergences should be interpreted as early warnings: a classic bearish divergence suggests that a rally is losing strength at a macro high; a classic bullish divergence suggests accumulation at a macro low. Hidden divergences help you stay with the dominant trend when a temporary retracement appears.
Practical examples
Example for a bullish setup: The short or medium layer crosses above zero, all extra layers are already above zero, and a Cascade Buy highlight appears. This indicates a synchronized bullish structure across short and long horizons. If a hidden bullish divergence appears during a pullback while the extra layers remain positive, it supports the continuation case and provides a structure-based reason to hold the position rather than exit too early.

Example for a bearish setup: The short or medium layer crosses below zero, extra layers are already negative, and a Cascade Sell highlight appears. If a classic bearish divergence appears near a price high, it warns that the bullish structure is weakening and that risk should be reduced.

How the components work together
The Cascade layer acts as a strict trend-alignment filter. The Divergence layer provides macro context and early warnings. Together, they allow you to trade momentum in the direction of the dominant structure while also identifying areas where the structure is at risk of reversal. The oscillator visuals let you see when the trend stack is compressing or expanding, which adds additional context beyond simple cross signals. The percentage-difference approach also makes it easier to compare trend strength across different instruments, because the values scale relative to the base average instead of absolute price.
What makes this script original
This is not a simple moving-average mashup. The script transforms eight averages into a percent-difference oscillator, then uses a layered alignment system to validate momentum shifts and a pivot-based divergence engine to detect macro-level structure shifts. The combination of these two modules produces information that you do not get from a single MA crossover or a standard oscillator divergence. The multi-layer structure, amplitude filtering, pivot spacing, non-repainting framework, and alert language are original additions and are central to the script’s usefulness.
Markets and timeframes
The script is designed for any liquid market, including Forex, Crypto, Stocks, Commodities, and Indices. For intraday use, 15m to 4H timeframes give stable Cascade signals and readable divergences. On daily and weekly charts, divergences are fewer but carry higher significance. For scalping on 1m to 5m charts, reduce moving average lengths and pivot spacing to maintain responsiveness and keep the divergence layer from lagging too far behind. For day trading on 5m to 1H, the defaults work well and provide a balanced signal frequency. For swing trading on 1H to daily charts, consider increasing pivot spacing and smoothing to emphasize macro swings. For longer-term investing on weekly to monthly charts, increase the long and extra MA lengths to match the broader cycle.

Settings guidance
Base Length controls the anchor average used for all percentage differences. Short, Medium, and Long define the base cross structure and provide the momentum layer. Extra MA 1-4 are the long-term alignment stack for Cascade and the core of the divergence oscillator. Pivot lookback left and right define how far the script looks to confirm a swing; higher values mean fewer but stronger divergences. Minimum bars between pivots is a noise filter that avoids consecutive pivots. Oscillator smoothing reduces erratic swings and sharpens macro structure. Minimum divergence amplitude filters out weak divergence signals.
Tips for tuning
If the oscillator feels too reactive, increase the base length and smoothing to reduce noise. If Cascade signals are too rare, reduce the extra MA lengths or increase the base layer responsiveness. If divergences are too frequent, raise the minimum amplitude or increase the bars-between-pivots setting. If divergences are too slow, reduce smoothing and pivot length, but expect more false positives. These changes should be tested per symbol, because volatility and trading session behavior can differ significantly between markets.

Alerts
The alert system is fully integrated with the non-repainting framework. Cascade Buy and Cascade Sell alerts trigger only after confirmed bar close when the Cascade conditions are met. Divergence alerts trigger only after confirmed pivot formation, so they do not move once printed. Alert messages include symbol, timeframe, and price to support automation or manual monitoring. This makes the alerts suitable for discretionary traders and for automated alert-to-webhook workflows.
Non-repainting behavior
This script includes a dedicated non-repainting toggle. When enabled, all signals, drawings, and alerts are confirmed on closed bars. This means a signal cannot appear and then disappear. The trade-off is a small delay in signaling, but it ensures historical and live behavior match, which is critical for honest backtesting and reliable alerts. When disabled, the script remains visually responsive for exploration, but users should treat signals as provisional until the bar closes.
Disclaimer
This indicator is a technical analysis tool and does not constitute financial advice. No indicator is perfect. Always use risk management, validate signals with additional context, and test settings on your chosen market and timeframe before trading with real funds.
The percentage-based moving average difference concept that powers the core oscillator in this script was inspired by the open-source "MA difference" indicator created by cereallarceny
I am grateful for that foundation and have expanded it into an eight-layer system with cascade alignment logic, macro divergence detection, additional filters, a non-repainting framework, and a publication-ready alert suite. This credit appears first to clarify lineage, and the rest of the description focuses on the specific additions and behavioral logic in this version.
Indicator name and purpose
Eight Moving Average Cross with Macro Divergences is a multi-layer trend alignment and macro reversal map. It converts eight moving averages into a percentage-difference oscillator so you can read how far each layer of the trend structure is positioned relative to a base reference. The script then adds two complementary decision layers: a Cascade signal to detect synchronized momentum shifts across the trend stack, and a Macro Divergence map that highlights early warning signs of trend exhaustion or trend continuation.
What it does
You receive a clean oscillator pane that shows when short-term momentum aligns with the long-term structure, and when the price action is losing strength at meaningful pivots. The Cascade layer provides a filtered trigger for momentum shifts, while the divergence layer provides a higher-timeframe context for reversals or continuation. The result is an indicator that can be used as a standalone oscillator for structure analysis, or as a confirmation layer in a broader trading plan. If you already use moving averages in your workflow, this script turns them into an objective percentage-based structure map that is easier to compare across markets and timeframes.
How it works in detail
The engine calculates the percentage distance between a base moving average and seven additional moving averages. Every layer expresses whether it is above or below the base, and by how much. These percentage differences are plotted and can be filled against the zero line to visualize bullish and bearish structure. The Cascade logic looks for a cross of the zero line from the short, medium, or long layer, but only allows a signal when the extra long-term layers are already aligned in the same direction. This ensures that a short-term shift is supported by the broader trend stack instead of being a simple noise move.
The Macro Divergence module is built from confirmed pivot swings. It uses a long-term reference, defined by the long moving average, to find price pivots and compares those pivots with a smoothed oscillator derived from the extra long-term averages. Classic divergences are detected when price makes a higher high while the oscillator makes a lower high, or when price makes a lower low while the oscillator makes a higher low. Hidden divergences are detected when price retains trend structure but the oscillator counter-swings, often signaling trend continuation. To reduce random signals, the algorithm enforces a minimum spacing between pivots and a minimum amplitude for divergence strength. This makes the divergence layer a macro view rather than a noisy micro-signal engine.
How to use it
Use the zero line as the structural boundary. When the short, medium, and long layers move above zero, the short-term structure is bullish. When they move below zero, the short-term structure is bearish. Cascade signals are intentionally strict: they appear only when a base layer crosses zero and all extra long-term layers are aligned. This is a momentum confirmation event rather than a prediction. Divergences should be interpreted as early warnings: a classic bearish divergence suggests that a rally is losing strength at a macro high; a classic bullish divergence suggests accumulation at a macro low. Hidden divergences help you stay with the dominant trend when a temporary retracement appears.
Practical examples
Example for a bullish setup: The short or medium layer crosses above zero, all extra layers are already above zero, and a Cascade Buy highlight appears. This indicates a synchronized bullish structure across short and long horizons. If a hidden bullish divergence appears during a pullback while the extra layers remain positive, it supports the continuation case and provides a structure-based reason to hold the position rather than exit too early.
Example for a bearish setup: The short or medium layer crosses below zero, extra layers are already negative, and a Cascade Sell highlight appears. If a classic bearish divergence appears near a price high, it warns that the bullish structure is weakening and that risk should be reduced.
How the components work together
The Cascade layer acts as a strict trend-alignment filter. The Divergence layer provides macro context and early warnings. Together, they allow you to trade momentum in the direction of the dominant structure while also identifying areas where the structure is at risk of reversal. The oscillator visuals let you see when the trend stack is compressing or expanding, which adds additional context beyond simple cross signals. The percentage-difference approach also makes it easier to compare trend strength across different instruments, because the values scale relative to the base average instead of absolute price.
What makes this script original
This is not a simple moving-average mashup. The script transforms eight averages into a percent-difference oscillator, then uses a layered alignment system to validate momentum shifts and a pivot-based divergence engine to detect macro-level structure shifts. The combination of these two modules produces information that you do not get from a single MA crossover or a standard oscillator divergence. The multi-layer structure, amplitude filtering, pivot spacing, non-repainting framework, and alert language are original additions and are central to the script’s usefulness.
Markets and timeframes
The script is designed for any liquid market, including Forex, Crypto, Stocks, Commodities, and Indices. For intraday use, 15m to 4H timeframes give stable Cascade signals and readable divergences. On daily and weekly charts, divergences are fewer but carry higher significance. For scalping on 1m to 5m charts, reduce moving average lengths and pivot spacing to maintain responsiveness and keep the divergence layer from lagging too far behind. For day trading on 5m to 1H, the defaults work well and provide a balanced signal frequency. For swing trading on 1H to daily charts, consider increasing pivot spacing and smoothing to emphasize macro swings. For longer-term investing on weekly to monthly charts, increase the long and extra MA lengths to match the broader cycle.
Settings guidance
Base Length controls the anchor average used for all percentage differences. Short, Medium, and Long define the base cross structure and provide the momentum layer. Extra MA 1-4 are the long-term alignment stack for Cascade and the core of the divergence oscillator. Pivot lookback left and right define how far the script looks to confirm a swing; higher values mean fewer but stronger divergences. Minimum bars between pivots is a noise filter that avoids consecutive pivots. Oscillator smoothing reduces erratic swings and sharpens macro structure. Minimum divergence amplitude filters out weak divergence signals.
Tips for tuning
If the oscillator feels too reactive, increase the base length and smoothing to reduce noise. If Cascade signals are too rare, reduce the extra MA lengths or increase the base layer responsiveness. If divergences are too frequent, raise the minimum amplitude or increase the bars-between-pivots setting. If divergences are too slow, reduce smoothing and pivot length, but expect more false positives. These changes should be tested per symbol, because volatility and trading session behavior can differ significantly between markets.
Alerts
The alert system is fully integrated with the non-repainting framework. Cascade Buy and Cascade Sell alerts trigger only after confirmed bar close when the Cascade conditions are met. Divergence alerts trigger only after confirmed pivot formation, so they do not move once printed. Alert messages include symbol, timeframe, and price to support automation or manual monitoring. This makes the alerts suitable for discretionary traders and for automated alert-to-webhook workflows.
Non-repainting behavior
This script includes a dedicated non-repainting toggle. When enabled, all signals, drawings, and alerts are confirmed on closed bars. This means a signal cannot appear and then disappear. The trade-off is a small delay in signaling, but it ensures historical and live behavior match, which is critical for honest backtesting and reliable alerts. When disabled, the script remains visually responsive for exploration, but users should treat signals as provisional until the bar closes.
Disclaimer
This indicator is a technical analysis tool and does not constitute financial advice. No indicator is perfect. Always use risk management, validate signals with additional context, and test settings on your chosen market and timeframe before trading with real funds.
Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que cualquier republicación del código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.
Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que cualquier republicación del código está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.