OPEN-SOURCE SCRIPT
AetherEdge - Particle Swarm Filter

🖊️ Overview
AE-SWARM tracks the market's hidden trend with a particle filter (sequential Monte Carlo). A swarm of hypotheses (particles) predicts, gets weighted by how well it explains the new price, and resamples — fit survive, unfit die. The swarm is drawn as a translucent point cloud on the latest bar, condensing into a tight band when confident and scattering into fog when uncertain — like fireflies. The swarm mean is the estimated trend, its spread the uncertainty, its mean velocity the momentum.
🔶 Key Features
Particle filter (sequential Monte Carlo): tracks hidden trend state with a swarm
Damped constant-velocity model: [level, velocity] state space
Systematic resampling: resamples particles when ESS collapses
Volatility-adaptive noise: process/observation noise scaled by ATR
Firefly particle cloud: swarm drawn as points on the latest bar
Uncertainty band: swarm spread as a ±spread band
BUY/SELL on swarm convergence + velocity flip
HUD showing effective sample size (ESS) and convergence state
No repaint: randomness seeded by bar
Per-event alerts
🧠 Technical Architecture
This implements a particle filter (sequential Monte Carlo). Each particle holds a damped constant-velocity state [level, velocity] (level += velocity; velocity = φ·velocity + ε), running each confirmed bar: PREDICT — propagate each particle with Gaussian process noise. WEIGHT — score each by observation likelihood w_i ∝ N(price | level_i, σ_obs²), normalize. RESAMPLE — when effective sample size ESS = 1/Σw_i² drops below threshold, systematic resampling duplicates high-weight particles and prunes low-weight ones. ESTIMATE — weighted mean is the trend, weighted stdev the uncertainty, mean velocity the momentum. Process/observation noise scale with ATR. Randomness is Box-Muller, seeded by bar index so it does not repaint. Signals fire when swarm velocity flips sign while the swarm is converging (spread shrinking). Particle updates run on confirmed bars only.
⚙️ Recommended Settings & Tuning Guide
Particle Count 40 is a starting point — more gives a smoother estimate but is heavier (max 80). Velocity Persistence (φ) 0.92 damps the velocity state — near 1 is random-walk velocity, lower is mean-reverting momentum. Process Noise: Velocity 0.15×ATR is how much velocity hypotheses jitter — higher is reactive and noisier. Observation Noise 0.6×ATR is the assumed price measurement noise — higher gives looser weighting and a broader swarm, lower is sharper but can degenerate. Resample when ESS < 0.5×N is the resample threshold. Require Swarm Convergence ON fires only when the swarm is converging (rising confidence) at the velocity flip.
💡 How to Use in Practice
Apply to chart and the swarm scatters like fireflies on the latest bar. A tight, condensed band means the swarm has converged (high confidence); a scattered fog means uncertainty. The swarm mean line is the estimated trend, colored by velocity sign. The uncertainty band (±spread) width shows the swarm's scatter. Check "eff. sample size" in the HUD for particle diversity; low ESS is the resampling moment. When swarm velocity flips while converging (HUD shows "converging"), a signal fires as a confident change of heading. Higher process noise is more reactive; lower is smoother.
⚠️ Important Notes
This is a genuine particle filter, but with a modest particle count for Pine's compute budget, systematic resampling, and ATR-scaled (not learned) noise. Randomness is seeded by bar index so it does not repaint, but real-time bars show the last confirmed state. As a stochastic simulation, details can vary with the particles' initial scatter even at the same settings. The swarm estimate is a guide to the trend, not a certain prediction. Particle updates run on confirmed bars only. All signals are probabilistic decisions based on historical data and do not guarantee future profits.
🚨 Disclaimer
This indicator is provided for educational and informational purposes only and does not constitute financial or investment advice. No signal guarantees future profit, and past performance does not indicate future results. All trading decisions are made at your own risk.
AE-SWARM tracks the market's hidden trend with a particle filter (sequential Monte Carlo). A swarm of hypotheses (particles) predicts, gets weighted by how well it explains the new price, and resamples — fit survive, unfit die. The swarm is drawn as a translucent point cloud on the latest bar, condensing into a tight band when confident and scattering into fog when uncertain — like fireflies. The swarm mean is the estimated trend, its spread the uncertainty, its mean velocity the momentum.
🔶 Key Features
Particle filter (sequential Monte Carlo): tracks hidden trend state with a swarm
Damped constant-velocity model: [level, velocity] state space
Systematic resampling: resamples particles when ESS collapses
Volatility-adaptive noise: process/observation noise scaled by ATR
Firefly particle cloud: swarm drawn as points on the latest bar
Uncertainty band: swarm spread as a ±spread band
BUY/SELL on swarm convergence + velocity flip
HUD showing effective sample size (ESS) and convergence state
No repaint: randomness seeded by bar
Per-event alerts
🧠 Technical Architecture
This implements a particle filter (sequential Monte Carlo). Each particle holds a damped constant-velocity state [level, velocity] (level += velocity; velocity = φ·velocity + ε), running each confirmed bar: PREDICT — propagate each particle with Gaussian process noise. WEIGHT — score each by observation likelihood w_i ∝ N(price | level_i, σ_obs²), normalize. RESAMPLE — when effective sample size ESS = 1/Σw_i² drops below threshold, systematic resampling duplicates high-weight particles and prunes low-weight ones. ESTIMATE — weighted mean is the trend, weighted stdev the uncertainty, mean velocity the momentum. Process/observation noise scale with ATR. Randomness is Box-Muller, seeded by bar index so it does not repaint. Signals fire when swarm velocity flips sign while the swarm is converging (spread shrinking). Particle updates run on confirmed bars only.
⚙️ Recommended Settings & Tuning Guide
Particle Count 40 is a starting point — more gives a smoother estimate but is heavier (max 80). Velocity Persistence (φ) 0.92 damps the velocity state — near 1 is random-walk velocity, lower is mean-reverting momentum. Process Noise: Velocity 0.15×ATR is how much velocity hypotheses jitter — higher is reactive and noisier. Observation Noise 0.6×ATR is the assumed price measurement noise — higher gives looser weighting and a broader swarm, lower is sharper but can degenerate. Resample when ESS < 0.5×N is the resample threshold. Require Swarm Convergence ON fires only when the swarm is converging (rising confidence) at the velocity flip.
💡 How to Use in Practice
Apply to chart and the swarm scatters like fireflies on the latest bar. A tight, condensed band means the swarm has converged (high confidence); a scattered fog means uncertainty. The swarm mean line is the estimated trend, colored by velocity sign. The uncertainty band (±spread) width shows the swarm's scatter. Check "eff. sample size" in the HUD for particle diversity; low ESS is the resampling moment. When swarm velocity flips while converging (HUD shows "converging"), a signal fires as a confident change of heading. Higher process noise is more reactive; lower is smoother.
⚠️ Important Notes
This is a genuine particle filter, but with a modest particle count for Pine's compute budget, systematic resampling, and ATR-scaled (not learned) noise. Randomness is seeded by bar index so it does not repaint, but real-time bars show the last confirmed state. As a stochastic simulation, details can vary with the particles' initial scatter even at the same settings. The swarm estimate is a guide to the trend, not a certain prediction. Particle updates run on confirmed bars only. All signals are probabilistic decisions based on historical data and do not guarantee future profits.
🚨 Disclaimer
This indicator is provided for educational and informational purposes only and does not constitute financial or investment advice. No signal guarantees future profit, and past performance does not indicate future results. All trading decisions are made at your own risk.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
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.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
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.