OPEN-SOURCE SCRIPT

Ornstein Uhlenbeck Reverter [forexobroker]

589
Ornstein-Uhlenbeck Reverter fits the continuous-time mean-reverting OU process dX = theta * (mu - X) * dt + sigma * dW to recent closes. Parameters theta (mean-reversion speed) and mu (long-run mean) are estimated by OLS. Half-life of reversion = ln(2) / theta. Signals fade overshoots beyond k * sigma — a statistically grounded mean-reversion entry.

🔶 ALGORITHM

1. Linear regression: r[t] = a + b * close[t-1] + e, where r = close[t-1] - close[t] (the negative one-step return).
2. theta_hat = -b (assuming dt = 1); mu_hat = a / theta_hat.
3. Half-life = ln(2) / theta. Sigma = stdev of OLS residuals.
4. Overshoot = (close - mu) / sigma.
5. Long fade: overshoot was below -k AND now turning back up. Short fade: above +k AND turning down.

🔶 SIGNAL LOGIC

- Buy: long fade trigger AND not already long AND cooldown elapsed AND barstate.isconfirmed.
- Sell: short fade trigger.
- Position-lock state machine.

🔶 INPUTS

- Fit Window (default 60)
- Overshoot k x sigma (default 1.5)
- Cooldown Bars (default 4)
- Visual: dashboard, glow, equilibrium hline, buy / sell colors

🔶 ALERTS

OUR Buy, OUR Sell, OUR Any Signal, OUR Underext, OUR Overext, OUR Extreme, OUR Fast Revert, OUR Drift Mode, OUR Webhook JSON.

🔶 LIMITATIONS

- OU assumes constant mu over the fit window; trending markets violate this and produce theta near zero (drift mode).
- OLS is sensitive to outliers; robust alternatives (MAD-based) may help on spike-heavy assets.
- The fit re-runs every bar; transitional periods produce unstable mu estimates.
- Mean-reversion strategies underperform during persistent trends; pair with a regime gate (e.g., Hurst < 0.5).

Pernyataan Penyangkalan

Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.