OPEN-SOURCE SCRIPT

Brownian Motion Residual [JOAT]

385
BROWNIAN MOTION RESIDUAL [JOAT]

A regime classifier rooted in the sqrt(T) scaling law of geometric Brownian motion. Under a true random walk, the standard deviation of T-bar returns scales as σ₁ · √T — that is the central fact of Brownian motion in continuous time. Markets violate this scaling in revealing ways: when they trend, dispersion at long horizons grows faster than √T; when they mean-revert, it grows slower. Brownian Motion Residual measures that violation across three horizons simultaneously, aggregates it, and surfaces a single Z-like residual that classifies the market into Strong MR / MR / Random / Trend / Strong Trend.

스냅샷

The sqrt(T) scaling law, restated

For a Brownian process with per-bar volatility σ₁:

σ(T-bar return) = σ₁ · √T

For a real market the observed σ at horizon T can be measured directly. The residual is the deviation of the observed value from the Brownian-implied value:

residual(T) = σ_observed(T) − σ₁ · √T

When the residual is positive, dispersion at T is greater than Brownian predicts — the market is trending (price travels further than a random walk in T bars). When it is negative, dispersion is less than Brownian predicts — the market is mean-reverting (price ends up closer to home than a random walk would).

Optional normalisation by σ₁ · √T turns the residual into a unit-less percentage of expected dispersion, so the same threshold values are meaningful across instruments and timeframes.

Three horizons, weighted blend

A single horizon is noisy. Brownian Motion Residual reads three horizons simultaneously (default 5 / 20 / 100 bars), each independently toggleable and weighted (default 1.0 each). The horizons are aggregated into a single residual line — the script's headline metric. Toggling off the short horizon makes the read smoother and slower; toggling off the long horizon makes it more reactive. Configurable.

A configurable EMA on top of the aggregated residual suppresses single-bar noise without lagging the regime view.

Two-tier classification

The aggregated residual is mapped to one of five regimes by two symmetric thresholds (default ±1 mild, ±2 strong):

  • Strong Trend — residual > +2. Aggressive momentum regime.
  • Trend — residual between +1 and +2. Trending.
  • Random — residual between −1 and +1. Brownian-like.
  • MR — residual between −2 and −1. Mean-reverting.
  • Strong MR — residual < −2. Aggressive reversion regime.


Visual system

  • Slope-coloured residual line with configurable width and optional area fill under it (transparency configurable).
  • Zero line and ±1 / ±2 threshold lines (toggleable).
  • Background tint by regime (subtle 88 transparency default) — teal trend, lavender MR, mint random.
  • Per-horizon plots (toggleable, off by default) — each horizon's residual as a faint dotted overlay; useful for seeing which horizon is driving the read.
  • Regime-change dots above the line at every confirmed flip.


A locked Aurora palette (teal trend / lavender MR / mint random on a deep-night ground) gives the pane a distinctive structural identity.

Dashboard

Monospaced table, positionable to any of nine corners, with vertical row-fade. Surfaces:

  • Aggregated residual (raw and smoothed).
  • Regime classification with glyph.
  • σ₁ value (the Brownian anchor).
  • Per-horizon residuals (h1 / h2 / h3) when enabled.
  • Bars in current regime.
  • Distance to nearest threshold.


Optional fancy Unicode header for the institutional aesthetic.

스냅샷

Alerts

Three alert conditions, each independently controllable:

  • Regime Change (any classification flip)
  • Strong threshold cross (±2)
  • Mild threshold cross (±1) — off by default


How to read it

Three reads, in order of conviction:

  1. Strong Trend / Strong MR entry — the highest-conviction read. The market has decisively departed from Brownian scaling in one direction. Pair with a momentum tool in Trend regimes, a reversion tool in MR regimes.
  2. Residual crossing zero — the regime fault line. Even before crossing a threshold, a sustained sign flip means the underlying distribution has rotated; the next threshold cross will confirm the new regime.
  3. Per-horizon disagreement (when enabled) — when the short horizon is in trend regime but the long horizon is in MR regime, the market is in a nested state: short-term momentum inside a longer reversion. This is the textbook setup for fade-the-extreme intraday plays inside a wider range.


Suggested settings

Defaults (σ₁ window 100, observed σ window 60, horizons 5/20/100, equal weights, log returns ON, normalisation ON) are tuned for 15m–4H on liquid markets. For lower timeframes drop horizon 3 to 50. For HTF (daily+) raise horizon 3 to 200 and σ₁ window to 200. Log returns are theoretically correct and the recommended default — the script's regime classification depends on the scaling law, which assumes log returns; switch off only for research.

Originality

The √T Brownian scaling law is textbook continuous-time finance — the central piece of Bachelier's 1900 thesis and the foundation of every diffusion model in pricing. The implementation here — the per-horizon σ measurement pipeline, the σ₁-anchored Brownian baseline with optional normalisation, the three-horizon weighted aggregation, the EMA-smoothed residual classifier with two-tier thresholds, the per-horizon overlay layer, the regime-tinted background, and the dashboard — is JOAT-original. No third-party code reused. The use of residual against Brownian as a regime classifier is the original quantitative contribution.

Limitations

The √T law is exact only for Brownian motion — real markets have fat tails, autocorrelation, and discrete bars, so the measured "residual" is always non-zero even in a regime that looks random. The thresholds (±1 / ±2) are calibrated to be the regime boundaries empirically; tighten or loosen if your instrument has unusual variance behaviour. Per-horizon σ values need their respective windows populated to be meaningful — early bars give a warm-up read.




-made with passion by jackofalltrades

면책사항

해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.