OPEN-SOURCE SCRIPT
CVD-MACD

### CVD-MACD (Research)
The CVD-MACD is a research-oriented indicator that combines Cumulative Volume Delta (CVD) with the classic MACD framework to provide insights into market momentum and potential reversals. Unlike a standard MACD based on price, this version uses CVD (the running total of buy vs. sell volume delta) as its input source, offering a volume-driven perspective on trend strength and divergences.
Key Features:
- **CVD-Based MACD Calculation**: Computes MACD using CVD instead of price, highlighting volume imbalances that may precede price moves.
- **Dual Divergence Detection**: Identifies bullish/bearish divergences on both the MACD line and histogram, with configurable pivot lookbacks and filters (e.g., momentum decay and zero-side consistency).
- **Visual Flexibility**: Toggle divergences in the indicator pane or overlaid on the main chart, with optional raw CVD line for reference.
- **Alerts**: Built-in conditions for bullish and bearish divergences to notify users of potential setups.
###This indicator is designed for research and experimentation—it's not financial advice. It performs best on liquid assets with reliable volume data (e.g., stocks, futures). I've shared this to gather community feedback: please test it thoroughly and point out any bugs, inefficiencies, or improvements! For example, if you spot issues with divergence detection on certain timeframes or symbols, let me know in the comments. Your input will help refine it.
Inspired by volume analysis techniques; open to collaborations or forks.
## User Manual for CVD-MACD (Research)
### Overview
The CVD-MACD indicator transforms traditional MACD by using Cumulative Volume Delta (CVD) as the base input. CVD accumulates the net delta between estimated buy and sell volume per bar, providing a volume-centric view of momentum. The indicator plots a MACD line, signal line, and histogram, while also detecting divergences on both the MACD line and histogram for potential reversal signals.
This manual covers setup, interpretation, and troubleshooting.
Note: This is a research tool—backtest and validate on your own data before using in live trading.
### Installation and Setup
1. **Add to Chart**: Search for "CVD-MACD (Research)" in TradingView's indicator library or paste the script into the Pine Editor and add it to your chart.
2. **Compatibility**: Works on any timeframe and symbol with volume data. Best on daily/intraday charts for stocks, forex, or futures. Avoid illiquid symbols where volume may be unreliable.
3. **Customization**: All inputs are configurable via the indicator's settings panel. Defaults are optimized for general use but can be tuned based on asset volatility.
### Input Parameters
The inputs are grouped for ease of use:
#### MACD Settings
- **Fast EMA (CVD)** (default: 12): Length of the fast EMA applied to CVD. Shorter values make it more responsive to recent volume changes.
- **Slow EMA (CVD)** (default: 26): Length of the slow EMA on CVD. Longer values smooth out noise for trend identification.
- **Signal EMA** (default: 9): Smoothing period for the signal line (EMA of the MACD line).
#### Divergence Logic (MACD Line)
- **Pivot Lookback (MACD Line)** (default: 5): Bars to look left/right for detecting pivots on the MACD line. Higher values detect larger swings but may miss smaller divergences.
- **Max Lookback Range (MACD Line)** (default: 50): Maximum bars between two pivots to consider a divergence valid. Prevents detecting outdated signals.
- **Enable Momentum Decay Filter (Histogram)** (default: false): When enabled, requires the histogram to show decaying momentum (absolute value decreasing) for MACD-line divergences to trigger.
#### Histogram Divergence
- **Pivot Lookback (Histogram)** (default: 5): Similar to above, but for histogram pivots.
- **Max Lookback Range (Histogram)** (default: 50): Max bars for histogram divergence detection.
- **Show Histogram Divergences in Indicator Pane** (default: true): Displays dashed lines and "H" labels for histogram divergences in the sub-window.
- **Show Histogram Divergences on Main Chart** (default: true): Overlays histogram divergences on the price chart with semi-transparent lines and labels.
- **Require Histogram to Stay on Same Side of Zero** (default: true): Filters divergences to only those where the histogram doesn't cross zero between pivots, ensuring consistent momentum direction.
#### Visuals (Dual View)
- **Show MACD-Line Divergences (Indicator Pane)** (default: true): Draws solid lines and "L" labels for MACD-line divergences in the sub-window.
- **Show MACD-Line Divergences (Main Chart)** (default: true): Overlays MACD-line divergences on the price chart.
- **Show Raw CVD Line** (default: false): Plots the underlying CVD as a faint gray line for reference.
### How to Interpret the Indicator
1. **Core Plots**:
- **MACD Line** (blue): Difference between fast and slow CVD EMAs. Above zero indicates building buy volume momentum; below zero shows sell dominance.
- **Signal Line** (orange): EMA of the MACD line. Crossovers can signal potential entries/exits (e.g., MACD above signal = bullish).
- **Histogram** (columns): MACD minus signal. Green shades for positive/expanding bars (bullish momentum); red for negative/contracting (bearish). Fading colors indicate weakening momentum.
- **Zero Line** (gray horizontal): Reference for bullish (above) vs. bearish (below) territory.
- **Raw CVD** (optional gray line): The cumulative buy-sell delta. Rising = net buying; falling = net selling.
2. **Divergences**:
- **Bullish (Green Lines/Labels)**: Occur when price makes lower lows, but MACD line or histogram makes higher lows. Suggests weakening downside momentum and potential reversal up. Look for "L" (MACD line) or "H" (histogram) labels.
- **Bearish (Red Lines/Labels)**: Price higher highs vs. MACD/histogram lower highs. Indicates fading upside and possible downturn.
- **Dual View**: Divergences appear in the indicator pane (sub-window) for clean analysis and overlaid on the main chart for price context. Histogram divergences use dashed lines to distinguish from MACD-line (solid).
- **Filters**: Momentum decay ensures only "hidden" or weakening divergences trigger. Zero-side filter prevents false signals from oscillating histograms.
3. **Alerts**:
- **Bullish Divergence (L or H)**: Triggers on either MACD-line or histogram bullish divergence. Message: "CVD-MACD Bullish Divergence detected on {{ticker}}".
- **Bearish Divergence (L or H)**: Similar for bearish. Use TradingView's alert setup to notify via email/SMS/webhook.
- Tip: Combine with price action (e.g., support/resistance) for confirmation.
### Usage Tips and Strategies
- **Trend Confirmation**: Use in uptrends for bullish divergences (pullback buys) or downtrends for bearish (short entries).
- **Timeframe Selection**: Higher timeframes (e.g., daily) for swing trading; lower (e.g., 15-min) for intraday. Adjust pivot lookbacks accordingly (shorter for faster charts).
- **Combination Ideas**: Pair with RSI for overbought/oversold confirmation or VWAP for intraday volume context.
- **Risk Management**: Divergences are probabilistic—not guarantees. Always use stop-losses based on recent swings.
- **Performance Notes**: Backtest on historical data via TradingView's Strategy Tester. CVD relies on accurate volume; test on exchanges like NYSE/NASDAQ.
### Known Limitations and Troubleshooting
- **Volume Dependency**: CVD estimation assumes linear buy/sell distribution based on bar position—may be less accurate on thin markets or during gaps.
- **Repainting**: Pivots and divergences can repaint as new data arrives (common in pivot-based indicators). Use on closed bars for reliability.
- **Resource Usage**: High max_bars_back (5000) ensures deep history; reduce if chart loads slowly.
- **No Signals on Low-Volume Bars**: If CVD flatlines, check symbol volume—some crypto/forex pairs have inconsistent data.
- **Community Feedback**: If you encounter bugs (e.g., false divergences on specific symbols/timeframes), missing alerts, or calculation errors, please comment below with details like symbol, timeframe, and screenshots. Suggestions for enhancements (e.g., more filters or visuals) are welcome!
If you have questions or find issues, drop a comment—let's improve this together!
The CVD-MACD is a research-oriented indicator that combines Cumulative Volume Delta (CVD) with the classic MACD framework to provide insights into market momentum and potential reversals. Unlike a standard MACD based on price, this version uses CVD (the running total of buy vs. sell volume delta) as its input source, offering a volume-driven perspective on trend strength and divergences.
Key Features:
- **CVD-Based MACD Calculation**: Computes MACD using CVD instead of price, highlighting volume imbalances that may precede price moves.
- **Dual Divergence Detection**: Identifies bullish/bearish divergences on both the MACD line and histogram, with configurable pivot lookbacks and filters (e.g., momentum decay and zero-side consistency).
- **Visual Flexibility**: Toggle divergences in the indicator pane or overlaid on the main chart, with optional raw CVD line for reference.
- **Alerts**: Built-in conditions for bullish and bearish divergences to notify users of potential setups.
###This indicator is designed for research and experimentation—it's not financial advice. It performs best on liquid assets with reliable volume data (e.g., stocks, futures). I've shared this to gather community feedback: please test it thoroughly and point out any bugs, inefficiencies, or improvements! For example, if you spot issues with divergence detection on certain timeframes or symbols, let me know in the comments. Your input will help refine it.
Inspired by volume analysis techniques; open to collaborations or forks.
## User Manual for CVD-MACD (Research)
### Overview
The CVD-MACD indicator transforms traditional MACD by using Cumulative Volume Delta (CVD) as the base input. CVD accumulates the net delta between estimated buy and sell volume per bar, providing a volume-centric view of momentum. The indicator plots a MACD line, signal line, and histogram, while also detecting divergences on both the MACD line and histogram for potential reversal signals.
This manual covers setup, interpretation, and troubleshooting.
Note: This is a research tool—backtest and validate on your own data before using in live trading.
### Installation and Setup
1. **Add to Chart**: Search for "CVD-MACD (Research)" in TradingView's indicator library or paste the script into the Pine Editor and add it to your chart.
2. **Compatibility**: Works on any timeframe and symbol with volume data. Best on daily/intraday charts for stocks, forex, or futures. Avoid illiquid symbols where volume may be unreliable.
3. **Customization**: All inputs are configurable via the indicator's settings panel. Defaults are optimized for general use but can be tuned based on asset volatility.
### Input Parameters
The inputs are grouped for ease of use:
#### MACD Settings
- **Fast EMA (CVD)** (default: 12): Length of the fast EMA applied to CVD. Shorter values make it more responsive to recent volume changes.
- **Slow EMA (CVD)** (default: 26): Length of the slow EMA on CVD. Longer values smooth out noise for trend identification.
- **Signal EMA** (default: 9): Smoothing period for the signal line (EMA of the MACD line).
#### Divergence Logic (MACD Line)
- **Pivot Lookback (MACD Line)** (default: 5): Bars to look left/right for detecting pivots on the MACD line. Higher values detect larger swings but may miss smaller divergences.
- **Max Lookback Range (MACD Line)** (default: 50): Maximum bars between two pivots to consider a divergence valid. Prevents detecting outdated signals.
- **Enable Momentum Decay Filter (Histogram)** (default: false): When enabled, requires the histogram to show decaying momentum (absolute value decreasing) for MACD-line divergences to trigger.
#### Histogram Divergence
- **Pivot Lookback (Histogram)** (default: 5): Similar to above, but for histogram pivots.
- **Max Lookback Range (Histogram)** (default: 50): Max bars for histogram divergence detection.
- **Show Histogram Divergences in Indicator Pane** (default: true): Displays dashed lines and "H" labels for histogram divergences in the sub-window.
- **Show Histogram Divergences on Main Chart** (default: true): Overlays histogram divergences on the price chart with semi-transparent lines and labels.
- **Require Histogram to Stay on Same Side of Zero** (default: true): Filters divergences to only those where the histogram doesn't cross zero between pivots, ensuring consistent momentum direction.
#### Visuals (Dual View)
- **Show MACD-Line Divergences (Indicator Pane)** (default: true): Draws solid lines and "L" labels for MACD-line divergences in the sub-window.
- **Show MACD-Line Divergences (Main Chart)** (default: true): Overlays MACD-line divergences on the price chart.
- **Show Raw CVD Line** (default: false): Plots the underlying CVD as a faint gray line for reference.
### How to Interpret the Indicator
1. **Core Plots**:
- **MACD Line** (blue): Difference between fast and slow CVD EMAs. Above zero indicates building buy volume momentum; below zero shows sell dominance.
- **Signal Line** (orange): EMA of the MACD line. Crossovers can signal potential entries/exits (e.g., MACD above signal = bullish).
- **Histogram** (columns): MACD minus signal. Green shades for positive/expanding bars (bullish momentum); red for negative/contracting (bearish). Fading colors indicate weakening momentum.
- **Zero Line** (gray horizontal): Reference for bullish (above) vs. bearish (below) territory.
- **Raw CVD** (optional gray line): The cumulative buy-sell delta. Rising = net buying; falling = net selling.
2. **Divergences**:
- **Bullish (Green Lines/Labels)**: Occur when price makes lower lows, but MACD line or histogram makes higher lows. Suggests weakening downside momentum and potential reversal up. Look for "L" (MACD line) or "H" (histogram) labels.
- **Bearish (Red Lines/Labels)**: Price higher highs vs. MACD/histogram lower highs. Indicates fading upside and possible downturn.
- **Dual View**: Divergences appear in the indicator pane (sub-window) for clean analysis and overlaid on the main chart for price context. Histogram divergences use dashed lines to distinguish from MACD-line (solid).
- **Filters**: Momentum decay ensures only "hidden" or weakening divergences trigger. Zero-side filter prevents false signals from oscillating histograms.
3. **Alerts**:
- **Bullish Divergence (L or H)**: Triggers on either MACD-line or histogram bullish divergence. Message: "CVD-MACD Bullish Divergence detected on {{ticker}}".
- **Bearish Divergence (L or H)**: Similar for bearish. Use TradingView's alert setup to notify via email/SMS/webhook.
- Tip: Combine with price action (e.g., support/resistance) for confirmation.
### Usage Tips and Strategies
- **Trend Confirmation**: Use in uptrends for bullish divergences (pullback buys) or downtrends for bearish (short entries).
- **Timeframe Selection**: Higher timeframes (e.g., daily) for swing trading; lower (e.g., 15-min) for intraday. Adjust pivot lookbacks accordingly (shorter for faster charts).
- **Combination Ideas**: Pair with RSI for overbought/oversold confirmation or VWAP for intraday volume context.
- **Risk Management**: Divergences are probabilistic—not guarantees. Always use stop-losses based on recent swings.
- **Performance Notes**: Backtest on historical data via TradingView's Strategy Tester. CVD relies on accurate volume; test on exchanges like NYSE/NASDAQ.
### Known Limitations and Troubleshooting
- **Volume Dependency**: CVD estimation assumes linear buy/sell distribution based on bar position—may be less accurate on thin markets or during gaps.
- **Repainting**: Pivots and divergences can repaint as new data arrives (common in pivot-based indicators). Use on closed bars for reliability.
- **Resource Usage**: High max_bars_back (5000) ensures deep history; reduce if chart loads slowly.
- **No Signals on Low-Volume Bars**: If CVD flatlines, check symbol volume—some crypto/forex pairs have inconsistent data.
- **Community Feedback**: If you encounter bugs (e.g., false divergences on specific symbols/timeframes), missing alerts, or calculation errors, please comment below with details like symbol, timeframe, and screenshots. Suggestions for enhancements (e.g., more filters or visuals) are welcome!
If you have questions or find issues, drop a comment—let's improve this together!
Script open-source
Nello spirito di TradingView, l'autore di questo script lo ha reso open source, in modo che i trader possano esaminarne e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricordiamo che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.
Script open-source
Nello spirito di TradingView, l'autore di questo script lo ha reso open source, in modo che i trader possano esaminarne e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricordiamo che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.