Divergence IQ [TradingIQ]Hello Traders!
Introducing "Divergence IQ"
Divergence IQ lets traders identify divergences between price action and almost ANY TradingView technical indicator. This tool is designed to help you spot potential trend reversals and continuation patterns with a range of configurable features.
Features
Divergence Detection
Detects both regular and hidden divergences for bullish and bearish setups by comparing price movements with changes in the indicator.
Offers two detection methods: one based on classic pivot point analysis and another that provides immediate divergence signals.
Option to use closing prices for divergence detection, allowing you to choose the data that best fits your strategy.
Normalization Options:
Includes multiple normalization techniques such as robust scaling, rolling Z-score, rolling min-max, or no normalization at all.
Adjustable normalization window lets you customize the indicator to suit various market conditions.
Option to display the normalized indicator on the chart for clearer visual comparison.
Allows traders to take indicators that aren't oscillators, and convert them into an oscillator - allowing for better divergence detection.
Simulated Trade Management:
Integrates simulated trade entries and exits based on divergence signals to demonstrate potential trading outcomes.
Customizable exit strategies with options for ATR-based or percentage-based stop loss and profit target settings.
Automatically calculates key trade metrics such as profit percentage, win rate, profit factor, and total trade count.
Visual Enhancements and On-Chart Displays:
Color-coded signals differentiate between bullish, bearish, hidden bullish, and hidden bearish divergence setups.
On-chart labels, lines, and gradient flow visualizations clearly mark divergence signals, entry points, and exit levels.
Configurable settings let you choose whether to display divergence signals on the price chart or in a separate pane.
Performance Metrics Table:
A performance table dynamically displays important statistics like profit, win rate, profit factor, and number of trades.
This feature offers an at-a-glance assessment of how the divergence-based strategy is performing.
The image above shows Divergence IQ successfully identifying and trading a bullish divergence between an indicator and price action!
The image above shows Divergence IQ successfully identifying and trading a bearish divergence between an indicator and price action!
The image above shows Divergence IQ successfully identifying and trading a hidden bullish divergence between an indicator and price action!
The image above shows Divergence IQ successfully identifying and trading a hidden bearish divergence between an indicator and price action!
The performance table is designed to provide a clear summary of simulated trade results based on divergence setups. You can easily review key metrics to assess the strategy’s effectiveness over different time periods.
Customization and Adaptability
Divergence IQ offers a wide range of configurable settings to tailor the indicator to your personal trading approach. You can adjust the lookback and lookahead periods for pivot detection, select your preferred method for normalization, and modify trade exit parameters to manage risk according to your strategy. The tool’s clear visual elements and comprehensive performance metrics make it a useful addition to your technical analysis toolbox.
The image above shows Divergence IQ identifying divergences between price action and OBV with no normalization technique applied.
While traders can look for divergences between OBV and price, OBV doesn't naturally behave like an oscillator, with no definable upper and lower threshold, OBV can infinitely increase or decrease.
With Divergence IQ's ability to normalize any indicator, traders can normalize non-oscillator technical indicators such as OBV, CVD, MACD, or even a moving average.
In the image above, the "Robust Scaling" normalization technique is selected. Consequently, the output of OBV has changed and is now behaving similar to an oscillator-like technical indicator. This makes spotting divergences between the indicator and price easier and more appropriate.
The three normalization techniques included will change the indicator's final output to be more compatible with divergence detection.
This feature can be used with almost any technical indicator.
Stop Type
Traders can select between ATR based profit targets and stop losses, or percentage based profit targets and stop losses.
The image above shows options for the feature.
Divergence Detection Method
A natural pitfall of divergence trading is that it generally takes several bars to "confirm" a divergence. This makes trading the divergence complicated, because the entry at time of the divergence might look great; however, the divergence wasn't actually signaled until several bars later.
To circumvent this issue, Divergence IQ offers two divergence detection mechanisms.
Pivot Detection
Pivot detection mode is the same as almost every divergence indicator on TradingView. The Pivots High Low indicator is used to detect market/indicator highs and lows and, consequently, divergences.
This method generally finds the "best looking" divergences, but will always take additional time to confirm the divergence.
Immediate Detection
Immediate detection mode attempts to reduce lag between the divergence and its confirmation to as little as possible while avoiding repainting.
Immediate detection mode still uses the Pivots Detection model to find the first high/low of a divergence. However, the most recent high/low does not utilize the Pivot Detection model, and instead immediately looks for a divergence between price and an indicator.
Immediate Detection Mode will always signal a divergence one bar after it's occurred, and traders can set alerts in this mode to be alerted as soon as the divergence occurs.
TradingView Backtester Integration
Divergence IQ is fully compatible with the TradingView backtester!
Divergence IQ isn’t designed to be a “profitable strategy” for users to trade. Instead, the intention of including the backtester is to let users backtest divergence-based trading strategies between the asset on their chart and almost any technical indicator, and to see if divergences have any predictive utility in that market.
So while the backtester is available in Divergence IQ, it’s for users to personally figure out if they should consider a divergence an actionable insight, and not a solicitation that Divergence IQ is a profitable trading strategy. Divergence IQ should be thought of as a Divergence backtesting toolkit, not a full-feature trading strategy.
Strategy Properties Used For Backtest
Initial Capital: $1000 - a realistic amount of starting capital that will resonate with many traders
Amount Per Trade: 5% of equity - a realistic amount of capital to invest relative to portfolio size
Commission: 0.02% - a conservative amount of commission to pay for trade that is standard in crypto trading, and very high for other markets.
Slippage: 1 tick - appropriate for liquid markets, but must be increased in markets with low activity.
Once more, the backtester is meant for traders to personally figure out if divergences are actionable trading signals on the market they wish to trade with the indicator they wish to use.
And that's all!
If you have any cool features you think can benefit Divergence IQ - please feel free to share them!
Thank you so much TradingView community!
Divergenceindicator
Divergence Toolkit (Real-Time)The Divergence Toolkit is designed to automatically detect divergences between the price of an underlying asset and any other @TradingView built-in or community-built indicator or script. This algorithm provides a comprehensive solution for identifying both regular and hidden divergences, empowering traders with valuable insights into potential trend reversals.
🔲 Methodology
Divergences occur when there is a disagreement between the price action of an asset and the corresponding indicator. Let's review the conditions for regular and hidden divergences.
Regular divergences indicate a potential reversal in the current trend.
Regular Bullish Divergence
Price Action - Forms a lower low.
Indicator - Forms a higher low.
Interpretation - Suggests that while the price is making new lows, the indicator is showing increasing strength, signaling a potential upward reversal.
Regular Bearish Divergence
Price Action - Forms a higher high.
Indicator - Forms a lower high.
Interpretation - Indicates that despite the price making new highs, the indicator is weakening, hinting at a potential downward reversal.
Hidden divergences indicate a potential continuation of the existing trend.
Hidden Bullish Divergence
Price Action - Forms a higher low.
Indicator - Forms a lower low.
Interpretation - Suggests that even though the price is retracing, the indicator shows increasing strength, indicating a potential continuation of the upward trend.
Hidden Bearish Divergence
Price Action - Forms a lower high.
Indicator - Forms a higher high.
Interpretation - Indicates that despite a retracement in price, the indicator is still strong, signaling a potential continuation of the downward trend.
In both regular and hidden divergences, the key is to observe the relationship between the price action and the indicator. Divergences can provide valuable insights into potential trend reversals or continuations.
The methodology employed in this script involves the detection of divergences through conditional price levels rather than relying on detected pivots. Traditionally, divergences are created by identifying pivots in both the underlying asset and the oscillator. However, this script employs a trailing stop on the oscillator to detect potential swings, providing a real-time approach to identifying divergences, you may find more info about it here (SuperTrend Toolkit) . We detect swings or pivots simply by testing for crosses between the indicator and its trailing stop.
type oscillator
float o = Oscillator Value
float s = Trailing Stop Value
oscillator osc = oscillator.new()
bool l = ta.crossunder(osc.o, osc.s) => Utilized as a formed high
bool h = ta.crossover (osc.o, osc.s) => Utilized as a formed low
// Note: these conditions alone could cause repainting when they are met but canceled at a later time before the bar closes. Hence, we wait for a confirmed bar.
// The script also includes the option to immediately alert when the conditions are met, if you choose so.
By testing for conditional price levels, the script achieves similar outcomes without the delays associated with pivot-based methods.
type bar
float o = open
float h = high
float l = low
float c = close
bar b = bar.new()
bool hi = b.h < b.h => A higher price level has been created
bool lo = b.l > b.l => A lower price level has been created
// Note: These conditions do not check for certain price swings hence they may seldom result in inaccurate detection.
🔲 Setup Guide
A simple example on one of my public scripts, Standardized MACD
🔲 Utility
We may auto-detect divergences to spot trend reversals & continuations.
🔲 Settings
Source - Choose an oscillator source of which to base the Toolkit on.
Zeroing - The Mid-Line value of the oscillator, for example RSI & MFI use 50.
Sensitivity - Calibrates the sensitivity of which Divergencies are detected, higher values result in more detections but less accuracy.
Lifetime - Maximum timespan to detect a Divergence.
Repaint - Switched on, the script will trigger Divergencies as they happen in Real-Time, could cause repainting when the conditions are met but canceled at a later time before bar closes.
🔲 Alerts
Bearish Divergence
Bullish Divergence
Bearish Hidden Divergence
Bullish Hidden Divergence
As well as the option to trigger 'any alert' call.
The Divergence Toolkit provides traders with a dynamic tool for spotting potential trend reversals and continuations. Its innovative approach to real-time divergence detection enhances the timeliness of identifying market opportunities.
Momentum Oscillator, Divergences & Signals [TrendAlpha]The "Momentum, Real Time Divergences & Signals " indicator is designed to provide traders with insights into market momentum, identify potential divergences, and generate buy and sell signals. It offers a comprehensive set of features to assist traders in making informed trading decisions.
The indicator starts by calculating the momentum oscillator based on user-defined parameters.
- Traders can adjust the "Length" parameter to customize the sensitivity of the oscillator. The default value is set to 7, but it can be modified according to individual preferences.
- The "Source" parameter allows traders to select the input source for the oscillator calculation, with the default being the closing price of the asset.
- Traders have the option to display divergence lines by switching on the "Show Lines" parameter. This feature helps identify potential divergences between the oscillator and the price.
The oscillator is calculated using a two-step process. First, a smoothing function is applied to the source data using the "sma" (simple moving average) function. Then, the rate of change is computed over the specified length using the "mom" (momentum) function. Positive oscillator values indicate upward momentum, while negative values indicate downward momentum.
The indicator also generates buy and sell signals by identifying bullish and bearish divergences. A bullish divergence occurs when the oscillator is negative and crosses above zero, while a bearish divergence occurs when the oscillator is positive and crosses below zero. The indicator checks for specific conditions to confirm the divergences, such as comparing the current oscillator value with the previous value and validating the corresponding price action.
When a bullish or bearish divergence is detected, the indicator plots circles to highlight these signals on the chart. A green circle indicates a bullish signal, suggesting a potential buying opportunity, while a red circle indicates a bearish signal, suggesting a potential selling opportunity. In addition to circles, the indicator also displays labels to provide further clarity on the signals. A "Buy" label is shown for bullish signals, and a "Sell" label is shown for bearish signals.
To visually represent the divergences, the indicator plots lines connecting the corresponding points on the oscillator. A green line is drawn for bullish divergences, while a red line is drawn for bearish divergences. Traders can easily observe the divergence patterns and their relationships with the price action, aiding them in making trading decisions.
- The indicator also includes alert conditions for both bullish and bearish divergences. Traders can set up alerts to receive notifications when potential divergences occur, allowing them to take timely action.
The Divergent LibraryLibrary "TheDivergentLibrary"
The Divergent Library is only useful when combined with the Pro version of The Divergent - Advanced divergence indicator . This is because the Basic (free) version of The Divergent does not expose the "Divergence Signal" value.
Usage instructions:
1. Create a new chart
2. Add The Divergent (Pro) indicator to your chart
3. Create a new strategy, import this library, add a "source" input, link it to "The Divergent: Divergence Signal", and use the library to decode the divergence signals from The Divergent (You can find example strategy code published in our profile)
4. Act on the divergences signalled by The Divergent
---
isRegularBullishEnabled(context) Returns a boolean value indicating whether Regular Bullish divergence detection is enabled in The Divergent.
Parameters:
context : The context of The Divergent Library.
Returns: A boolean value indicating whether Regular Bullish divergence detection is enabled in The Divergent.
isHiddenBullishEnabled(context) Returns a boolean value indicating whether Hidden Bullish divergence detection is enabled in The Divergent.
Parameters:
context : The context of The Divergent Library.
Returns: A boolean value indicating whether Hidden Bullish divergence detection is enabled in The Divergent.
isRegularBearishEnabled(context) Returns a boolean value indicating whether Regular Bearish divergence detection is enabled in The Divergent.
Parameters:
context : The context of The Divergent Library.
Returns: A boolean value indicating whether Regular Bearish divergence detection is enabled in The Divergent.
isHiddenBearishEnabled(context) Returns a boolean value indicating whether Hidden Bearish divergence detection is enabled in The Divergent.
Parameters:
context : The context of The Divergent Library.
Returns: A boolean value indicating whether Hidden Bearish divergence detection is enabled in The Divergent.
getPivotDetectionSource(context) Returns the 'Pivot Detection Source' setting of The Divergent. The returned value can be either "Oscillator" or "Price".
Parameters:
context : The context of The Divergent Library.
Returns: One of the following string values: "Oscillator" or "Price".
getPivotDetectionMode(context) Returns the 'Pivot Detection Mode' setting of The Divergent. The returned value can be either "Bodies" or "Wicks".
Parameters:
context : The context of The Divergent Library.
Returns: One of the following string values: "Bodies" or "Wicks".
isLinked(context) Returns a boolean value indicating the link status to The Divergent indicator.
Parameters:
context : The context of The Divergent Library.
Returns: A boolean value indicating the link status to The Divergent indicator.
init(firstBarSignal, displayLinkStatus, debug) Initialises The Divergent Library's context with the signal produced by The Divergent on the first bar. The value returned from this function is called the "context of The Divergent Library". Some of the other functions of this library requires you to pass in this context.
Parameters:
firstBarSignal : The signal from The Divergent indicator on the first bar.
displayLinkStatus : A boolean value indicating whether the Link Status window should be displayed in the bottom left corner of the chart. Defaults to true.
debug : A boolean value indicating whether the Link Status window should display debug information. Defaults to false.
Returns: A bool array containing the context of The Divergent Library.
processSignal(signal) Processes a signal from The Divergent and returns a 5-tuple with the decoded signal: [ int divergenceType, int priceBarIndexStart, int priceBarIndexEnd, int oscillatorBarIndexStart, int oscillatorBarIndexEnd]. `divergenceType` can be one of the following values: na → No divergence was detected, 1 → Regular Bullish, 2 → Regular Bullish early, 3 → Hidden Bullish, 4 → Hidden Bullish early, 5 → Regular Bearish, 6 → Regular Bearish early, 7 → Hidden Bearish, 8 → Hidden Bearish early.
Parameters:
signal : The signal from The Divergent indicator.
Returns: A 5-tuple with the following values: [ int divergenceType, int priceBarIndexStart, int priceBarIndexEnd, int oscillatorBarIndexStart, int oscillatorBarIndexEnd].