OPEN-SOURCE SCRIPT
업데이트됨 Monte Carlo Simulation Bands

Monte Carlo Simulation v2.4.2
Plots a one-bar-ahead price distribution band built from many simulated paths. The green band shows empirical percentiles of simulated final prices—these are distribution bounds, not a confidence interval of the mean.
What It Does
Simulates many one-bar price paths using a directional random walk with volatility scaling (uniform shocks, not Gaussian GBM).
Plots Mean Forecast, Median Forecast, and configurable percentile bounds (default 5th/95th).
Optional rolling HTF-days mean line (yellow) for trend context.
Optional labels and forward projection lines.
Alerts when the confirmed close breaks above or below the percentile band.
Non-Repainting & HTF Behavior (Fail-Closed)
All calculations are gated to confirmed bars only via explicit no_repaint_ok gate (barstate.isconfirmed).
If you select an HTF Resolution, the script uses a strict request.security(..., lookahead_off, gaps_off) pipeline.
If HTF data is unavailable, outputs are na—no silent fallback to chart timeframe.
A separate "HTF Alignment (lagged)" plot shows the prior HTF close (htf_price[1]) as visual proof of no look-ahead.
Volatility Source & Scaling
If "Use Historical Volatility" is enabled, volatility is estimated from log returns on the selected resolution (HTF if set, otherwise chart).
Annualization adapts to session type:
Equities: 6.5 hours/day, 252 trading days/year
Crypto: 24 hours/day, 365 days/year
Substeps increase path smoothness within the same one-bar horizon—they do not extend the forecast to multiple bars.
Key Inputs
• Prob Up / Prob Down — Must satisfy Prob Up + Prob Down ≤ 1.0. If violated, simulation is skipped and table shows "✗ PROB>1".
• # Simulations / # Substeps — Higher = smoother/more stable, but slower. Default 100×100 is a good balance.
• Lower/Upper Percentile — Define the band width (e.g., 5 and 95 for a 90% distribution band).
• Run On Last Bar Only — Performance mode (recommended). Skips historical computation; updates on each new confirmed bar.
• Resolution (HTF) — Leave blank for chart timeframe, or set to Weekly/Monthly for HTF-aligned simulation.
• Crypto 24/7 Session? — Enable for crypto markets to use correct annualization (365d, 24h).
How to Use (Quickstart)
Start with defaults and keep Run On Last Bar Only = true for speed.
Set Prob Up and Prob Down so their sum ≤ 1.0 (e.g., 0.5 + 0.5 = 1.0 for neutral).
Enable "Use Historical Volatility" and set a Volatility Lookback (e.g., 20 bars) for data-driven vol.
Set Resolution (HTF) if you want the model to run on higher timeframe data (e.g., 1W). Expect updates only when a new HTF interval starts.
Choose percentiles (e.g., 5 and 95) to define your distribution band width.
Enable alerts for "Price Above Upper Percentile" or "Price Below Lower Percentile" to get notified of breakouts.
Limitations & Disclosures
Plots a one-bar-ahead price distribution band built from many simulated paths. The green band shows empirical percentiles of simulated final prices—these are distribution bounds, not a confidence interval of the mean.
What It Does
Simulates many one-bar price paths using a directional random walk with volatility scaling (uniform shocks, not Gaussian GBM).
Plots Mean Forecast, Median Forecast, and configurable percentile bounds (default 5th/95th).
Optional rolling HTF-days mean line (yellow) for trend context.
Optional labels and forward projection lines.
Alerts when the confirmed close breaks above or below the percentile band.
Non-Repainting & HTF Behavior (Fail-Closed)
All calculations are gated to confirmed bars only via explicit no_repaint_ok gate (barstate.isconfirmed).
If you select an HTF Resolution, the script uses a strict request.security(..., lookahead_off, gaps_off) pipeline.
If HTF data is unavailable, outputs are na—no silent fallback to chart timeframe.
A separate "HTF Alignment (lagged)" plot shows the prior HTF close (htf_price[1]) as visual proof of no look-ahead.
Volatility Source & Scaling
If "Use Historical Volatility" is enabled, volatility is estimated from log returns on the selected resolution (HTF if set, otherwise chart).
Annualization adapts to session type:
Equities: 6.5 hours/day, 252 trading days/year
Crypto: 24 hours/day, 365 days/year
Substeps increase path smoothness within the same one-bar horizon—they do not extend the forecast to multiple bars.
Key Inputs
• Prob Up / Prob Down — Must satisfy Prob Up + Prob Down ≤ 1.0. If violated, simulation is skipped and table shows "✗ PROB>1".
• # Simulations / # Substeps — Higher = smoother/more stable, but slower. Default 100×100 is a good balance.
• Lower/Upper Percentile — Define the band width (e.g., 5 and 95 for a 90% distribution band).
• Run On Last Bar Only — Performance mode (recommended). Skips historical computation; updates on each new confirmed bar.
• Resolution (HTF) — Leave blank for chart timeframe, or set to Weekly/Monthly for HTF-aligned simulation.
• Crypto 24/7 Session? — Enable for crypto markets to use correct annualization (365d, 24h).
How to Use (Quickstart)
Start with defaults and keep Run On Last Bar Only = true for speed.
Set Prob Up and Prob Down so their sum ≤ 1.0 (e.g., 0.5 + 0.5 = 1.0 for neutral).
Enable "Use Historical Volatility" and set a Volatility Lookback (e.g., 20 bars) for data-driven vol.
Set Resolution (HTF) if you want the model to run on higher timeframe data (e.g., 1W). Expect updates only when a new HTF interval starts.
Choose percentiles (e.g., 5 and 95) to define your distribution band width.
Enable alerts for "Price Above Upper Percentile" or "Price Below Lower Percentile" to get notified of breakouts.
Limitations & Disclosures
- Forecast horizon is one bar only. Substeps do not create a multi-bar forecast.
- Model uses uniform shocks with direction chosen from Prob Up/Down. This is not Geometric Brownian Motion (GBM) and is not calibrated to any option-implied distribution.
- Bounds are percentiles of final simulated prices, not a statistical confidence interval of the mean.
- HTF mode updates at the start of a new HTF interval (first chart bar where the HTF timestamp changes), so the band appears "step-like" in realtime.
- Historical volatility requires enough bars for the selected lookback; until then, values may be na.
- Performance depends on Sims × Substeps; extreme settings (e.g., 500×500) can be slow.
- This indicator does not predict direction—it shows a probabilistic range based on your inputs.
릴리즈 노트
Fixed an error in referencing too many historical bars오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.