OPEN-SOURCE SCRIPT
Atualizado

OBV with Kalman Filter Improv [TechnicalZen]

3 533
Reversals, Breakouts & Re-Entries: OBV with Kalman Filter Improv [TechnicalZen]

What This Indicator Does

This indicator transforms On-Balance Volume into a visual momentum instrument. Raw OBV is normalized to a 0-100 scale, rendered as stair-step candles with a continuous color gradient, and overlaid with a dual Kalman-filtered ribbon that tracks the flow trend with adaptive precision.

The result is a single pane that answers three questions at a glance: Is volume flow accumulating or distributing? How strong is the conviction? Where are the reversal, breakout, and re-entry points?

No footprint data required. No premium subscription needed. Pure price action and volume.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Why OBV Matters More Than Raw Volume

Raw volume bars tell you how much traded. They do not tell you which direction the volume was pushing. A high-volume bar during a selloff looks identical to a high-volume bar during a breakout rally.

On-Balance Volume assigns direction. When price closes up, the bar's volume is added. When price closes down, it is subtracted. The running total — OBV — reveals the persistent pressure beneath the surface. Rising OBV with flat price means accumulation. Falling OBV with rising price means distribution. These divergences are invisible on a standard volume histogram.

This indicator takes OBV further by normalizing it into a bounded oscillator, smoothing it for clarity, and applying Kalman filtering for adaptive trend detection.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

How It Works

The indicator processes OBV through four stages.

Stage 1 — Normalize to 0-100

Raw OBV is an unbounded cumulative number that grows indefinitely. This makes it difficult to compare across time periods or instruments. The indicator applies a rolling min-max normalization over a configurable lookback window (default 100 bars), mapping OBV into a 0-100 scale.

At 100, OBV is at its highest point within the lookback. At 0, its lowest. At 50, it sits at the midpoint of its recent range. This creates a bounded oscillator from a trending series.

Stage 2 — Stair-Step Candles

The normalized OBV is rendered as candles where each bar's open equals the previous bar's close. This creates seamless stair-step blocks with no gaps and no overlaps. The candles show the direction and magnitude of each bar's contribution to the flow — a tall green block means a strong volume push upward, a tall red block means aggressive selling pressure.

Stage 3 — Position-Based Color Gradient

Candle color is determined by where the candle sits in the 0-100 range, not merely whether it went up or down:

  • Bright green (above 70) — strong bullish accumulation zone
  • Yellow-green (50-70) — moderate bullish flow
  • Yellow (around 50) — neutral, transition zone
  • Orange (30-50) — weakening flow, bearish lean
  • Red (below 30) — strong bearish distribution zone


This gradient reveals the market's volume state at a glance. Candles clustered at the top in green signal sustained accumulation. Candles dropping through yellow into red signal a regime shift.

Stage 4 — Dual Kalman Ribbon

Two Kalman-filtered lines track the normalized OBV at different speeds:

  • Short KF (default 20) — responsive to recent flow shifts
  • Long KF (default 80) — tracks the underlying flow trend


When the short line is above the long line, the ribbon fills bullish. When below, bearish. The Kalman filter adapts its responsiveness automatically — smoothing through noise while responding quickly to genuine regime changes. This is fundamentally superior to any fixed-length moving average.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Reading the Three Signals

Reversals

A reversal signal appears when candles have been clustered at one extreme (above 70 or below 30) and begin migrating toward the midline. The color gradient shifts — green fading to yellow, or red fading to orange. The Kalman ribbon begins to narrow as the short line approaches the long line. When the ribbon flips color, the reversal is confirmed by volume flow, not just price action.

Breakouts

A breakout appears as a large candle that punches through the 70 or 30 threshold line with expanding body size. The Kalman ribbon is already aligned in the breakout direction (short above long for bullish, below for bearish). This confirms that volume flow is supporting the price move — not just a wick or a fake breakout.

Re-Entries

After a breakout, price often pulls back. During a healthy pullback, the candles dip toward the midline (50) but the Kalman ribbon stays in the trend direction. Candles may turn yellow briefly but do not reach the opposite extreme. When candles resume their original color and move away from the midline, that is the re-entry — volume flow confirms the trend is intact.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Why Kalman Filtering — Not EMA, SMA, or Hull

Traditional moving averages apply a fixed smoothing recipe regardless of market conditions. In a quiet market, they lag. In a volatile market, they whipsaw. The trader is forced to manually change the length setting as conditions change.

The Kalman filter solves this structurally. It maintains an internal estimate of both the value and its uncertainty. On every bar, it computes a gain that automatically balances between trusting the new data and trusting its prediction. When data is noisy, the gain drops and the filter smooths aggressively. When a genuine shift occurs, the gain rises and the filter responds immediately.

Two parameters control this behavior:

  • R (Measurement Noise) — how much noise is expected in each bar's data. Higher values produce smoother output.
  • Q (Process Noise) — how quickly the underlying trend is expected to change. Higher values allow faster adaptation.


The dual-line ribbon (short KF vs long KF) combines the adaptive smoothing with trend direction detection. The crossover of two Kalman-filtered lines is more reliable than traditional MA crossovers because the filter has already absorbed the noise before the crossover happens.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Reading the Indicator

