OPEN-SOURCE SCRIPT

AetherEdge RL Signal Optimizer

364
🖊️ Overview
AetherEdge RL Signal Optimizer is a truly self-optimizing signal engine powered by a complete Q-Learning (TD-learning) implementation. It discretizes the market into 18 states, explores Long/Short/Skip actions through trial-and-error, updates Q-values via the Bellman equation, and dynamically balances exploration vs exploitation through ε-greedy decay. Combined with statistical TP/SL learning from MFE/MAE tracking, it is a living reinforcement-learning system where both policy and risk-management evolve with every trade.

🔶 Key Features

Full Q-Learning Implementation (TD(0)): 18 states × 3 actions Q-table
ε-Greedy Exploration: Auto-decay from 30% → 5%, solving the exploration/exploitation dilemma
State Discretization: Trend(3) × RSI(3) × Volatility(2) = 18 states
Reward Function: n-step ATR-normalized return + skip penalty
MFE/MAE Learning: Statistical TP/SL estimation from up to 200 trades
Dynamic TP/SL: Quantile-based optimal levels (TP=70%, SL=85% confidence)
Q-Spread Confidence: Best vs second-best Q gap as conviction proxy
Q-Table Heatmap: All 18 states visualized with color-graded Q-values
Learning Progress Bar: EXPLORING → MIXING → EXPLOITING phases
Performance Tracking: Win rate, avg reward, recent 50-reward MA
Current-State Highlight: On-chart directional box

🧠 Technical Architecture

This indicator is a complete reinforcement-learning agent running natively on TradingView.

State Space (18 states):
Trend Index: EMA20-50 spread (Bear/Flat/Bull)
RSI Index: Low/Mid/High
Volatility Index: ATR short/long ratio (Low/High)
Combined: state = trend×6 + rsi×2 + vol
Action Space (3 actions): 0=Long, 1=Short, 2=Skip
Q-Update (Bellman Equation):
Q(s,a) ← Q(s,a) + α × [r + γ·max Q(s',a') - Q(s,a)]
Reward Function:
Long → r = (close - close[n]) / ATR[n]
Short → r = -(close - close[n]) / ATR[n]
Skip → r = skipPenalty (-0.05)
ε-Greedy Policy:
With probability ε: random exploration; else greedy
Linear decay: epsStart → epsEnd over epsDecayLen
Pseudo-random: sin(seed×12.9898 + 78.233) for reproducibility
TP/SL Learning Engine:
Track MFE/MAE for trackBars after each signal
Separate Long/Short buffers, max 200 trades each
TP = 70th percentile of MFE; SL = 85th percentile of MAE
Safe defaults when data insufficient (TP=2.0×, SL=1.5×ATR)
Q-Spread Confidence: Signal fires only if best - second_best ≥ minConfidence
State Coverage Tracking: Percentage of (state, action) cells visited

⚙️ Recommended Settings & Tuning Guide

Crypto Defaults:

BTC (4H): α=0.15, γ=0.90, epsDecay=500 (standard)
ETH (1H): α=0.20, γ=0.85, epsDecay=300 (fast-learn)
SOL (high-vol): α=0.10, γ=0.92, epsDecay=800 (careful)
XRP (short-term): α=0.25, epsDecay=200, rewardLook=2
Q-Learning Hyperparameters:

α (Learning Rate):
0.05–0.10: conservative, noise-resilient
0.15: standard
0.25–0.40: fast adaptation, unstable risk
γ (Discount):
0.80: short-term view, immediate reward
0.90: standard
0.95–0.99: long-term strategy, delayed reward
ε Decay:
200: rapid learning, low data
500: standard
1000+: thorough exploration, HTF use
TP/SL Optimization:

tpConfidence=0.5: conservative TP (early profit)
tpConfidence=0.7: standard
tpConfidence=0.9: greedy TP (miss risk)
slConfidence=0.85: standard (tolerate 85% drawdowns)
Min Q-Spread:

0.05: many signals, noise included
0.15: standard
0.30: ultra-curated, fewer opportunities

💡 How to Use in Practice

EXPLOITING phase (ε≤0.08): Maximum signal trust, live trading
EXPLORING phase (ε>0.20): Learning, signals are reference only
MIXING phase: Transitional, observe carefully
CONFIDENT + LONG/SHORT: Sufficient Q-spread, entry candidate
UNCERTAIN: Ambiguous state, skip recommended
Q-Table Observation:
All-green rows: bullish bias learned
High Visits = high cell reliability
"—" displayed: unvisited cells, insufficient data
Trade Scenarios:
Bull · RSI↓ · LoVol with max Q[Long]: Pullback-buy pattern learned
Bear · RSI↑ · HiVol with max Q[Short]: Bounce-sell pattern learned
Learned TP/SL with 1:2.5 R:R: Trade only after statistical edge confirmed
AetherEdge Synergy:
SMC AI Confidence Engine: A+ zone + RL Long = double rationale
NeuraNet Predictor: Direction match + RL CONFIDENT = high probability
Self-Evolving S/R Grid: Strong line touch + RL signal = supreme alignment
All-in-One Dashboard: HIGH-CONVICTION + RL EXPLOITING = ultimate confluence

⚠️ Important Notes

Learning Reset Issue: Q-table resets on chart reload or timeframe change—relearning required
Initial Learning Period: Run at least epsDecayLen × 1.5 bars before live use
State Coverage: <50% means many unvisited states; 80%+ recommended for stability
Overfitting Risk: High α over-fits to recent noise; HTF requires lower α
MFE/MAE Buffer: At least 20+ trades needed for reliable TP/SL
Pseudo-Random: bar_index-based, so same moment yields same exploration
Signal Latency: Operates on barstate.isconfirmed; signals confirm after bar close

🚨 Disclaimer

This indicator is a reinforcement-learning demonstration for educational and research purposes only and does not constitute financial advice. Q-Learning is a stochastic optimization method and does not guarantee future profits. Learning outcomes depend strongly on environment and data; past performance does not predict future results. Use with thorough validation and proper risk management.

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

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