OPEN-SOURCE SCRIPT

AetherEdge - Multi-Armed Bandit

230
🖊️ Overview

AE-MAB is a self-evolving signal allocator that treats a panel of sub-signals as the "arms" of a bandit and learns which to trust now. Each classic signal — trend, momentum, breakout, mean-reversion, MACD — carries a Bayesian Beta(α,β) posterior over its directional hit-rate, updated online with forgetting from realized hits/misses (the reward). Allocation weights come from Thompson Sampling (sampling each posterior) or UCB (mean + confidence bound), both balancing exploration of uncertain arms against exploitation of proven ones. The final signal is the credibility-weighted vote of the arms.

🔶 Key Features

Multi-armed bandit engine — runs 5 sub-signals as arms and dynamically weights toward whichever is working now.
Reward & Bayesian learning — each arm's directional hit/miss is the reward, updating a Beta(α,β) posterior online with forgetting.
Exploration & exploitation — switch between Thompson Sampling (sample the posteriors, occasionally trying uncertain arms) and UCB (mean + confidence bound).
Self-evolving beliefs — a forgetting factor weights recent performance; as the market shifts, the trusted arm quietly changes.
Credibility panel — lists each arm's direction, credibility bar (Beta posterior mean), and allocation weight, with the current lead signal glowing.
Credibility-weighted allocation — a continuous allocation (−1 to +1) of arm directions weighted by credibility is the final signal, reflected in the price background and markers.
Live statistics panel — final signal, conviction, lead arm, allocation value, bandit P&L, and forgetting factor.
Deterministic, non-repainting design — Thompson's RNG is seed-fixed (no intrabar flicker); learning on confirmed bars only, no look-ahead.

🧠 Technical Architecture

Each bar, the 5 arms emit a directional view (+1/0/−1): trend (EMA cross), momentum (RSI), breakout (Donchian), mean-reversion (z-score, contrarian), MACD. On each confirmed bar, posteriors first decay toward the prior Beta(1,1), then the previous bar's view is checked against the realized return — a hit adds α+=1, a miss β+=1 (one-bar lag, no look-ahead). This is the reward-driven self-evolution.
Scores are: in UCB mode mean + c·std (mean = α/(α+β), std = the Beta distribution's width); in Thompson mode a sample from a Gaussian approximation of the Beta posterior clip(mean + σ·z, 0,1) (z from a deterministic LCG + Box-Muller standard normal). Positive scores are normalized into weights w_a, giving the credibility-weighted allocation alloc = Σ w_a·dir_a ∈ [−1,1]. The lead arm is the highest-scoring one. Allocation beyond the deadband calls Long/Short; inside it, Flat.

🎯 Three design choices stand out. First, the Beta posterior's width (uncertainty) directly drives exploration — arms with little evidence are occasionally sampled high under Thompson and get a higher confidence bound under UCB, so they get tried. Second, forgetting adapts to non-stationary markets, naturally lowering the weight of arms that stop working. Third, a deterministic RNG plus confirmed-bar updates keep historical signals non-repainting.

⚙️ Recommended Settings & Tuning Guide

As a crypto starting point — BTC/ETH (1D, 4H): Strategy = Thompson, adaptation λ = 0.97, deadband 0.15; the lead signal rotates smoothly with regime. High-volatility names (SOL, XRP): lower λ toward 0.95 for faster adaptation, and raise the deadband to 0.20 to avoid trading on weak consensus. For more deterministic behavior, switch to UCB (c ≈ 1.0).
Per parameter: Strategy (Thompson/UCB) sets the quality of exploration — Thompson is stochastic and diverse, UCB deterministic and steady. Adaptation λ sets learning memory (0.99 = stable/long, 0.95 = nimble). UCB c sets exploration strength. Deadband sets the consensus strength required to fire. Sub-signal lengths are tuned to your timeframe.

💡 How to Use in Practice

The core read is final signal × conviction. When allocation swings strongly one way (high conviction) and several arms in the credibility panel agree, that's cross-regime consensus — a tailwind for trend-following. The moment the lead arm changes (e.g., from Trend to MeanRev) signals the type of edge that's working has shifted. The credibility bars show at a glance which logic (trend vs contrarian) currently dominates the market. When conviction is low and arms disagree, no logic is working well — an unstable phase where standing aside is wise.
For multi-timeframe work, read the higher-timeframe lead arm for the macro-effective logic and execute on lower-timeframe signals. Bandit P&L offers a sense of the allocator's in-sample traction.

⚠️ Important Notes

Signals are hidden until the warmup period (default 100 bars) completes. Reloading the indicator rebuilds the posteriors from scratch — learning state is not persisted. Thompson sampling uses a Gaussian approximation of the Beta, not exact Beta draws (the approximation is coarse with little early evidence). The panel's "Bandit P&L" is an in-sample metric that excludes trading cost and slippage. The arms are fixed classic rules — the bandit selects among them, it does not invent new signals. Updates occur on confirmed bars only.

🚨 Disclaimer

This indicator is for educational and informational purposes only and does not constitute financial or investment advice. Past performance is not indicative of future results. All trading involves risk. Use it alongside your own thorough testing and sound risk management; all trading decisions remain solely your own responsibility.

Thông báo miễn trừ trách nhiệm

Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.