Stochastic Divergence
The Stochastic lines here are the standard calculation, read straight off the built-in indicator so the values match whatever plain Stochastic is already on the chart - nothing about the oscillator itself is reinvented. What is added is a divergence marker, built on a strict rule rather than a visual "looks like it" judgement. A swing high or low only counts once it is a confirmed fractal - the highest or lowest point within K bars on both sides, which by definition cannot be known until those K bars have closed. Divergence is then a straight comparison between two confirmed swings of the same type: bearish when price's second swing high is higher than its first but %K's reading at that second high is lower than at the first; bullish is the mirror case on swing lows. %K is compared against price rather than %D, because %D is already a smoothed average of %K. Comparing price to a twice-smoothed line would blur exactly the swing-to-swing disagreement this tool exists to catch, and %D remains on the chart purely as the usual signal-line cross reference. Because both swings being compared are already confirmed by the time the marker can appear, the marker itself never moves once drawn and never appears retroactively on a bar that has already scrolled off the right edge of the chart. What it costs is a lag of K bars behind the live edge, which is the same lag every fractal-based tool in this catalogue carries and the price of not repainting. Notes and limitations - Divergence here means regular divergence only (price extreme not confirmed by %K) - it does not attempt to classify hidden divergence, which is a different and more ambiguous read. - Every marker sits InpK bars behind the live edge by construction; treat it as confirmation of a completed structural disagreement, not a same-bar entry trigger. - Divergence is a warning sign, not a trade signal on its own - price can and does keep extending after a confirmed divergence. Combine with the trader's own trigger and risk management. - Uses the built-in iStochastic() call for the lines themselves rather than a hand-rolled recalculation, so warm-up behaviour matches the platform's own Stochastic exactly.
Indicator · MT5 · v1.0 · Free
About Stochastic Divergence
Stochastic Divergence is an indicator for MetaTrader 5 based on Divergence and Stochastic. It draws buy and sell arrows on the chart and can alert you with a pop-up, sound, email or push message. It has 7 settings, such as K period, D period and Slowing. MQL source code included.
Files in the download: StochasticDivergence.ex5, StochasticDivergence.mq5, StochasticDivergence.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| K period | 5 | %K period |
| D period | 3 | %D period |
| Slowing | 3 | Slowing |
| Ma method | StochSmoothSma | Smoothing method |
| Price field | StochLowHigh | Price field |
| 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: Stochastic · Divergence · Fractals · Oscillator · Buy/Sell Arrows · Alerts · MT5 Indicator · MQL5 Source Code