OPEN-SOURCE SCRIPT
AetherEdge - Self-Attention Focus

🖊️ Overview
AE-FOCUS uses the Transformer self-attention mechanism to compute "which past moments does NOW most resemble" and forecasts from the outcomes of those analogous states. Each bar is a feature vector; the current query is dotted against past keys, softmax-normalized into attention weights, and the "what happened after" of high-attention past bars is weight-averaged into a forecast. Glowing arcs sweep from NOW back to resonating past bars, brighter where attention is stronger — a visualization unprecedented in Pine.
🔶 Key Features
Self-attention mechanism: genuine query-key-value-softmax structure
4-D feature vector: standardized return, momentum, RSI-deviation, volatility-ratio
Attention-weighted forecast: weight-averages outcomes of analogous past states
Resonance arc rendering: curves from NOW to high-attention bars visualize resonance
Arc brightness/width scales with attention strength
Online forecast hit-rate tracking
Confidence from attention concentration (entropy-based)
Forecast-direction background + BUY/SELL markers
HUD showing resonance target and concentration
Per-event alerts
🧠 Technical Architecture
This implements the self-attention mechanism. Each bar's feature vector is standardized 4-D [return, momentum, RSI-deviation, volatility-ratio]. With query = current features and key_s = past bar s features, the attention score score(s) = (q · k_s)/√d is computed and normalized α(s) = softmax_s(score/τ) (τ = temperature). value(s) = the realized return in the h bars after bar s (known since s is far enough in the past). forecast = Σ α(s)·value(s) weight-averages the outcomes of analogous states into a predicted return. This is effectively attention-kernel regression over past states similar to the current one. The forecast's hit-rate is tracked online, combined with attention concentration (entropy) and forecast magnitude into confidence. Signals fire when the smoothed forecast crosses threshold.
⚙️ Recommended Settings & Tuning Guide
Attention Lookback (N) 60 is a starting point — the past bars the current query attends over. Outcome Horizon (h) 5 is the value horizon (outcome in the h bars after each past bar) and the forecast horizon. Softmax Temperature (τ) 1.0 is attention sharpness — lower focuses hard on the single closest analog (sharp), higher is more averaged (soft). Feature Normalization Window 100 is the standardization window. Forecast Threshold 0.15 is the firing threshold (normalized return). Arc Threshold 2.5 is how many times the average attention a bar must exceed to get an arc; Arc Height 2.0 is the arc height.
💡 How to Use in Practice
Apply to chart and glowing arcs sweep from NOW to high-attention past bars. The past moments where arcs cluster are those most "resonating" with now. Green arcs mean analogous states rose afterward (bullish forecast); red means they fell (bearish). The HUD's "resonates with" shows how many bars ago resonates most, and "concentration" shows attention concentration (whether a clear analog exists). When concentration is high and forecast hit-rate is high, signal reliability rises. Lowering τ reacts sharply to the single closest analog; raising it gives a smooth forecast averaged over many states.
⚠️ Important Notes
This is single-head attention with fixed (identity/statistical) projections — learned W_Q/W_K/W_V weights and multi-head are outside Pine's limits. It is effectively attention-kernel regression over analogous states, but the query-key-value-softmax structure is the genuine attention mechanism. The forecast is a probabilistic decision based on outcomes of analogous past states, not a certain prediction (past analogies are not guaranteed to repeat). Attention arcs show only the latest bar's resonance and update in real time. All signals are probabilistic decisions based on historical data and do not guarantee future profits.
🚨 Disclaimer
This indicator is provided for educational and informational purposes only and does not constitute financial or investment advice. No signal guarantees future profit, and past performance does not indicate future results. All trading decisions are made at your own risk.
AE-FOCUS uses the Transformer self-attention mechanism to compute "which past moments does NOW most resemble" and forecasts from the outcomes of those analogous states. Each bar is a feature vector; the current query is dotted against past keys, softmax-normalized into attention weights, and the "what happened after" of high-attention past bars is weight-averaged into a forecast. Glowing arcs sweep from NOW back to resonating past bars, brighter where attention is stronger — a visualization unprecedented in Pine.
🔶 Key Features
Self-attention mechanism: genuine query-key-value-softmax structure
4-D feature vector: standardized return, momentum, RSI-deviation, volatility-ratio
Attention-weighted forecast: weight-averages outcomes of analogous past states
Resonance arc rendering: curves from NOW to high-attention bars visualize resonance
Arc brightness/width scales with attention strength
Online forecast hit-rate tracking
Confidence from attention concentration (entropy-based)
Forecast-direction background + BUY/SELL markers
HUD showing resonance target and concentration
Per-event alerts
🧠 Technical Architecture
This implements the self-attention mechanism. Each bar's feature vector is standardized 4-D [return, momentum, RSI-deviation, volatility-ratio]. With query = current features and key_s = past bar s features, the attention score score(s) = (q · k_s)/√d is computed and normalized α(s) = softmax_s(score/τ) (τ = temperature). value(s) = the realized return in the h bars after bar s (known since s is far enough in the past). forecast = Σ α(s)·value(s) weight-averages the outcomes of analogous states into a predicted return. This is effectively attention-kernel regression over past states similar to the current one. The forecast's hit-rate is tracked online, combined with attention concentration (entropy) and forecast magnitude into confidence. Signals fire when the smoothed forecast crosses threshold.
⚙️ Recommended Settings & Tuning Guide
Attention Lookback (N) 60 is a starting point — the past bars the current query attends over. Outcome Horizon (h) 5 is the value horizon (outcome in the h bars after each past bar) and the forecast horizon. Softmax Temperature (τ) 1.0 is attention sharpness — lower focuses hard on the single closest analog (sharp), higher is more averaged (soft). Feature Normalization Window 100 is the standardization window. Forecast Threshold 0.15 is the firing threshold (normalized return). Arc Threshold 2.5 is how many times the average attention a bar must exceed to get an arc; Arc Height 2.0 is the arc height.
💡 How to Use in Practice
Apply to chart and glowing arcs sweep from NOW to high-attention past bars. The past moments where arcs cluster are those most "resonating" with now. Green arcs mean analogous states rose afterward (bullish forecast); red means they fell (bearish). The HUD's "resonates with" shows how many bars ago resonates most, and "concentration" shows attention concentration (whether a clear analog exists). When concentration is high and forecast hit-rate is high, signal reliability rises. Lowering τ reacts sharply to the single closest analog; raising it gives a smooth forecast averaged over many states.
⚠️ Important Notes
This is single-head attention with fixed (identity/statistical) projections — learned W_Q/W_K/W_V weights and multi-head are outside Pine's limits. It is effectively attention-kernel regression over analogous states, but the query-key-value-softmax structure is the genuine attention mechanism. The forecast is a probabilistic decision based on outcomes of analogous past states, not a certain prediction (past analogies are not guaranteed to repeat). Attention arcs show only the latest bar's resonance and update in real time. All signals are probabilistic decisions based on historical data and do not guarantee future profits.
🚨 Disclaimer
This indicator is provided for educational and informational purposes only and does not constitute financial or investment advice. No signal guarantees future profit, and past performance does not indicate future results. All trading decisions are made at your own risk.
開源腳本
秉持TradingView一貫精神,這個腳本的創作者將其設為開源,以便交易者檢視並驗證其功能。向作者致敬!您可以免費使用此腳本,但請注意,重新發佈代碼需遵守我們的社群規範。
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。
開源腳本
秉持TradingView一貫精神,這個腳本的創作者將其設為開源,以便交易者檢視並驗證其功能。向作者致敬!您可以免費使用此腳本,但請注意,重新發佈代碼需遵守我們的社群規範。
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。