OPEN-SOURCE SCRIPT
Corwin-Schultz Spread Bands [forexobroker]

Corwin-Schultz Spread Bands [forexobroker] estimates the effective bid-ask spread directly from daily high-low data using the Corwin-Schultz (2012) two-bar estimator, then turns the rolling spread into a stress regime and a pair of price bands. The unique angle is using a peer-reviewed microstructure spread formula intended for daily data on any timeframe to flag liquidity stress on the chart and time entries when stress fades into a directional trend.
🔶 ALGORITHM
1. For each pair of adjacent bars compute beta = (ln(H_t / L_t))^2 + (ln(H_{t-1} / L_{t-1}))^2 and gamma = (ln(max(H_t, H_{t-1}) / min(L_t, L_{t-1})))^2.
2. Compute alpha = (sqrt(2 x beta) - sqrt(beta)) / (3 - 2 x sqrt(2)) - sqrt(gamma / (3 - 2 x sqrt(2))).
3. Raw spread = 2 x (exp(alpha) - 1) / (1 + exp(alpha)). Clamp to the [0, 1] range.
4. Smooth with EMA (default 5) to produce a stable percentage spread.
5. Rolling regime stats: 100-bar (default) median and stdev of the smoothed spread; threshold = median + k x stdev (default k = 1.0).
6. In-stress = smoothed spread above threshold. Exiting stress = was above on the prior bar and below now.
7. Trend filter: close versus 20-SMA (default).
8. Visual bands: close +/- (spread / 2) x close x mult.
🔶 SIGNAL LOGIC
- Buy: spread regime just exited stress AND close > trend SMA AND session filter passes AND posState was not long AND cooldown elapsed AND barstate.isconfirmed.
- Sell: spread regime just exited stress AND close < trend SMA AND session filter passes AND posState was not short AND cooldown elapsed AND barstate.isconfirmed.
A flip-prevention posState plus cooldown bars (default 15) avoid stacking signals inside a single regime transition.
🔶 INPUTS
- Spread Estimator: smoothing EMA default 5, regime lookback default 100, stdev multiplier default 1.0.
- Signal Logic: trend SMA length default 20, cooldown bars default 15.
- Filters: optional session window default 0000-2400.
- Visual: spread band multiplier default 1.0, glow, fill, bands, stress bgcolor, neon palette, dashboard.
🔶 ALERTS
CSS Buy, CSS Sell, CSS Any Signal, CSS Enter Stress, CSS Exit Stress, CSS Spread Rising, CSS Spread Falling, CSS Trend Up, CSS Trend Down, CSS Extreme Spread, CSS Webhook JSON.
🔶 LIMITATIONS
- The estimator was designed for daily bars; on very low timeframes the high-low range gets dominated by tick noise and the spread value is noisier than the daily case.
- Spread is computed in price-fraction terms; reporting in basis points assumes that interpretation is meaningful for the instrument.
- The regime threshold depends on a 100-bar lookback, so on fresh history the threshold is unstable until the buffer is full.
- Signals require the regime to flip, so during long sideways regimes with no stress event the indicator can sit idle for many bars.
- The 20-SMA trend filter is intentionally simple and will misclassify direction during tight ranges.
🔶 ALGORITHM
1. For each pair of adjacent bars compute beta = (ln(H_t / L_t))^2 + (ln(H_{t-1} / L_{t-1}))^2 and gamma = (ln(max(H_t, H_{t-1}) / min(L_t, L_{t-1})))^2.
2. Compute alpha = (sqrt(2 x beta) - sqrt(beta)) / (3 - 2 x sqrt(2)) - sqrt(gamma / (3 - 2 x sqrt(2))).
3. Raw spread = 2 x (exp(alpha) - 1) / (1 + exp(alpha)). Clamp to the [0, 1] range.
4. Smooth with EMA (default 5) to produce a stable percentage spread.
5. Rolling regime stats: 100-bar (default) median and stdev of the smoothed spread; threshold = median + k x stdev (default k = 1.0).
6. In-stress = smoothed spread above threshold. Exiting stress = was above on the prior bar and below now.
7. Trend filter: close versus 20-SMA (default).
8. Visual bands: close +/- (spread / 2) x close x mult.
🔶 SIGNAL LOGIC
- Buy: spread regime just exited stress AND close > trend SMA AND session filter passes AND posState was not long AND cooldown elapsed AND barstate.isconfirmed.
- Sell: spread regime just exited stress AND close < trend SMA AND session filter passes AND posState was not short AND cooldown elapsed AND barstate.isconfirmed.
A flip-prevention posState plus cooldown bars (default 15) avoid stacking signals inside a single regime transition.
🔶 INPUTS
- Spread Estimator: smoothing EMA default 5, regime lookback default 100, stdev multiplier default 1.0.
- Signal Logic: trend SMA length default 20, cooldown bars default 15.
- Filters: optional session window default 0000-2400.
- Visual: spread band multiplier default 1.0, glow, fill, bands, stress bgcolor, neon palette, dashboard.
🔶 ALERTS
CSS Buy, CSS Sell, CSS Any Signal, CSS Enter Stress, CSS Exit Stress, CSS Spread Rising, CSS Spread Falling, CSS Trend Up, CSS Trend Down, CSS Extreme Spread, CSS Webhook JSON.
🔶 LIMITATIONS
- The estimator was designed for daily bars; on very low timeframes the high-low range gets dominated by tick noise and the spread value is noisier than the daily case.
- Spread is computed in price-fraction terms; reporting in basis points assumes that interpretation is meaningful for the instrument.
- The regime threshold depends on a 100-bar lookback, so on fresh history the threshold is unstable until the buffer is full.
- Signals require the regime to flip, so during long sideways regimes with no stress event the indicator can sit idle for many bars.
- The 20-SMA trend filter is intentionally simple and will misclassify direction during tight ranges.
開源腳本
秉持TradingView一貫精神,這個腳本的創作者將其設為開源,以便交易者檢視並驗證其功能。向作者致敬!您可以免費使用此腳本,但請注意,重新發佈代碼需遵守我們的社群規範。
🔵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.
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。
開源腳本
秉持TradingView一貫精神,這個腳本的創作者將其設為開源,以便交易者檢視並驗證其功能。向作者致敬!您可以免費使用此腳本,但請注意,重新發佈代碼需遵守我們的社群規範。
🔵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.
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。