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 aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
🔵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.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
🔵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.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.