OPEN-SOURCE SCRIPT
ที่อัปเดต: Event Study: Forward Returns Analyzer After Price Shock

Event Study – Forward Returns Analyzer identifies historical price shocks on any asset and measures forward performance across four calendar horizons: 1, 3, 6, and 12 months after the event.
Define a drop threshold and the indicator automatically detects every qualifying session, logs the date and magnitude of the shock, then tracks the exact price 1, 3, 6, and 12 calendar months later — using timestamp arithmetic rather than bar counts, so results are precise regardless of trading day variations, holidays, or timeframe used.
What you get:
A paginated event table with every shock dated and color-coded, plus a persistent statistics panel showing Average, Median, Win Rate, Skewness, Max Drawdown, and Sharpe Ratio across all four horizons — always calculated on the full filtered sample, regardless of which page you're viewing.
Sample controls:
- Start From Year: focus the analysis on a specific regime, ignoring older history
- Exclude Month / Year: surgically remove structural outliers from the sample (e.g. April 2020 for crude oil futures
CL1! )
Designed for: macro researchers, cross-asset analysts, and systematic traders who want to quantify how an asset historically behaves in the weeks and months following a sharp sell-off.
Works on any daily chart. No repainting. No bar-count approximations.
Define a drop threshold and the indicator automatically detects every qualifying session, logs the date and magnitude of the shock, then tracks the exact price 1, 3, 6, and 12 calendar months later — using timestamp arithmetic rather than bar counts, so results are precise regardless of trading day variations, holidays, or timeframe used.
What you get:
A paginated event table with every shock dated and color-coded, plus a persistent statistics panel showing Average, Median, Win Rate, Skewness, Max Drawdown, and Sharpe Ratio across all four horizons — always calculated on the full filtered sample, regardless of which page you're viewing.
Sample controls:
- Start From Year: focus the analysis on a specific regime, ignoring older history
- Exclude Month / Year: surgically remove structural outliers from the sample (e.g. April 2020 for crude oil futures
Designed for: macro researchers, cross-asset analysts, and systematic traders who want to quantify how an asset historically behaves in the weeks and months following a sharp sell-off.
Works on any daily chart. No repainting. No bar-count approximations.
Release Note
v2 – Event Direction + Rolling WindowThis update introduces two major enhancements to the Event Study analyzer:
1. Dual event direction
The indicator now supports both Drop and Rally detection. Select the event direction from the new dropdown input: "Drop" triggers on cumulative returns ≤ −threshold, "Rally" on cumulative returns ≥ +threshold. The table header dynamically reflects the active mode with color coding (red for drops, green for rallies).
2. Flexible rolling window
Instead of detecting single-candle moves only, you can now define a multi-bar rolling window (1 to 252 bars). On a Daily chart, setting Window = 10 detects any 10-day cumulative move that exceeds the threshold. This allows event studies across weekly, monthly, or custom horizons without switching timeframes.
3. Cooldown filter
A configurable cooldown (in bars) prevents overlapping events from being registered consecutively, avoiding double-counting during sustained trending moves.
Release Note
Max Drawdown fix: worst case instead of averageFixed the MAX DD row in the statistics panel.
Previously, the indicator displayed the average of per-event maximum drawdowns across all detected events. This was misleading — it smoothed out the tail risk and understated the worst outcomes.
The MAX DD row now shows the single worst drawdown observed across all events for each forward return horizon (1M, 3M, 6M, 12M). This gives a more accurate picture of the maximum pain experienced after a trigger event, which is the relevant metric for risk management purposes.
Release Note
Streak Filter + Unconstrained BenchmarkTwo new features added.
1. Consecutive streak filter
A new optional filter under "Streak Filter" group. When enabled, an event is only registered if the asset has printed N or more consecutive up or down closes immediately before the trigger. Useful for isolating drops that occur after sustained rallies, or rallies that emerge from persistent selling pressure. The active streak condition is displayed in the table title (e.g. STK:Up3). Streak length is a minimum threshold — a setting of 3 captures streaks of 3 or more consecutive bars.
2. Unconstrained benchmark row
A new -- BENCHMARK -- section appears below the stats block, showing the unconditional average forward returns of the asset at 1M, 3M, 6M, and 12M horizons — with no event filter applied. This allows direct comparison between post-event returns and what the asset does on average across all historical periods. If your event AVG is higher than the benchmark, the event genuinely predicts above-average forward performance.
Release Note
Benchmark fix- The AVG (unconstrained) benchmark was producing different values depending on the chart timeframe. The benchmark is now always computed on Daily data via request.security, with fixed offsets of 21/63/126/252 bars corresponding to 1M/3M/6M/12M. Switching between Daily, Weekly, or Monthly charts no longer affects the benchmark values.สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน