OBV With Divergence
On Balance Volume is a running total that adds a bar's volume when it closes higher and subtracts it when it closes lower, tracking whether volume is flowing with or against the price trend. A divergence between price and OBV - price pushing to a new extreme while OBV fails to confirm it - is one of the more established warning signs that a trend is running out of participation, but spotting it reliably by eye means comparing two lines' swing points against each other, which is easy to get wrong on a busy chart. This indicator finds swings the same way the rest of this set does: a bar is a confirmed swing high or low once it is the most extreme point within a fixed number of bars on both sides. Each time a new swing confirms, its price and its OBV value are compared against the previous confirmed swing of the same type. A higher price high paired with a lower OBV value marks bearish divergence; a lower price low paired with a higher OBV value marks bullish divergence. The marker sits on the second swing's own bar, which by definition is already several bars in the past by the time it can be confirmed - divergence detection cannot be instantaneous, because a swing is only a swing once the bars on both sides of it exist. Only regular divergence is detected (the classic exhaustion signal). Hidden divergence, which continuation traders read the opposite way, is a different pattern with a different practical use and is not covered by this indicator. Notes and limitations - Only regular (exhaustion-type) divergence is marked; hidden (continuation-type) divergence is a different signal and is not detected here. - A swing, and therefore any divergence built from it, is only confirmed InpK bars after the swing bar itself - this cannot and does not claim to catch a divergence the moment it forms. - OBV here runs on tick volume (price-change count), the only volume figure most MT4 feeds expose, not a count of contracts or lots traded. - The whole OBV series and the full confirmable swing history are recomputed on every call rather than patched incrementally, which keeps the logic simple and correct after any history reload at the cost of some redundant work on very long histories. - Recomputed entirely from closed-bar price and volume, with nothing kept that a later bar can override, so there is nothing here that can repaint.
Indicator · MT5 · v1.0 · Free
About OBV With Divergence
OBV With Divergence is an indicator for MetaTrader 5 based on Divergence. It draws buy and sell arrows on the chart and can alert you with a pop-up, sound, email or push message. It has 2 settings, such as K and Alerts. MQL source code included.
Files in the download: ObvDivergence.ex5, ObvDivergence.mq5, ObvDivergence.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| K | 3 | Bars required on each side to confirm a swing |
| Alerts | true | Alert on a new confirmed divergence |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Indicators.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the indicator from the Navigator onto a chart and adjust the settings.
Tags: Volume · Divergence · Trend · Buy/Sell Arrows · Alerts · MT5 Indicator · MQL5 Source Code