OPEN-SOURCE SCRIPT

Extended SOPR Indicator — SSOPR Tops (A/B toggle)

67
Extended SOPR Indicator — SSOPR Tops and Lows (A/B toggle)
Observation-only. Data: Glassnode SOPR.

Overview
This indicator extends the classical SOPR (Spent Output Profit Ratio) to improve readability and reduce noise on charts. SOPR measures whether coins moved on-chain were spent at a profit or at a loss. In brief: SOPR > 1 → spending at profit; SOPR < 1 → spending at loss. SSOPR (from "Smoothed SOPR") applies optional log transform (centers baseline at 0), smoothing (standard or adaptive), and adds structured signals: Z‑score lows (capitulation), buy zones, and top detection after prolonged elevation.


Why extend SOPR? (SSOPR vs classical SOPR)
Noise reduction: Raw daily SOPR can whipsaw around its baseline. SSOPR uses smoothing and (optionally) adaptive smoothing so regimes are visible without overfitting.
Better readability: The log transform shifts the break-even line to 0, making “profit territory” (above 0) and “loss territory” (below 0) visually intuitive on oscillators.
Actionable context: Z‑score highlights extreme lows (capitulation risk), a simple buy-zone threshold marks potential accumulation, and a structured top pattern (with a time factor) helps frame distribution phases after sustained elevation.

What the script plots
Smoothed SOPR (SSOPR): An orange line representing the smoothed SOPR (with optional log transform and optional adaptive smoothing).
Top markers: A red triangle appears once at the onset of a confirmed top pattern.
Background shading:
– Soft green: Buy zone when SSOPR falls below the “Buy Threshold.” (+ Z‑score capitulation zones (extreme lows)).
– Soft red: Top‑zone shading when the top criteria are met but before the single triangle fires.

Inputs & parameters
Smoothing Length (default 14): Base window for smoothing SSOPR. Higher values = smoother, slower response.
Apply Log Transform (default ON): Uses log(SOPR) so the baseline is 0 (log(1)=0). Above 0 → net profit regime; below 0 → net loss regime.
Adaptive Smoothing (default OFF): Expands smoothing length as volatility rises using a standard deviation proxy; reduces whipsaws while preserving structure.
Z‑score Threshold for Lows (default −2.5): Highlights capitulation zones when SSOPR deviates far below its rolling mean.
SSOPR Buy Threshold (default −0.02): Simple rule-of-thumb level for potential accumulation context when below (log scale).
SSOPR Top Threshold (default +0.005): Minimum elevation required for “profit territory” when assessing tops (log scale).
Min Bars Above Threshold Before Top (default 50): Ensures prolonged elevation before calling a top.
Lookback for Peak Detection (default 50): Window used to locate the recent high.
Drop % from Peak to Confirm Top (default 5%): Confirms the start of distribution from a local high.
Highlight Background: Toggles shaded zones.

Top detection (indicator-only)
A top fires when ALL of the following are true:

  1. SSOPR spent at leastMin Bars Above Threshold above the Top Threshold (sustained elevation).
  2. The rising phase test passes (Option A or B; see below).
  3. A drop from the local peak exceeds Drop % within the Lookback window.
  4. The peak occurred in profit territory (SSOPR > Top Threshold).
  5. To avoid repeated signals during the decline, the script emits the triangle once, at onset.


Rising‑phase switch: Option A vs Option B
Option A — Up‑step ratio: Over the last A: Bars for Rising Check (default 50), it requires that at least A: Required Up‑Step Ratio (default 60%) of bars were rising (each bar compared to the previous). This favors gradual, persistent advances and filters out “choppy” lifts.
Option B — Net slope: Compares current SSOPR to its value B: Bars Back for Net Slope ago (default 50). If higher, the series is considered rising. This is simpler and reacts faster in volatile phases but can admit brief pseudo‑trends.

Guidance: Prefer A for conservative confirmation in slow, persistent cycles; use B when trend moves are strong and you need timely detection.

Interpretation guide
Regimes (log view): Above 0 → spending at profit; below 0 → spending at loss.
Capitulation lows: When Z‑score < threshold, conditions often reflect forced/liquidity‑driven spending. Treat as context, not signals.
Buy zone: SSOPR < Buy Threshold flags potential accumulation conditions (combine with price structure).
Tops: After prolonged elevation, a confirmed top often coincides with profit‑taking/distribution phases.

Recommended timeframes
Daily: Code optimized for daily timeframe.

Method summary
• SSOPR source: GLASSNODE:BTC_SOPR (via request.security).
• Optional log transform: sopr → log(sopr) to normalize around 0.
• Smoothing: SMA over Smoothing Length, optionally adaptive using local volatility (std dev).
• Z‑score: (SSOPR − mean) / std dev, highlighting extreme lows.
• Top: Requires long elevation above Top Threshold, rising‑phase (A/B), and a subsequent drop > Drop % from recent high.

Limitations & notes
• SOPR reflects on‑chain movements; some activity occurs off‑chain (exchanges, internal transfers). Not all moves imply sale; aggregation makes it a usable proxy for profit/loss realization.
• Higher smoothing reduces noise but delays signals; adaptive smoothing can help but is still a trade‑off.
• Treat thresholds as context markers. They are not entry/exit signals by themselves.
• Use with price structure, volume, and other on‑chain indicators (e.g., realized price bands, dormancy/CDD) for confluence.

How to use (examples)
Advance holding above 0 (log view): Retests of 0 from above that hold—while SSOPR remains elevated—often mark absorption; look for Top conditions only after sustained elevation and a confirmed drop from peak.
Downtrend below 0: Rejections near 0 can align with continued loss realization; extreme Z‑score lows suggest capitulation risk—context for accumulation, not a blind buy.

Recommended settings
Weekly: Log ON, Smoothing Length 14–30, Adaptive ON, Buy Threshold −0.02, Top Threshold +0.005, Rising Method A, Min Bars 50.
Daily: Log ON, Smoothing Length 14–20, Adaptive OFF or ON (depending on noise), Rising Method B for timely slope checks.

Credits & references
• SOPR metric: Renato Shirakashi; documentation: Glassnode, CryptoQuant, overview: Bitbo.

Disclaimer
This script is for research/education on market behavior. It is not financial advice. Indicators provide context; decisions remain your responsibility.

Tags
bitcoin, btc, on‑chain, sopr, ssopr, glassnode, oscillator, regime, distribution, capitulation

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.