OPEN-SOURCE SCRIPT

BioSwarm Imprinter™

99
BioSwarm Imprinter™ — Agent-Based Consensus for Traders

What it is

BioSwarm Imprinter™ is a non-repainting, agent-based sentiment oscillator. It fuses many short-to-medium lookback “opinions” into one 0–100 consensus line that is easy to read at a glance (50 = neutral, >55 bullish bias, <45 bearish bias). The engine borrows from swarm intelligence: many simple voters (agents) adapt their influence over time based on how well they’ve been predicting price, so the crowd gets smarter as conditions change.

Use it to:
• Detect emerging trends sooner without overreacting to noise.
• Filter mean-reversion vs continuation opportunities.
• Gate entries with a confidence score that reflects both strength and persistence of the move.
• Combine with your execution tools (VWAP/ORB/levels) as a state filter rather than a trade signal by itself.



Why it’s different
• Swarm learning: Each agent improves or decays its “fitness” depending on whether its vote matched the next bar’s direction. High-fitness agents matter more; weak agents fade.
• Multi-horizon by design: The crowd is composed of fixed, simple lookbacks spread from lenMin to lenMax. You get a blended, robust view instead of a single fragile parameter.
• Two complementary lenses: Each agent evaluates RSI-style balance (via Wilder’s RMA) and momentum (EMA deviation). You decide the weight of each.
• No repaint, no MTF pitfalls: Everything runs on the chart’s timeframe with bar-close confirmation; no request.security() or forward references.
• Actionable UI: A clean consensus line, optional regime background, confidence heat, and triangle markers when thresholds are crossed.



What you see on the chart
• Consensus line (0–100): Smoothed to your preference; color/area makes bull/bear zones obvious.
• Regime coloring (optional): Light green in bull zone, light red in bear zone; neutral otherwise.
• Confidence heat: A small gauge/number (0–100) that combines distance from neutral and recent persistence.
• Markers (optional): Triangles when consensus crosses up through your bull threshold (e.g., 55) or down through your bear threshold (e.g., 45).
• Info panel (optional): Consensus value, regime, confidence, number of agents, and basic diagnostics.



How it works (under the hood)
1. Horizon bins: The range [lenMin … lenMax] is divided into numBins. Each bin has a fixed, simple integer length (crucial for Pine’s safety rules).
2. Per-bin features (computed every bar):
• RSI-style balance using Wilder’s RMA (not ta.rsi()), then mapped to −1…+1.
• Momentum as (close − EMA(L)) / EMA(L) (dimensionless drift).
3. Agent vote: For its assigned bin, an agent forms a weighted score: score = wRSI*RSI_like + wMOM*Momentum. A small dead-band near zero suppresses chop; votes are +1/−1/0.
4. Fitness update (bar close): If the agent’s previous vote agreed with the next bar’s direction, multiply its fitness by learnGain; otherwise by learnPain. Fitness is clamped so it never explodes or dies.
5. Consensus: Weighted average of all votes using fitness as weights → map to 0–100 and smooth with EMA.

Why it doesn’t repaint:
• No future references, no MTF resampling, fitness updates only on confirmed bars.
• All TA primitives (RMA/EMA/deltas) are computed every bar unconditionally.



Signals & confidence
• Bullish bias: consensus ≥ bullThr (e.g., 55).
• Bearish bias: consensus ≤ bearThr (e.g., 45).
• Confidence (0–100):
• Distance score: how far consensus is from 50.
• Momentum score: how strong the recent change is versus its recent average.
• Combined into a single gate; start filtering entries at ≥60 for higher quality.

Tip: For range sessions, raise thresholds (60/40) and increase smoothing; for momentum sessions, lower smoothing and keep thresholds at 55/45.



Inputs you’ll actually tune
• Agents & horizons:
• N_agents (e.g., 64–128)
• lenMin / lenMax (e.g., 6–30 intraday, 10–60 swing)
• numBins (e.g., 12–24)
• Weights & smoothing:
• wRSI vs wMOM (e.g., 0.7/0.3 for FX & indices; 0.6/0.4 for crypto)
• deadBand (0.03–0.08)
• consSmooth (3–8)
• Thresholds & hygiene:
• bullThr/bearThr (55/45 default)
• cooldownBars to avoid signal spam



Playbooks (ready-to-use)

1) Breakout / Trend continuation
• Timeframe: 15m–1h for day/swing.
• Filter: Take longs only when consensus > 55 and confidence ≥ 60.
• Execution: Use your ORB/VWAP/pullback trigger for entry. Trail with swing lows or 1.5×ATR. Exit on a close back under 50 or when a bearish signal prints.

2) Mean reversion (fade)
• When: Sideways days or low-volatility clusters.
• Setup: Increase deadBand and consSmooth.
• Signal: Bearish fades when consensus rolls over below ≈55 but stays above 50; bullish fades when it rolls up above ≈45 but stays below 50.
• Targets: The neutral zone (~50) as the first take-profit.

3) Multi-TF alignment
• Keep BioSwarm on 1H for bias, execute on 5–15m:
• Only take entries in the direction of the 1H consensus.
• Skip counter-bias scalps unless confidence is very low (explicit mean-reversion plan).



Integrations that work
• DynamoSent Pro+ (macro bias): Only act when macro bias and swarm consensus agree.
• ORB + Session VWAP Pro: Trade London/NY ORB breakouts that retest while consensus >55 (long) or <45 (short).
• Levels/Orderflow: BioSwarm is your “go / no-go”; execution stays with your usual triggers.



Quick start
1. Drop the indicator on a 1H chart.
2. Start with: N_agents=64, lenMin=6, lenMax=30, numBins=16, deadBand=0.06, consSmooth=5, thresholds 55/45.
3. Trade only when confidence ≥ 60.
4. Add your favorite execution tool (VWAP/levels/OR) for entries & exits.



Non-repainting & safety notes
• No request.security(); no hidden lookahead.
• Bar-close confirmation for fitness and signals.
• All TA calls are unconditional (no “sometimes called” warnings).
• No series-length inputs to RSI/EMA — we use RMA/EMA formulas that accept fixed simple ints per bin.



Known limits & tips
• Too many signals? Raise deadBand, increase consSmooth, widen thresholds to 60/40.
• Too few signals? Lower deadBand, reduce consSmooth, narrow thresholds to 53/47.
• Over-fitting risk: Keep learnGain/learnPain modest (e.g., ×1.04 / ×0.96).
• Compute load: Large N_agents × numBins is heavier; scale to your device.



Example recipes

EURUSD 1H (swing):
lenMin=8, lenMax=34, numBins=16, wRSI=0.7, wMOM=0.3, deadBand=0.06, consSmooth=6, thr=55/45
Buy breakouts when consensus >55 and confidence ≥60; confirm with 5–15m pullback to VWAP or level.

SPY 15m (US session):
lenMin=6, lenMax=24, numBins=12, consSmooth=4, deadBand=0.05
On trend days, stay with longs as long as consensus >55; add on shallow pullbacks.

BTC 1H (24/7):
Increase momentum weight: wRSI=0.6, wMOM=0.4, extend lenMax to ~50. Use dynamic stops (ATR) and partials on strong verticals.



Final word

BioSwarm is a state engine: it tells you when the market is primed to continue or mean-revert. Pair it with your entries and risk framework to turn that state into trades. If you’d like, I can supply a companion strategy template that consumes the consensus and back-tests the three playbooks (Breakout/Fade/Flip) with standard risk management.

免责声明

这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。