Multi-Divergence Strategy | GainzAlgoThe Multi-Divergence Strategy is a comprehensive, quantitative trading tool designed to identify momentum exhaustion through multi-oscillator divergence detection. By visualizing the relationship between price action and nine distinct momentum/volume metrics, this indicator provides a framework for identifying high-probability reversal setups.
Core Logic: How it Identifies Divergence
The indicator functions by monitoring pivot highs and lows across both price and nine independent oscillators (RSI, MFI, Stochastic, Z-Score, ADX, MACD, OBV, Price Action, and Swing Volume).
Logic: The script flags a Bullish Divergence when the price reaches a lower low, but the oscillator reaches a higher low. Conversely, it flags a Bearish Divergence when the price reaches a higher high, but the oscillator reaches a lower high.
Trigger: The script creates a dynamic detection system that triggers signals only when new pivot highs or lows are confirmed, ensuring signals are not repainting.
The Technical Overlay
The Technical Overlayis a visual dashboard that renders seven distinct indicator panes directly on your main chart.
Customization: The Window Width input allows you to adjust the lookback period for these panels, while the Future Offset allows you to shift the UI horizontally to avoid cluttering current price action.
Visuals: When divergence is detected, the overlay renders "neon" glowing markers at the exact pivot point where the divergence occurred, providing immediate visual feedback on which indicator is signaling the reversal.
Settings and Toggle Menus
The indicator is highly modular, allowing for granular control via the inputs menu.
General Settings:
Window Width (Bars): Defines the depth of the visual analysis panes.
Future Offset (Bars): Offsets the UI panels relative to the current bar.
Divergence Pivot Length: Adjusts sensitivity. Lower values (e.g., 2-5) detect micro-divergences, while higher values (up to 15) isolate major structural shifts.
Show Technical Overlay: A master toggle to turn the neon dashboard on or off.
Screener and Risk Management Settings:
SL/TP Multipliers: These adjust the Stop Loss (SL) and Take Profit (TP) distance based on the 14-period Average True Range (ATR).
Custom SL %: If enabled, this bypasses the ATR-based stop in favor of a fixed percentage-based stop loss.
Visuals: Show TP / SL Lines toggles the display of active trade plans on the chart, helping you visualize your risk parameters.
Risk Management and P&L Calculations
Every signal detected by the strategy is treated as a trade plan with a defined entry, stop, and target.
Stop Outs and Exits: The script performs a rolling calculation of every active trade. A trade is closed (marked as a loss) if price hits the SL level, or closed (marked as a win) if price hits the TP level.
ATR-Based P&L: The P&L is not based on arbitrary dollar amounts, but on ATR multipliers. This ensures your performance metrics are normalized against the current market volatility.
Understanding the Performance Table
The performance table provides a real-time summary of every divergence indicator's effectiveness.
Signals: The total number of trades initiated by that specific indicator.
Wins/Losses: The count of trades that reached the TP vs. the SL.
Win%: The percentage of closed trades that resulted in a win.
Avg Win/Loss: The average ATR distance captured in winning trades versus the average risk taken in losing trades.
Cumulative ATR Multi: This is the most critical metric. It represents the total P&L of the strategy expressed in ATR multiples.
A Note on Win Rate and Expectations: You may observe an average win rate of approximately 37%. Do not get discouraged by a low win rate. In quantitative trading, a "high" win rate is often irrelevant if the risk management is poor.
Instead of focusing on the strike rate, prioritize the Cumulative ATR Multi. A strategy with a 37% win rate can be highly profitable if your "Average Win" is significantly larger than your "Average Loss". Use the table to identify which specific indicators are yielding the highest cumulative ATR returns in the current market environment and lean into those signals.
How to Trade with the Strategy
Enable the Table: Keep Show Performance Table enabled to track the "Cumulative ATR Multi" for each indicator.
Monitor Signals: When a neon marker appears on your chart, verify the entry, stop-loss, and take-profit lines.
Analyze and Execute: Focus your trades on the indicators that show a positive or rising "Cumulative ATR Multi" in the performance table.
Risk Management: Always respect the stop-loss lines, as they are calculated to keep your risk consistent with current market volatility.
Disclaimer: This indicator is for analytical and educational purposes only. Past performance does not guarantee future results.
Pine Script®指标






















