OPEN-SOURCE SCRIPT
AetherEdge Self-Evolving S/R Grid

🖊️ Overview
AetherEdge Self-Evolving S/R Grid is a revolutionary self-evolving support & resistance system that brings the philosophy of Q-learning into technical analysis. It learns from market reactions—rejections, breaks, and flips—as "rewards," automatically pruning low-value lines and constructing a Darwinian S/R grid where only functional levels survive. Moving beyond static line-drawing tools, it delivers a truly intelligent price-structure map that breathes and evolves alongside the market itself.
🔶 Key Features
Q-Learning-Style Score Updates: Reinforcement learning replicated through α (learning rate), γ (discount factor), and ε (exploration rate)
Self-Evolving Line Lifecycle: Fully automated birth → learning → reinforcement/pruning cycle
Multi-Source Grid Generation: Pivots / Williams Fractals / Round Numbers / Swing Extremes
Dynamic Reward System: Reject reward, break penalty, S/R flip bonus
ATR-Based Sensitivity: Market-adaptive touch tolerance and break confirmation
Volume-Weighted Reaction Detection: Filters out thin-volume false signals
Score-Based Visualization: Dynamic color, width, and transparency by line strength
Strong Zone Highlighting: Threshold-exceeding lines visually emphasized
Dying Line Display: Pre-pruning lines fade visibly
Comprehensive Stats Panel: Cumulative tracking of generations, deletions, rejects, breaks, flips
Safe Coordinate System: MAX_BARS_BACK clamping to prevent drawing errors on legacy bars
🧠 Technical Architecture
This indicator is an advanced system that reconstructs core reinforcement-learning concepts in Pine Script.
Q-Learning Update Equation: Applies newQ = Q + α × (R + γ × maxFutureQ − Q) to every active line each bar. Each line carries its own "value (Q-value)" and self-updates through market experience.
Reward Function: Price-line interactions are classified into three categories—rejection (+rejectReward), break (−breakPenalty), and S/R flip (+flipReward). Rewards are amplified when volume exceeds the moving average.
Exploration vs. Exploitation Dilemma: explorationRate governs new-line generation frequency. High ε aggressively probes uncharted price zones; low ε prioritizes exploitation of high-Q-value lines.
Grid Generation Strategy: Candidate prices extracted from four sources, deduplicated via existsNear(), validated against psychological levels via isRoundNumber(), and rendered safely using safeX1().
Line Lifecycle: bornBar → lastTouchBar → touches/rejects/breaks/flips accumulation → score update → if below minScore, active=false → automatic deletion.
Score Decay Mechanism: Unreacted lines decay by decayPerBar each bar, naturally pruning non-functional lines through a self-cleansing mechanism.
S/R Flip Detection: After a break, line type inverts; the pendingFlip flag monitors retests, and a flip reward is granted upon successful confirmation.
Visualization Layer: Dynamic line widths (>0.7=3px / >0.5=2px / else=1px) and transparency (80−score×60) by score.
Stats Panel: Five metrics cumulatively tracked via the stats array, with globalSuccessRate aggregating system-wide performance.
⚙️ Recommended Settings & Tuning Guide
Crypto Defaults:
BTC (4H): learningRate=0.15, gridSpacingATR=1.5, maxLines=40, pivotStrength=10
ETH (1H): learningRate=0.20, gridSpacingATR=1.2, maxLines=50, genFrequency=15
SOL/XRP (15M): learningRate=0.25, gridSpacingATR=1.0, maxLines=60, decayPerBar=0.002
Long-Term (1D): learningRate=0.10, gridSpacingATR=2.5, maxLines=30, minScore=0.30
Tuning Guide:
Conservative Learning: α=0.05, γ=0.95 for slow, steady evolution—ideal for long-term trends
Aggressive Learning: α=0.30, ε=0.40 for rapid adaptation—ideal for high-volatility markets
Strict Pruning: minScore=0.35, decayPerBar=0.003 to keep only functional lines
Lenient Pruning: minScore=0.10, decayPerBar=0.0005 to retain more lines
High-Density Grid: gridSpacingATR=0.8, maxLines=80 for scalping
Sparse Grid: gridSpacingATR=3.0, maxLines=20 for long-term swing trading
Volume-Focused: Enable volumeBoost to reward only genuine reactions
Flip Hunting: flipReward=1.0 to emphasize structural reversals
💡 How to Use in Practice
Strong Lines (Yellow Highlight): colStrong lines represent high-Q-value proven levels—enter on confirmed rejection
S/R Flip Tracking: Post-break retest from the opposite side confirms a flip—powerful trend continuation signal
Breakout Strategy: Close beyond breakConfirm × ATR confirms the break—use as the origin of a new trend
Reverse Use of Dying Lines: colDying lines have lost relevance—useful as a filter to ignore stale levels
Multi-Timeframe Integration: Use higher-TF strong lines as anchor entries on lower TFs
AetherEdge Synergy: Combine with Pattern Recognition Trendline for pattern × S/R grid double confirmation
Round-Number Strategy: High-Q lines born from round numbers reflect psychological/institutional support
Grid Trading: High-density settings enable mechanical execution in ranging markets
⚠️ Important Notes
Initial Learning Period: At least 200–500 bars of data accumulation is required before signal quality stabilizes
Learning Reset: Settings changes or chart reloads reset all Q-values, requiring relearning
The ε Trap: Excessive exploration breeds low-quality lines; insufficient exploration delays adaptation
MAX_BARS_BACK Constraint: bornBar values older than 4500 bars are automatically clamped
maxLines Cap: When exceeded, oldest/lowest-score lines are auto-pruned
Regime Changes: During abrupt market shifts, legacy lines may temporarily lose validity until decay resolves them
🚨 Disclaimer
This indicator is a technical analysis tool provided for educational and research purposes only and does not constitute financial advice. Q-learning-style scores are evaluations based on historical price reactions and do not guarantee future performance. All trading decisions are made at your own risk and should be accompanied by proper risk management.
AetherEdge Self-Evolving S/R Grid is a revolutionary self-evolving support & resistance system that brings the philosophy of Q-learning into technical analysis. It learns from market reactions—rejections, breaks, and flips—as "rewards," automatically pruning low-value lines and constructing a Darwinian S/R grid where only functional levels survive. Moving beyond static line-drawing tools, it delivers a truly intelligent price-structure map that breathes and evolves alongside the market itself.
🔶 Key Features
Q-Learning-Style Score Updates: Reinforcement learning replicated through α (learning rate), γ (discount factor), and ε (exploration rate)
Self-Evolving Line Lifecycle: Fully automated birth → learning → reinforcement/pruning cycle
Multi-Source Grid Generation: Pivots / Williams Fractals / Round Numbers / Swing Extremes
Dynamic Reward System: Reject reward, break penalty, S/R flip bonus
ATR-Based Sensitivity: Market-adaptive touch tolerance and break confirmation
Volume-Weighted Reaction Detection: Filters out thin-volume false signals
Score-Based Visualization: Dynamic color, width, and transparency by line strength
Strong Zone Highlighting: Threshold-exceeding lines visually emphasized
Dying Line Display: Pre-pruning lines fade visibly
Comprehensive Stats Panel: Cumulative tracking of generations, deletions, rejects, breaks, flips
Safe Coordinate System: MAX_BARS_BACK clamping to prevent drawing errors on legacy bars
🧠 Technical Architecture
This indicator is an advanced system that reconstructs core reinforcement-learning concepts in Pine Script.
Q-Learning Update Equation: Applies newQ = Q + α × (R + γ × maxFutureQ − Q) to every active line each bar. Each line carries its own "value (Q-value)" and self-updates through market experience.
Reward Function: Price-line interactions are classified into three categories—rejection (+rejectReward), break (−breakPenalty), and S/R flip (+flipReward). Rewards are amplified when volume exceeds the moving average.
Exploration vs. Exploitation Dilemma: explorationRate governs new-line generation frequency. High ε aggressively probes uncharted price zones; low ε prioritizes exploitation of high-Q-value lines.
Grid Generation Strategy: Candidate prices extracted from four sources, deduplicated via existsNear(), validated against psychological levels via isRoundNumber(), and rendered safely using safeX1().
Line Lifecycle: bornBar → lastTouchBar → touches/rejects/breaks/flips accumulation → score update → if below minScore, active=false → automatic deletion.
Score Decay Mechanism: Unreacted lines decay by decayPerBar each bar, naturally pruning non-functional lines through a self-cleansing mechanism.
S/R Flip Detection: After a break, line type inverts; the pendingFlip flag monitors retests, and a flip reward is granted upon successful confirmation.
Visualization Layer: Dynamic line widths (>0.7=3px / >0.5=2px / else=1px) and transparency (80−score×60) by score.
Stats Panel: Five metrics cumulatively tracked via the stats array, with globalSuccessRate aggregating system-wide performance.
⚙️ Recommended Settings & Tuning Guide
Crypto Defaults:
BTC (4H): learningRate=0.15, gridSpacingATR=1.5, maxLines=40, pivotStrength=10
ETH (1H): learningRate=0.20, gridSpacingATR=1.2, maxLines=50, genFrequency=15
SOL/XRP (15M): learningRate=0.25, gridSpacingATR=1.0, maxLines=60, decayPerBar=0.002
Long-Term (1D): learningRate=0.10, gridSpacingATR=2.5, maxLines=30, minScore=0.30
Tuning Guide:
Conservative Learning: α=0.05, γ=0.95 for slow, steady evolution—ideal for long-term trends
Aggressive Learning: α=0.30, ε=0.40 for rapid adaptation—ideal for high-volatility markets
Strict Pruning: minScore=0.35, decayPerBar=0.003 to keep only functional lines
Lenient Pruning: minScore=0.10, decayPerBar=0.0005 to retain more lines
High-Density Grid: gridSpacingATR=0.8, maxLines=80 for scalping
Sparse Grid: gridSpacingATR=3.0, maxLines=20 for long-term swing trading
Volume-Focused: Enable volumeBoost to reward only genuine reactions
Flip Hunting: flipReward=1.0 to emphasize structural reversals
💡 How to Use in Practice
Strong Lines (Yellow Highlight): colStrong lines represent high-Q-value proven levels—enter on confirmed rejection
S/R Flip Tracking: Post-break retest from the opposite side confirms a flip—powerful trend continuation signal
Breakout Strategy: Close beyond breakConfirm × ATR confirms the break—use as the origin of a new trend
Reverse Use of Dying Lines: colDying lines have lost relevance—useful as a filter to ignore stale levels
Multi-Timeframe Integration: Use higher-TF strong lines as anchor entries on lower TFs
AetherEdge Synergy: Combine with Pattern Recognition Trendline for pattern × S/R grid double confirmation
Round-Number Strategy: High-Q lines born from round numbers reflect psychological/institutional support
Grid Trading: High-density settings enable mechanical execution in ranging markets
⚠️ Important Notes
Initial Learning Period: At least 200–500 bars of data accumulation is required before signal quality stabilizes
Learning Reset: Settings changes or chart reloads reset all Q-values, requiring relearning
The ε Trap: Excessive exploration breeds low-quality lines; insufficient exploration delays adaptation
MAX_BARS_BACK Constraint: bornBar values older than 4500 bars are automatically clamped
maxLines Cap: When exceeded, oldest/lowest-score lines are auto-pruned
Regime Changes: During abrupt market shifts, legacy lines may temporarily lose validity until decay resolves them
🚨 Disclaimer
This indicator is a technical analysis tool provided for educational and research purposes only and does not constitute financial advice. Q-learning-style scores are evaluations based on historical price reactions and do not guarantee future performance. All trading decisions are made at your own risk and should be accompanied by proper risk management.
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。