OPEN-SOURCE SCRIPT

Market Stress Radar

174
Market Stress Radar

Which assets withstand a market selloff — and which recover first?

Market Stress Radar compares an asset with a selected benchmark during defined market stress episodes. It tracks their losses from a shared reference date, their recovery times, and whether initial relative strength turns into weakness.

READING THE CHART

• Green line: Asset return from its own pre-stress closing price.
• Blue line: Benchmark return from its own pre-stress closing price.
• Zero line: Each instrument’s respective reference price.
• Orange shading: Stress detection day.
• Green triangle: First asset recovery after detection.
• Orange triangle: Delayed relative weakness.
• Gray square: Observation window ended.

Both return lines use the same reference date. They appear during monitored episodes and remain blank between episodes.

HOW STRESS IS DETECTED

By default, the radar examines the benchmark’s three-day return.

A stress episode starts when the decline reaches the larger of:

• A minimum drop of 3%.
• 1.5 × pre-window ATR percentage × √3, using a 20-day ATR.

The volatility measurement comes from before the decline window. This is a scaling rule, not a statistical confidence level.

Detection requires a fresh transition into stress and a confirmed daily close. Only one episode is monitored at a time; additional triggers during that episode are ignored.

RECOVERY: FIRST TOUCH AND EPISODE COMPLETION

The reference prices are frozen at the closing prices immediately before the measured decline window.

D0 is the detection day. An instrument first recovers when it closes at or above its own frozen reference price. A value already above that price on D0 is recorded as D+0.

First recovery does not mean permanent recovery. An asset can recover and subsequently fall back below its reference.

The episode ends when:

• Both instruments close at or above their respective reference prices on the same day; or
• The observation limit is reached — 30 daily bars after detection by default.

Missing or misaligned data ends the episode separately. Elapsed days refer to daily chart bars, which are trading sessions for stocks.

ILLUSTRATIVE EXAMPLE

Suppose BTC falls 8% over the detection window while the chart coin falls 3%.

The coin initially leads BTC by 5 percentage points.

If the coin returns to its own reference price four daily bars after detection, its first recovery is recorded as D+4. If BTC remains below its reference, monitoring continues.

If either instrument never recovers within the observation window, that recovery remains NOT OBSERVED. A timeout is not counted as a successful recovery.

This is a hypothetical example, not a backtest result.

DELAYED RELATIVE WEAKNESS

An initially resilient asset can lose its advantage.

With the default settings, the radar issues one warning per episode when:

• The asset initially leads its benchmark by at least 0.5 percentage points; and
• Its lead later falls to −0.5 percentage points or below.

WEAKNESS OBSERVED records that this happened during the episode. It does not necessarily mean the asset is still underperforming; the latest returns and relative lead show the current relationship.

COMPACT DASHBOARD

The dashboard shows:

• Episode status.
• Asset and benchmark returns.
• First recovery day, or OPEN / NOT OBSERVED.
• Initial and latest relative lead.
• Detection date, elapsed daily bars and reference date.
• Counts of jointly recovered episodes, timeouts and data gaps.

After an episode ends, LAST EPISODE identifies the frozen final values. These are not current returns or trading win rates.

The dashboard can be placed in five positions.

SETUP

Use standard 1D candles.

Automatic benchmark selection:

• Crypto: BINANCE:BTCUSDT.
• USD stocks: AMEX:SPY.

A custom benchmark can also be selected. Use instruments with matching daily sessions and comparable quote currencies. No currency conversion is performed.

ALERTS

Six alert conditions are available:

• New market stress.
• First asset recovery.
• Late relative weakness.
• Both instruments recovered.
• Observation window ended.
• Data gap stopped the episode.

Configure alerts separately in TradingView.

METHOD AND LIMITATIONS

Calculations and event signals use confirmed daily closes. Markers are not backdated to the earlier reference date.

Results depend on the selected instruments, settings and available history. Historical data corrections can change results. Price returns account for splits but exclude dividend income.

Market Stress Radar is a descriptive analysis tool. It does not place trades, predict guaranteed recoveries or establish a profitable trading strategy.

Wyłączenie odpowiedzialności

Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.