OPEN-SOURCE SCRIPT
Roll Spread Estimator [forexobroker]

Roll Spread Estimator implements Roll (1984) — the bid-ask bounce induces negative serial covariance in observed returns. Spread = 2 * sqrt(-cov(r[t], r[t-1])) when cov is negative. Tight spread = liquid market = clean breakouts; wide spread = thin = breakouts to fade. Signals fire on EMA cross during a tight regime. Stacked-flag visual signature distinct from any other hero indicator.
🔶 ALGORITHM
1. r0 = close - close[1]; r1 = close[1] - close[2].
2. cov(r0, r1) = sma(r0 * r1, N) - sma(r0, N) * sma(r1, N).
3. Spread = 2 * sqrt(-cov) when cov < 0; otherwise 0.
4. Quantile q (e.g., 70th percentile) over rolling window.
5. Tight regime when spread <= q.
6. EMA cross within tight fires entries.
🔶 SIGNAL LOGIC
- Buy: tight AND close crosses EMA up AND not already long AND cooldown elapsed AND barstate.isconfirmed.
- Sell: tight AND close crosses EMA down.
- Position-lock state machine.
🔶 INPUTS
- Cov Window (default 40)
- Tight Spread Quantile (default 0.7)
- Pullback EMA Length (default 8)
- Cooldown Bars (default 4)
- Visual: dashboard, glow (3 stacked flags), spread channel, buy / sell colors
🔶 ALERTS
RSE Buy, RSE Sell, RSE Any Signal, RSE Tight Start, RSE Tight End, RSE Bounce, RSE EMA Up, RSE EMA Down, RSE Webhook JSON.
🔶 LIMITATIONS
- Roll's estimator assumes the bid-ask bounce is the dominant source of negative covariance; trend-following autocorrelation can produce positive cov, in which case the estimator is undefined and returns 0.
- Forex and equities show clear bid-ask bounces; pure spot-market crypto is less consistent.
- The stacked-flag visual uses 3 overlapping flags for a thicker appearance — visually distinct but slightly heavier draw.
- Quantile-based threshold means tight is *relative* to recent history, not absolute.
🔶 ALGORITHM
1. r0 = close - close[1]; r1 = close[1] - close[2].
2. cov(r0, r1) = sma(r0 * r1, N) - sma(r0, N) * sma(r1, N).
3. Spread = 2 * sqrt(-cov) when cov < 0; otherwise 0.
4. Quantile q (e.g., 70th percentile) over rolling window.
5. Tight regime when spread <= q.
6. EMA cross within tight fires entries.
🔶 SIGNAL LOGIC
- Buy: tight AND close crosses EMA up AND not already long AND cooldown elapsed AND barstate.isconfirmed.
- Sell: tight AND close crosses EMA down.
- Position-lock state machine.
🔶 INPUTS
- Cov Window (default 40)
- Tight Spread Quantile (default 0.7)
- Pullback EMA Length (default 8)
- Cooldown Bars (default 4)
- Visual: dashboard, glow (3 stacked flags), spread channel, buy / sell colors
🔶 ALERTS
RSE Buy, RSE Sell, RSE Any Signal, RSE Tight Start, RSE Tight End, RSE Bounce, RSE EMA Up, RSE EMA Down, RSE Webhook JSON.
🔶 LIMITATIONS
- Roll's estimator assumes the bid-ask bounce is the dominant source of negative covariance; trend-following autocorrelation can produce positive cov, in which case the estimator is undefined and returns 0.
- Forex and equities show clear bid-ask bounces; pure spot-market crypto is less consistent.
- The stacked-flag visual uses 3 overlapping flags for a thicker appearance — visually distinct but slightly heavier draw.
- Quantile-based threshold means tight is *relative* to recent history, not absolute.
Skrypt open-source
W zgodzie z duchem TradingView twórca tego skryptu udostępnił go jako open-source, aby użytkownicy mogli przejrzeć i zweryfikować jego działanie. Ukłony dla autora. Korzystanie jest bezpłatne, jednak ponowna publikacja kodu podlega naszym Zasadom serwisu.
🔵Gain access to our powerful tools : forexobroker.com/tv
🔵Join our free telegram for updates : t.me/dominicwalsfxhtrader
All scripts & content provided by Forexobroker are for informational & educational purposes only.
🔵Join our free telegram for updates : t.me/dominicwalsfxhtrader
All scripts & content provided by Forexobroker are for informational & educational purposes only.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.
Skrypt open-source
W zgodzie z duchem TradingView twórca tego skryptu udostępnił go jako open-source, aby użytkownicy mogli przejrzeć i zweryfikować jego działanie. Ukłony dla autora. Korzystanie jest bezpłatne, jednak ponowna publikacja kodu podlega naszym Zasadom serwisu.
🔵Gain access to our powerful tools : forexobroker.com/tv
🔵Join our free telegram for updates : t.me/dominicwalsfxhtrader
All scripts & content provided by Forexobroker are for informational & educational purposes only.
🔵Join our free telegram for updates : t.me/dominicwalsfxhtrader
All scripts & content provided by Forexobroker are for informational & educational purposes only.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.