The Candles
  • Green blocks at top — strong sustained buying pressure. Trend is healthy.
  • Red blocks at bottom — strong sustained selling. Downtrend confirmed by volume.
  • Yellow/orange blocks at midline — indecision. Flow is balanced. Wait for direction.
  • Color transition — the gradient shift (green to yellow, or red to orange) often leads price by several bars.


The Kalman Ribbon
  • Green fill (short above long) — volume flow trend is bullish
  • Red fill (short below long) — volume flow trend is bearish
  • Ribbon narrowing — trend weakening, potential flip ahead
  • Ribbon widening — trend conviction increasing


The Threshold Lines
  • 70 line — overbought in volume flow terms. Sustained presence above = strong trend, not necessarily a sell signal.
  • 50 line — equilibrium. Transitions through this level signal regime changes.
  • 30 line — oversold in volume flow terms. Sustained presence below = strong downtrend.
  • Line colors match the candle gradient — they shift with the regime.


━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Key Settings

Normalization Lookback (default: 100)
Rolling window for min-max scaling. Higher values produce smoother oscillation with fewer extremes. Lower values make the indicator more reactive to recent volume changes.

HA Smoothing Passes (default: 1)
Number of additional smoothing passes on the normalized OBV. 1 = standard stair-step. 2-3 = smoother candles with less noise.

Short KF / Long KF Length (default: 20 / 80)
Controls the responsiveness of the two Kalman lines. The gap between them determines how quickly the ribbon detects trend changes.

Measurement Noise R (default: 0.01)
Higher = smoother Kalman output. Lower = more reactive to each bar.

Process Noise Q (default: 0.10)
Higher = faster adaptation to regime shifts. Lower = more rigid trend following.

Upper / Lower Threshold (default: 70 / 30)
Defines the overbought/oversold boundaries for the volume flow oscillator.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Divergence — The Most Powerful Signal

When price makes a new high but the OBV candles fail to reach the upper zone (or are falling), volume is not confirming the move. This bearish divergence often precedes reversals by several bars. The Kalman ribbon will begin narrowing before the price chart shows any weakness.

Conversely, when price makes a new low but OBV candles hold above the lower zone or begin rising, that is bullish divergence — accumulation is happening beneath the surface.

The gradient coloring makes these divergences immediately visible. Price may look strong, but if the candles are orange instead of green, the volume story disagrees.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

What This Indicator Is Not

  • It does not generate automated buy or sell signals. It provides visual regime information for the trader to interpret.
  • It does not use footprint or order flow data. It is built on standard OBV which infers direction from price close. For actual bid/ask decomposition, a footprint-based indicator is required.
  • It does not predict future price direction. It reveals the current state and trend of volume flow. What the market does with that flow is never guaranteed.
  • It is not a standalone trading system. It is a confirmation and divergence detection tool designed to complement price action analysis.


━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Disclaimer

This indicator is provided for educational and informational purposes only. It is not financial advice, and it does not constitute a recommendation to buy, sell, or hold any financial instrument.

All trading involves risk. Past performance of any signal, regime detection system, or volume analysis mechanism does not guarantee future results. The normalized OBV readings, Kalman-filtered trend lines, and color gradient zones represent a computational assessment of publicly available price and volume data. They are not predictions and should not be treated as certainties.

On-Balance Volume assigns all of a bar's volume to one direction based solely on whether the close was higher or lower than the previous close. This is an approximation. A bar that closes up by one tick with heavy selling throughout will register as entirely bullish volume in OBV. Traders should be aware of this limitation.

The Kalman filter parameters (R and Q) affect responsiveness. Poorly tuned parameters can produce either excessive lag or excessive noise. The default values are designed for general use but may require adjustment for specific instruments or timeframes.

No indicator, algorithm, or model can account for all market variables including liquidity events, news-driven gaps, exchange outages, or sudden regime changes. Traders should always use independent risk management, position sizing, and their own judgment before entering any trade.

By using this indicator, you acknowledge that you are solely responsible for your own trading decisions and that the authors accept no liability for any losses incurred.

Notas de Lançamento
RBR: OBV Kalman Improv v3 — Release Notes

Dual Display Mode

New "Display Mode" setting: Trend or Oscillator
Trend: Detrended OBV candles around zero — shows reversals, divergence, and flow direction clearly. Candles colored by direction (bull/bear). Zero line reference.
Oscillator: Normalized 0-100 stair-step candles — shows overbought/oversold zones. Candles colored by gradient position (green→yellow→red). 30/50/70 threshold lines.
DX/ADX Regime Engine

Full directional movement system adapted for OBV data
Competitive DM logic: buy-volume expansion vs sell-volume expansion — only the winner scores
OBV True Range analog for proper normalization
4-state regime: Bull Strong, Bull Weak, Bear Strong, Bear Weak
Displayed in dashboard
Guitar Visual

Applies to Oscillator mode only (disabled in Trend mode to avoid distortion)
Show/hide toggle moved to top-level setting for quick access
Guitar body, gradient neck, and sound hole scale to the 0-100 pane
Kalman Ribbon

Dual Kalman-filtered lines (Short 20 / Long 80) with adaptive smoothing
Ribbon fill colored by direction — works in both display modes
Dashboard

Regime state, Kalman direction, OBV position vs fast KF, DX value, bar volume, cumulative OBV

Aviso legal

As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.