OPEN-SOURCE SCRIPT
Momentum Divergence

Overview
The Momentum Divergence Oscillator is a valuable tool designed for traders who are familiar with basic charting but want to deepen their market insights. This indicator combines a momentum calculation with divergence detection, presenting the data in an intuitive way with a blue momentum line and colored divergence signals ("Bull" and "Bear"). It’s perfect for refining entry and exit points across various timeframes, especially for scalping or swing trading strategies.
Understanding the Concepts
What is Momentum?
Momentum measures the speed and strength of a price movement by comparing the current closing price to a previous close over a set period. In this indicator, it’s calculated as the difference between the current close and the close from a user-defined number of bars ago (default: 10). A rising momentum line indicates accelerating upward momentum, while a falling line suggests slowing momentum or a potential reversal. This helps you gauge whether a trend is gaining power or losing steam, making it a key indicator for spotting overbought or oversold conditions.
What is a Divergence?
A divergence occurs when the price action and the momentum indicator move in opposite directions, often signaling a potential trend reversal. The Momentum Divergence Oscillator highlights two types:
How the Indicator Works
The indicator plots a momentum line in a separate pane below your chart, giving you a clear view of price momentum over time. It also scans for divergences using adjustable lookback periods (default: 5 bars left and right) and a range window (default: 5-60 bars) to ensure relevance. When a divergence is detected, it’s visually highlighted, and you can customize the sensitivity through input settings like the momentum length and pivot lookback. Alerts are included to notify you of new divergence signals in real-time, saving you from constant monitoring.
How to Apply It
Strategy Example
Customization Tips
Important Considerations
The Momentum Divergence Oscillator is a valuable tool designed for traders who are familiar with basic charting but want to deepen their market insights. This indicator combines a momentum calculation with divergence detection, presenting the data in an intuitive way with a blue momentum line and colored divergence signals ("Bull" and "Bear"). It’s perfect for refining entry and exit points across various timeframes, especially for scalping or swing trading strategies.
Understanding the Concepts
What is Momentum?
Momentum measures the speed and strength of a price movement by comparing the current closing price to a previous close over a set period. In this indicator, it’s calculated as the difference between the current close and the close from a user-defined number of bars ago (default: 10). A rising momentum line indicates accelerating upward momentum, while a falling line suggests slowing momentum or a potential reversal. This helps you gauge whether a trend is gaining power or losing steam, making it a key indicator for spotting overbought or oversold conditions.
What is a Divergence?
A divergence occurs when the price action and the momentum indicator move in opposite directions, often signaling a potential trend reversal. The Momentum Divergence Oscillator highlights two types:
- Bullish Divergence: When the price forms a lower low (indicating weakness), but the momentum shows a higher low (suggesting underlying strength). This can foreshadow an upward reversal.
- Bearish Divergence: When the price reaches a higher high (showing strength), but the momentum records a lower high (indicating fading momentum). This may hint at an impending downward turn.
How the Indicator Works
The indicator plots a momentum line in a separate pane below your chart, giving you a clear view of price momentum over time. It also scans for divergences using adjustable lookback periods (default: 5 bars left and right) and a range window (default: 5-60 bars) to ensure relevance. When a divergence is detected, it’s visually highlighted, and you can customize the sensitivity through input settings like the momentum length and pivot lookback. Alerts are included to notify you of new divergence signals in real-time, saving you from constant monitoring.
How to Apply It
- Identifying Opportunities: Use bullish divergences ("Bull") as a cue to consider long positions, especially when confirmed by support levels or a moving average crossover. Bearish divergences ("Bear") can signal short opportunities, particularly near resistance zones.
- Combining with Other Tools: Pair this oscillator with indicators like the Relative Strength Index (RSI) or volume analysis to filter out false signals and increase confidence in your trades. For example, a bullish divergence with rising volume can be a stronger buy signal.
- Timeframe Flexibility: Test it on shorter timeframes (e.g., 5-minute charts) for quick scalping trades or longer ones (e.g., 1-hour or 4-hour charts) for swing trading, adjusting the momentum length to suit the market’s pace.
- Alert Setup: Enable the built-in alerts to get notified when a divergence forms, allowing you to react promptly without staring at the screen all day.
Strategy Example
- Spot a bullish divergence on a 15-minute chart where the price hits a lower low, but the momentum rises.
- Confirm with a break above a 20-period EMA and increasing volume.
- Enter a long position with a stop-loss below the recent low and a take-profit near the next resistance level.
Customization Tips
- Adjust the "Momentum Length" (default: 10) to make the oscillator more or less sensitive—shorter lengths react faster, while longer ones smooth out noise.
- Tweak the "Pivot Lookback" settings to widen or narrow the divergence detection range based on your trading style.
- Use the "Range Upper/Lower" inputs to focus on divergences within a specific timeframe that matches your strategy.
Important Considerations
- b]This indicator is a technical analysis tool, not a guaranteed trading system. Always pair it with a solid strategy and strict risk management, such as setting stop-losses.
- In strong trending markets, divergences can sometimes produce false signals. Consider adding a trend filter (e.g., ADX below 25) to avoid whipsaws.
- Experiment with the settings on a demo account or backtest to find what works best for your preferred markets and timeframes.
Open-source script
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.
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.
Open-source script
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.
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.