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.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
🔵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.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
🔵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.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.