OPEN-SOURCE SCRIPT
Ornstein Uhlenbeck Reverter [forexobroker]

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).
🔶 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).
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
🔵Gain access to our powerful tools : kestutisbalciunas.com/tradingview/
🔵Join our free telegram for updates : t.me/algotradingedge
All scripts & content provided by Forexobroker are for informational & educational purposes only.
🔵Join our free telegram for updates : t.me/algotradingedge
All scripts & content provided by Forexobroker are for informational & educational purposes only.
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
🔵Gain access to our powerful tools : kestutisbalciunas.com/tradingview/
🔵Join our free telegram for updates : t.me/algotradingedge
All scripts & content provided by Forexobroker are for informational & educational purposes only.
🔵Join our free telegram for updates : t.me/algotradingedge
All scripts & content provided by Forexobroker are for informational & educational purposes only.
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.