Tradehook — Trading Automation Service
mediumTechnical Indicator

DivAlgo

The DivAlgo identifies divergences between price action and momentum oscillators —a powerful signal that often precedes significant reversals. The algorithm supports multiple oscillators (RSI, MACD, Stochastic, CCI) and detects both regular and hidden divergences.

TradingView Preview
See this algorithm in action on real charts
DivAlgo TradingView chart
Performance Metrics
Historical backtesting results
71.4%
Win Rate
2.60
Profit Factor
1.5%
Max Drawdown
$170
Avg Trade
Based on 91 trades

About This Algorithm

DIVERGENCE DETECTION STRATEGY

Quick Facts:

  • Category: Divergence / Momentum
  • Markets: All markets
  • Timeframes: 1H, 4H, Daily

Overview

The DivAlgo identifies divergences between price action and momentum oscillators —a powerful signal that often precedes significant reversals. The algorithm supports multiple oscillators (RSI, MACD, Stochastic, CCI) and detects both regular and hidden divergences.

Divergence occurs when price makes a new high/low but the oscillator fails to confirm, indicating weakening momentum and potential reversal.


How It Works

OSCILLATOR CALCULATION Choose from multiple oscillators:

  • RSI: ta.rsi(close, rsiPeriod)
    • MACD: MACD histogram
    • Stochastic: Stochastic %K
    • CCI: ta.cci(close, cciPeriod)

PIVOT DETECTION Identify pivots on both price and oscillator:

  • Price Pivot High: ta.pivothigh(high, pivotLookback, pivotLookback)
    • Price Pivot Low: ta.pivotlow(low, pivotLookback, pivotLookback)
    • Oscillator pivots detected similarly

DIVERGENCE DETECTION

REGULAR BULLISH DIVERGENCE:

  • Price makes lower low
    • Oscillator makes higher low
    • Signals bullish reversal

REGULAR BEARISH DIVERGENCE:

  • Price makes higher high
    • Oscillator makes lower high
    • Signals bearish reversal

HIDDEN BULLISH DIVERGENCE (Optional):

  • Price makes higher low
    • Oscillator makes lower low
    • Signals trend continuation

HIDDEN BEARISH DIVERGENCE (Optional):

  • Price makes lower high
    • Oscillator makes higher high
    • Signals trend continuation

CONFIRMATION Optional filters for divergence validity:

  • Minimum divergence angle
    • Maximum pivot distance (bars between pivots)
    • Oscillator level filter (only oversold/overbought)

Key Parameters

OSCILLATOR:

  • oscillator ("RSI"): "RSI", "MACD", "Stochastic", "CCI"
    • rsiPeriod (14): RSI period
    • macdFast/macdSlow/macdSignal: MACD parameters
    • stochPeriod (14): Stochastic period
    • cciPeriod (20): CCI period

PIVOT DETECTION:

  • pivotLookback (5): Bars on each side for pivot
    • maxPivotDistance (50): Maximum bars between pivots

DIVERGENCE TYPES:

  • regularDivergence (true): Trade regular divergences
    • hiddenDivergence (false): Trade hidden divergences

FILTERS:

  • oscLevelFilter (true): Only trade at extreme osc levels
    • rsiBullThreshold (30): RSI level for bullish signals
    • rsiBearThreshold (70): RSI level for bearish signals

Best Use Cases

✅ REVERSAL DETECTION at extended moves ✅ TREND EXHAUSTION identification ✅ MULTI-TIMEFRAME divergence confirmation ✅ CONFLUENCE with other reversal signals

Customer Reviews

No reviews yet. Be the first to review this algorithm!
Technical Indicator
Requires Technical Indicator Plan

Subscribe to Technical Indicator or higher to access

Subscription Access

Get access to this indicator/strategy on TradingView through our invite-only system. Your TradingView account will be granted access.

One-Time Purchase

Own the complete Pine Script source code forever. Modify, customize, and use it on your own TradingView account.

$1,500
Subscribe to any tier to unlock one-time purchases

What you get with source code:

  • Complete Pine Script v5 source code
  • Lifetime ownership - no recurring fees
  • Full customization rights
  • Use on your own TradingView account
PlatformTradingView
Subscription AccessTradingView Invite
One-Time PurchaseSource Code
LicensePersonal Use

We Value Your Privacy

We use cookies to enhance your browsing experience, analyze site traffic, and personalize content. By clicking "Accept All", you consent to our use of cookies. Read our Privacy Policy for more information.