OPEN-SOURCE SCRIPT

IQ Session Bayesian Particle Filter [TradingIQ]

4 149
🔹 OVERVIEW

This indicator runs a genuine Sequential Monte Carlo particle filter; the Bayesian architecture used in robotics and signal tracking... on your chart! Session by session, it learns where trading volume concentrates and paints a forecast of the coming session's entire volume-by-price distribution before that session unfolds: every expected high-volume level at once, not a single line.

It is not a moving average wearing a costume. Each finished session is treated as evidence: hundreds of particles are weighed against what actually traded, resampled, and mutated. Predict → observe → update, honestly Bayesian, every session.


🔹 HOW IT WORKS

Two particle swarms run side by side:

• A shape swarm learns the form of the distribution; one lump or several, wide or tight, and where each volume node sits.
• A drift swarm learns how far from the open the session's center of gravity tends to land.

An empirical-Bayes trust term scales the drift forecast by how much it has actually earned: when its track record is poor, the forecast automatically hugs the open. The prediction you see is the shape swarm's density, re-anchored by the trusted fraction of the drift forecast, rendered through a kernel density estimate whose bandwidth follows Silverman's rule.


🔸 HOW TO READ IT

Session heatmap — the predicted density painted from the session open to the profile. A two-tone gradient split at the open; the tones swap roles across it, so each side mirrors the other. Bold color = expected business, fade = expected quiet.
Mirrored profile — the forecast on the left, split bullish/bearish at the session open; the realized session volume on the right in a single neutral color.
Confidence honesty — the prediction's glow scales with the filter's live confidence. When it has been wrong lately, its side visibly goes quiet. The realized side never fades, because reality doesn't.
Bias info box — seated between the halves: the share of predicted volume above vs below the open (🢁 / 🢃).
Expected levels — dashed lines at the probability-weighted average predicted price of each half: the session's expected bull and bear magnets.
HVN lines + POC — the predicted high-volume levels. The point of control always shows; the HVN Threshold input is your dial between a few safe targets and every level worth watching.


🔹 SELF-TUNING

Every statistical free parameter tunes itself from data: the KDE bandwidth (Silverman's rule for visual convenience), the observation noise, the swarms' search domain (tracks the observed session spread), the mutation rate (genetic adaptation), the scout rate (scales with recent error), and the center trust (regression shrinkage). The inputs you are given are visual preferences plus a compute preset. There is nothing statistical to fiddle with, on purpose.


🔸 INPUTS

Session Engine — Session Timeframe (the session boundary; must exceed the chart timeframe), Prediction Quality (particles per swarm, Fast 100 → Max 4000), Sessions to Keep.
Volume Profile — toggles for the profile, bias box and expected levels; width, offset, info-box width, transparency.
Session Heatmap — toggle, faint/bold density transparencies, Tone A / Tone B.
High Volume Nodes — toggle, HVN Threshold %, reach, color.
Colors — Bullish, Bearish, Realized.


🔹 VALIDATION

The filter was tested on real intraday data; 10 large-cap symbols, three session horizons, every prediction one-step-ahead and out-of-sample, against uniform, yesterday's-profile, Gaussian-fit, rolling-average and EWMA baselines, with the test harness itself audited too.

• Against naive prediction (uniform prior, yesterday's profile) it wins every metric tested at every horizon.
• Against the strongest profile-averaging methods it trades wins: they edge the single-lump fit metrics; the filter captures materially more of the session's actual traded volume with its predicted levels, and is the only method that reliably names multiple simultaneous targets.
• On sessions with two or more real volume peaks; roughly 4 in 10 sessions, its targets covered 19–42% more realized volume than the best alternative.


🔸 LIMITATIONS AND HONEST NOTES

• The forecast for a session is set when that session opens and is not repainted; the realized half updates live as the session trades.
• It estimates a distribution of volume, not a promise of direction. The bias %, expected levels and HVN set are probability-weighted readings of that distribution.
• The filter is stochastic by nature: two chart reloads can differ in fine detail, the way two runs of any Monte Carlo method do. The structure it finds is stable; the pixel-level noise is not.
• Requires volume data from your data feed. Not supported on non-standard chart types.
• The chart timeframe must be lower than the session timeframe.

免責聲明

這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。