Contribute an indicator to the library by clicking here. Note you must be logged in.

New! Stock Portfolio Organizer is now available:
  • Shares, Margin, Futures and Forex
  • EOD and Realtime data
  • And Much More...
GoTo Stock Portfolio Organizer
New! WiseTrader Toolbox for Amibroker is now available with:
  • Advanced Adaptive Indicators
  • Advanced Pattern Exploration
  • Neural Networks
  • And Much More...
GoTo WiseTrader Toolbox

Popular Indicators

Ultimate Divergence Detector for Amibroker (AFL)

3 / 5 (Votes 17)

Divergence is one of the most reliable trading signals, but it’s tricky to identify divergences in real time and if you’re not paying attention, it’s easy to miss a divergence. There are a bunch of divergence detectors posted here, so why another one? Well, I tried all the ones I found and none of them really met my needs, so I decided to create my own. Here’s what makes mine different:

1. Most divergence detectors look for peaks and troughs in price and then try to find a nearby peak or trough in RSI. I took the opposite approach. UDD looks for higher RSI troughs and lower RSI peaks. It then looks for divergences between price and RSI at the current RSI peak/trough, compared with the previous one. I feel this is a more reliable method of identifying divergences, because RSI is less noisy than price. If you want to use a different indicator from RSI, it just involves changing one line of code.

2. UDD plots the RSI and overlays the Zig-Zag indicator on top of it. It then plots a green dot identifying each bullish divergence and a red dot identifying each bearish divergence. This makes it easy for the user to see the divergence. Just follow the Zig-Zag line back to the prior zig/zag point on the graph. The prior point is where the divergence began and the red or green dot is the trade entry point. Peaks or troughs that have no divergence are shown as grey dots.

3. UDD allows the user to specify the RSI length and the percentage change threshold. As you adjust these values, the graph dynamically updates, so you can see the effect of the change in real time. The default RSI length of 14 and percentage threshold of 10% may be too noisy for many markets. If you see too many false signals on the graph, just increase these values until you’re comfortable with how the graph looks.

4. UDD uses pure array processing, no loops, so it’s extremely fast and the code is compact and easy to understand.

5. UDD includes a simple trading system with backtesting. The system buys on each bullish divergence and goes short on each bearish divergence. It exits the trade at the next point on the zig-zag line. For instance, if it goes short on a bearish divergence, it will exit the trade at the next trough. The actual entries and exits occur one bar after the peak or trough is identified. If you backtest this against a variety of markets, you may be surprised at how profitable it is.

Here is a screenshot of how the indicator looks:

Similar Formulas



Hi Brad Konia,

Really Ultimate. Thanks for sharing. My rating 5/5

Please describe when to book profits & SL also
Is it possible to develop explorer/scan for buy Sell?

Hi Brad Konia,

I am back testing on daily Time frame. Results are good but lots of whisphaws because of threshold=10.

As per you experience, for daily time frame charts, what should be optimal value for threshold???

Thanks once again

looks into future quates

Hi Brad,
Excellent indicator. Just want to clear one thing. Suppose i see a greendot(Bullish divergence) at 10:00am in 15 min timeframe chart. At what time was that green dot actually formed i.e. at close of 10:15am, open of 10:30am or close of 10:30am candle. Please clarify.

Seems quite useful; but I cannot see the Zig-Zag line. Please advise.


Doesn’t it look into future?

Exceptional and Unbelievable Results. Thanks for sharing

It looks in to the future

10. K Gadkari

I have just downloaded the indicator …But the look of it gives real confidence . Thanks a lot for sharing such a good indicator.
How do I use it for MACD if At all I can ?

11. K Gadkari

Can anybody help change the above code for getting divergence on CLOSING of bar instead of PEAK and TROUGH . As RSI is calculated on basis of CLOSE of the bar . So divergence also has to be observed for CLOSE of the bar.
Thanjs and Regards .
All in all good indicator 5/5

Please login here to leave a comment.

Main Menu