OPEN-SOURCE SCRIPT

AetherEdge - Portfolio Regime Hedge Optimizer

474
🖊️ Overview

A multi-asset engine for the portfolio era. Rather than reading one symbol in isolation, it pulls in up to two correlated assets (e.g. ETH and DXY alongside BTC, or a stock and an FX pair) and learns their relative regime with a NeuraLib network — relative strength, rolling correlation, and the correlation regime itself (risk-on coupling vs. decoupling). From that, the agent issues hedge signals — when the main asset's downside is best offset by a correlated instrument — and diversification guidance when correlations decouple. A reward based on whether a hedge call actually reduced realized drawdown lets the regime model self-evolve. Visualization: "Hedge Alert" arrows on the main asset plus up to two relative-strength comparison lines.

🔶 Key Features

Multi-asset relative-regime learning — AI learns the main + two correlated assets' relationship (beyond single-symbol analysis)
Correlation-regime classification — labels coupling (COUPLED) / decoupling (DECOUPLED) / inverse (INVERSE) from rolling correlation
Hedge signals — recommends hedging with a correlated asset when correlation rises amid downside pressure
Diversification guidance — flags when low correlation makes spreading exposure favorable
Self-evolving reward — learns from post-hedge drawdown reduction (accounting for hedging cost)
Hedge Alert arrows — warning arrows and labels on the main asset chart
Relative-strength lines — each correlated asset's main-relative performance, rebased onto price, up to two lines
Intelligence panel — hedge conviction, hedge/diversify/hold regime values, each correlation, relative strength, and main drawdown at a glance

🧠 Technical Architecture

The engine pulls in two correlated assets via request.security on the same timeframe as the main chart. The state vector comprises six relative-regime features: (1)(2) main-vs-each-asset rolling correlation, (3)(4) main-vs-each relative strength (relative performance gap), (5) the main asset's drawdown pressure from its recent high, and (6) the main asset's volatility regime — all clamp-normalized.
This feeds a NeuraLib regime network (state(6) → hidden(tanh) → Q[3]) estimating the value of three actions — HEDGE / DIVERSIFY / HOLD. The reward design is the core: HEDGE is rewarded when the main subsequently fell (protection was valuable) and lightly penalized (cost) when it rose; DIVERSIFY is rewarded when correlation is low and the alt outperformed; HOLD is rewarded when the main held up (avoiding needless hedge cost). The model thus learns when to hedge from a drawdown-reduction standpoint. Training is DQN-style (target = r + γ·max Q(s′)) from uniform replay.
Hedge conviction is the normalized dominance of the HEDGE value over the others; after smoothing, when it clears the gate amid main downside pressure, a "Hedge Alert" fires. The relative-strength lines rebase each correlated asset's main-relative performance onto the main close, overlaying them on the price chart for a visual strength comparison.

⚙️ Recommended Settings & Tuning Guide

BTC (main) + ETH + DXY (1H–4H): Correlation 40, Relative 30, High-Corr 0.6, Decoupling 0.2, Hedge Gate 0.45 — a crypto + risk-off-proxy setup
ETH (main) + BTC + Total (1H–4H): BTC as asset 1, the broad crypto market as asset 2
Stock (main) + Index + VIX/DXY: index and a volatility proxy as correlated assets for single-stock hedging
FX (main) + DXY + related pair: for currency relative-regime and hedging
Correlation Window: longer is a steadier correlation regime; shorter is nimbler — ~40 is practical
High-Correlation / Decoupling Level: the coupling/decoupling thresholds — set to the pair's typical correlation
Hedge Gate: higher makes hedge alerts rare and high-confidence; lower more frequent — tune to risk tolerance
Choice of correlated assets: pick economically meaningful pairs (same sector, risk-on/off relationship)

💡 How to Use in Practice

Reacting to Hedge Alert arrows: an arrow marks where the model judges the main's downside can be offset by a correlated asset — a basis to consider hedging (shorting the correlate, options, trimming size)
Reading relative-strength lines: versus the main close (anchor), a correlate line above = that asset outperforms the main (main weaker); below = main leads — useful for rotation calls
Using the correlation regime: COUPLED = risk resonates and hedging is effective; DECOUPLED = diversification works; INVERSE = a natural hedge exists
Using diversification flags: DIVERSIFY markers mark decoupled conditions where spreading risk across the assets may lower portfolio volatility
Pairing with drawdown pressure: deep main drawdown plus high hedge conviction is the most caution-worthy risk-off setup
Multi-timeframe usage: read the big-picture correlation regime on the higher timeframe (4H), then time on Hedge Alerts on the lower one (1H)

⚠️ Important Notes

Correlated assets must be set: this requires proper correlated-asset symbols; unrelated assets break correlation learning — choose economically related ones
request.security constraints: correlated data is fetched on the same timeframe; illiquid symbols or timeframe mismatches can make correlation inaccurate
Initial learning period: right after launch the buffer is nearly empty and the regime model is immature; treat hedge conviction as low-confidence until it learns (several hundred bars)
Learning resets: changing parameters, symbol/timeframe, correlated assets, or recompiling reinitializes the network weights and buffer
Hedging isn't infallible: correlations shift over time, and in crises normally-uncorrelated assets can move together (correlation convergence) — hedge recommendations do not guarantee protection
On forward-looking reward: rewards use closed-bar forward returns (a standard RL training construct); as with any adaptive system, historical and live behavior can differ — always forward-test
Constraints: this is a lightweight implementation within Pine's compute budget

🚨 Disclaimer

This indicator is an analytical and educational visualization tool. The relative-regime learning, correlation analysis, hedge signals, diversification guidance, and relative-strength lines are quantitative heuristics computed on-chart from price data — they are not financial advice, trade/hedge signals, or any guarantee of future performance. Make portfolio hedging and diversification decisions on your own responsibility, including consulting a professional. Always combine any tool with your own analysis and disciplined risk management.

Aviso legal

As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.