OPEN-SOURCE SCRIPT

AetherEdge - A2C Advantage Critic

278
🖊️ Overview

A self-evolving Advantage Actor-Critic (A2C) agent that trains two neural networks in tandem: an Actor that selects actions and a Critic that estimates state value. Their interplay produces the advantage A = R + γV(s′) − V(s) — the signed "surprise" of an outcome relative to what the Critic expected — which both trains the Actor and filters the signals: arrows fire only when the advantage is decisively in favor of a direction, naturally rejecting noisy conditions. Learning from experience on your chart, it visualizes its decisions with clean arrows and a single Critic-value histogram whose intensity encodes the strength of its valuation.

🔶 Key Features

Joint Actor-Critic learning — a shared trunk forks into an Actor head (softmax policy) and a Critic head (state value V(s)), trained together
Advantage filtering — signals fire only when |advantage| clears a gate, excluding low-conviction conditions (the heart of the A2C filter)
TD-error advantage — A = R + γV(s′) − V(s) as the action-evaluation signal
Entropy bonus — prevents premature Actor collapse onto one action, encouraging exploration
Prioritized Sampling (PER) — high-advantage transitions learned preferentially
Clean directional arrows — only filtered, decisive Long/Short signals are shown
Critic value histogram — normalized state value drawn as a single column, with intensity (opacity/height) encoding valuation strength
Intelligence panel — Actor per-action probabilities, selected action with filter status, Critic value, advantage, and buffer state at a glance

🧠 Technical Architecture

The agent perceives the market as a four-dimensional state vector: momentum spread (ATR-normalized fast/slow EMA gap), RSI deviation, a volatility-regime ratio, and position-within-range — all z-normalized. This state passes through a NeuraLib-style Actor-Critic network: a shared trunk (tanh hidden) forks into two heads. The Actor head produces three logits → softmax policy π(a|s); the Critic head produces a scalar state value V(s).
The core is the advantage. For a transition (s, a, r, s′), the Critic computes the TD target R + γV(s′) and the advantage A = R + γV(s′) − V(s) — a signed measure of how much better action a was than expected. The Actor updates via the advantage-weighted policy gradient ∇ = A·(𝟙[a] − p) (raising the chosen action's probability when advantage is positive, lowering it when negative), plus an entropy bonus. The Critic regresses toward the TD target via squared error. Both gradients backpropagate manually into the shared trunk, with separate Actor and Critic learning rates (a slightly faster Critic keeps the baseline tracking the Actor).
For signal filtering, the live advantage is EMA-smoothed and arrows fire only when its magnitude clears the gate. The Critic value histogram z-normalizes the state value over a rolling window, drawing a single column colored by sign (positive greenish, negative reddish) with opacity scaled by magnitude.

⚙️ Recommended Settings & Tuning Guide

BTC (1H–4H): Training Horizon 800–1500, γ 0.94, Actor LR 0.03 / Critic LR 0.05, Advantage Gate 0.35, Hidden 8. Standard settings fit well
ETH (1H–4H): As BTC, with Reward Lookahead 5–8 to value slightly longer advantage
SOL (15m–1H): High volatility favors Advantage Gate 0.4–0.5 (stricter filter), Advantage Smoothing 4–5 to curb noise, ATR-normalization always ON
XRP (1H–4H): Spike-prone; a higher Advantage Gate, Critic LR 0.05–0.07 for baseline accuracy
Advantage Gate (filter): higher (0.4–0.6) gives fewer, higher-quality signals; lower (0.2–0.3) gives more but noisier — tune to your trade frequency
Actor LR / Critic LR: keep the Critic faster than the Actor (≈1.3–1.7×) for stability; lower both if diverging
Entropy Bonus: raise to 0.02–0.05 if the Actor biases too early to one side

💡 How to Use in Practice

Reacting to filtered arrows: every arrow shown has already cleared the advantage gate — an edge confirmed beyond the Critic's expectation, a high-confidence basis for trend-following entries
Reading the Critic histogram: a large green column = the Critic strongly values the current state (upside expectation); a large red column = strong negative valuation (downside). Taller, more opaque columns mean stronger Critic conviction
Arrow + histogram alignment: a Long arrow with a strong green column, or a Short arrow with a strong red column, is the most coherent setup; stand aside when they disagree
Advantage convergence: when the panel's advantage hovers near the gate, the call is balanced; a decisive break of the gate marks the entry opportunity
Multi-timeframe usage: read the big-picture Critic valuation on the higher timeframe (4H), then refine timing on filtered arrows on the lower one (15m–1H)
Combinations: use divergence between price and the Critic histogram (price at highs but Critic valuation falling) as an early reversal warning

⚠️ Important Notes

Initial learning period: right after launch the buffer is nearly empty and both Actor and Critic are unstable; treat signals as low-confidence until it fills (several hundred bars)
Learning resets: changing parameters, switching symbol/timeframe, or recompiling reinitializes the network weights and buffer, restarting learning from zero
Critic normalization: the histogram is a rolling-window z-score, showing relative strength rather than an absolute level; values are unstable until the window fills
On forward-looking reward: rewards and advantage use closed-bar forward returns (a standard RL training construct); current-bar evaluation is on confirmed values, but as with any adaptive system, historical and live behavior can differ — always forward-test
Constraints: this is a lightweight implementation operating within Pine's compute budget

🚨 Disclaimer

This indicator is an analytical and educational visualization tool. The Advantage Actor-Critic, Actor/Critic networks, advantage computation, reward shaping, and outputs are quantitative heuristics computed on-chart from price data — they are not financial advice, buy/sell signals, or any guarantee of future performance. Reinforcement-learning agents can and do make wrong calls. Always combine any tool with your own analysis and disciplined risk management.

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.