Devadex

Volume Delta Divergence Indicator

gumroad   Free   by kryptera
2d old

Volume Delta Divergence Indicator | Python Backtest ImplementationA full Python port of the "Volume Delta (TopinTrade)" TradingView indicator — turned into a testable divergence strategy, with zero lookahead bias, a normalized 0–100 volume-delta oscillator, pivot-confirmed divergence scoring, and vectorbt-powered backtesting.What Is This?Most volume indicators just tell you what already happened — a bar was green, a bar was red. They don't tell you when buying or selling pressure is quietly shifting before price catches up.This system takes TradingView's Volume Delta indicator — which estimates buy/sell pressure from where price closes within each bar's range — and builds a proper divergence-based trading rule around it. Instead of reacting to raw delta, it tracks confirmed pivots in a smoothed, normalized delta oscillator and looks for the classic tell: price and volume pressure disagreeing with each other.The Volume Delta Divergence Indicator builds a bounded 0–100 oscillator from rolling volume delta, detects confirmed pivots in both price and the oscillator, and fires only when the two diverge with enough time-based strength behind them. No signal clustering, no lookahead, no guessing at unconfirmed pivots.The idea is direct:When price makes a lower low but volume delta makes a higher low, buying pressure is building underneath falling price — a bullish divergence entry. When price makes a higher high but volume delta makes a lower high, that strength is fading — a bearish divergence exit. A latching regime filter unlocks an additional "hidden bullish" entry pattern during confirmed uptrends.How It WorksThe strategy computes a Chaikin-style buy/sell volume split for every bar, sums it over a rolling window, and normalizes it to a 0–100 oscillator so it behaves like an RSI-style bounded signal instead of an unbounded raw value.Within that framework:✓ Volume delta = buy_volume − sell_volume, where buy_volume is estimated from where each bar's close landed inside its high/low range✓ The oscillator = rolling min-max normalization of the rolling delta sum (0–100 scale, causal — the window never looks past the current bar)✓ Pivots in the oscillator are only confirmed after pivot_lookback bars have passed to the right — exactly matching Pine Script's ta.pivotlow() / ta.pivothigh() confirmation timing✓ A latching regime flips Bullish when the oscillator pushes above the upper threshold, and flips back off below the lower threshold — holding state bar-by-bar, no repainting✓ Divergence strength is scored by bar-distance between the two most recent confirmed pivots (closer pivots score higher, distant ones are filtered out entirely)Entry is confirmed only once both the price pivot and the oscillator pivot have been independently confirmed — never anticipated ahead of time.What's Inside the Full Code✓ Chaikin-style volume delta approximation (buy/sell split from OHLCV — no tick data required)✓ Rolling-window 0–100 oscillator normalization (bounded, RSI-style behavior)✓ Pivot detection with proper forward-shift confirmation (zero lookahead, matches Pine Script exactly)✓ Latching regime engine mirroring Pine Script's var bool state-holding logic✓ Time-scored divergence strength matrix (100% / 75% / 50% / 25% / ignored, by bar-distance)✓ Normal Bullish + Hidden Bullish entry detection (regime-gated)✓ Normal Bearish exit detection✓ Strict no-lookahead architecture — every decision finalized at bar close✓ Next-bar open execution via 1-bar signal shift✓ vectorbt-powered portfolio engine integration✓ Realistic fees and slippage included in the backtest✓ Full performance statistics, equity curves, drawdown analysis, and trade P&L✓ Modular Python architecture ready to extend into: Walk-forward optimization Multi-ticker / stock-universe scanning Monte Carlo robustness validation Parameter sensitivity analysis Machine learning pipelines The Core Strategy LogicNormal Bullish Entry Price makes a lower low while the volume delta oscillator makes a higher low, with the two pivots close enough together to score above the minimum divergence strength threshold — confirming buying pressure diverging from falling price.Hidden Bullish Entry (Bull Regime only) Price makes a higher low while the oscillator makes a lower low, during a confirmed Bull Regime — a continuation-style entry rather than a reversal.Normal Bearish Exit Price makes a higher high while the oscillator makes a lower high — confirming fading buying pressure into a rising price, triggering exit.Execution Logic Signals are shifted forward by 1 bar and executed on the next bar's open price, to maintain walk-forward-safe execution and eliminate lookahead bias.Why the Divergence Framework MattersMost volume-delta tools are pure visuals — you're expected to eyeball the histogram and form your own read. That's useful for discretionary trading, but it isn't testable, repeatable, or backtestable on its own.This system converts that visual into a mechanical, fully causal rule set by: Treating the oscillator like any bounded technical indicator (pivots, divergence, regime) instead of a raw plot Scoring divergence by time-distance between pivots, so stale or coincidental divergences are filtered out automatically Gating a second entry pattern (hidden bullish) behind a regime filter, so continuation setups aren't confused with reversal setups Confirming every pivot only after its right-side window has passed — never assuming a pivot exists before price has actually moved past it This creates footprints such as: Entries clustered around genuine shifts in buy/sell pressure rather than every minor wiggle A regime filter that separates "buying pressure returning after a pullback" from "buying pressure building for the first time" Quiet periods with no signal noise when price and volume pressure agree with each other A framework that only ever needs OHLCV data — no tick feed, no bid/ask, no external data required Perfect For Python quant traders studying volume-based divergence systems vectorbt users building oscillator-driven mean-reversion or continuation strategies Traders researching order-flow proxies without tick-data access Developers wanting a clean pivot/regime/divergence engine that mirrors Pine Script exactly Researchers exploring volume delta as an alternative to RSI/momentum divergence Anyone interested in converting TradingView volume-based indicators to Python Key Research Concepts Chaikin-style OHLCV volume delta approximation Rolling min-max oscillator normalization (0–100 scale) Pine Script-accurate pivot confirmation (ta.pivotlow / ta.pivothigh timing) Time-scored divergence strength matrices Latching regime detection with state holdover Bar-confirmed signal detection (no clustering) Next-bar open execution for lookahead-safe backtesting vectorbt portfolio engine integration Important NotesTradingView's original "Volume Delta (TopinTrade)" indicator pulls true lower-timeframe buy/sell volume from the exchange feed via ta.requestVolumeDelta(). Standard OHLCV data does not contain tick-level or bid/ask volume, so an exact reproduction isn't possible without a tick-data vendor.This implementation uses the standard, widely-used OHLCV approximation instead: each bar's volume is split into buy/sell components based on where price closed within that bar's high/low range. This stays fully causal — it only ever uses a bar's own finalized OHLCV — but it is an approximation of true order-flow volume, not a tick-perfect replica. This should be understood as a volume-pressure proxy rather than a literal reconstruction of exchange-level buy/sell volume.Ideal ExtensionsThis framework becomes especially powerful when combined with: Walk-forward optimization across oscillator length and regime threshold parameters Multi-ticker scanning across a broad universe rather than a single symbol Monte Carlo resampling of trade sequences to stress-test the drawdown profile Regime filters combining this oscillator with a separate trend or volatility filter Multi-timeframe confirmation layers Machine learning classifiers for divergence quality prediction Adaptive pivot-lookback or strength-threshold optimization by volatility regime If this project helped you, please consider leaving a ⭐⭐⭐⭐⭐ rating — it genuinely supports future quantitative research tools, trading systems, and open-source strategy development.Thank you for supporting the project 🙌

Get it → kryptera.gumroad.com

Found on Devadex — the discovery index for independent software the big search engines bury. More from gumroad.

Report this listing