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).
Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que cualquier republicación del código está sujeta a nuestras Normas internas.
🔵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.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.
Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que cualquier republicación del código está sujeta a nuestras Normas internas.
🔵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.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.