OPEN-SOURCE SCRIPT
Session-Conditioned Regime ATR

Why this exists
Classic ATR is great—until the open. The first few bars often inherit overnight gaps and 24-hour noise that have nothing to do with the intraday regime you actually trade. That inflates early ATR, scrambles thresholds, and invites hyper-recency bias (“today is crazy!”) when it’s just the open being the open.
This tool was built to:
Overview
Purpose: objectively identify unusually big or small candles within the active trading session, compared to the recent session regime.
Use cases: volatility filters, entry/exit confirmation, session bias detection, adaptive sizing.
This indicator replaces generic ATR with a session-conditioned, regime-aware measure. It colors candles only when their True Range (TR) is abnormally large/small versus the last N completed sessions of the same session window.
How it works
Panel (top-right by default)
Inputs
Alerts
Notes & limitations
Practical tips
Roadmap
Changelog
v0.9b (Beta)
Session presets (NYSE/CME RTH/FX NY/Custom) with timezone handling.
Panel enhancements: ratio + sample size n.
Four-state bar coloring (big/small × bull/bear).
Alerts for BIG/SMALL bars.
Hidden Z-score stream for downstream use.
Gap-in-TR toggle for the first in-session bar.
Disclaimer
For educational purposes only. Not investment advice. Validate thresholds and session settings across symbols/timeframes before live use.
Classic ATR is great—until the open. The first few bars often inherit overnight gaps and 24-hour noise that have nothing to do with the intraday regime you actually trade. That inflates early ATR, scrambles thresholds, and invites hyper-recency bias (“today is crazy!”) when it’s just the open being the open.
This tool was built to:
- Separate session reality from 24h noise. Measure volatility only inside your defined session (e.g., NYSE 09:30–16:00 ET).
- Judge candles against the current regime, not the last 2–3 bars. A rolling statistic from the last N completed sessions defines what “typical” means right now.
- Label “large” and “small” objectively. Bars are colored only when True Range meaningfully departs from the session regime—no gut feel, no open-bar distortion (gap inclusion optional).
Overview
Purpose: objectively identify unusually big or small candles within the active trading session, compared to the recent session regime.
Use cases: volatility filters, entry/exit confirmation, session bias detection, adaptive sizing.
This indicator replaces generic ATR with a session-conditioned, regime-aware measure. It colors candles only when their True Range (TR) is abnormally large/small versus the last N completed sessions of the same session window.
How it works
- Session gating: Only bars inside the selected session are evaluated (presets for NYSE, CME RTH, FX NY; custom supported).
- Per-bar TR: TR = max(high, prevRef) − min(low, prevRef).
- prevRef is the prior close for in-session bars.
- First bar of the session can include the overnight gap (optional; default off).
- Regime statistic: For any bar in session k, aggregate all in-session TRs from the previous N completed sessions (k−N … k−1), then compute Median (default) or Mean.
- Today’s anchor: Running statistic from today’s session start → current bar (for context and the on-chart ratio).
- Color logic:
- Big if TR ≥ bigMult × RegimeStat
- Small if TR ≤ smallMult × RegimeStat
- Colored states: big bull, big bear, small bull, small bear.
- Non-triggering bars retain the chart’s native colors.
Panel (top-right by default)
- Regime ATR (Nd): session-conditioned statistic over the past N completed sessions.
- Today ATR (anchored): running statistic for the current session.
- Ratio (Today/Regime): intraday volatility vs regime.
- Sample size n: number of bars used in the regime calculation.
Inputs
- Session Preset: NYSE (09:30–16:00 ET), CME RTH (08:30–15:00 CT), FX NY (08:00–17:00 ET), Custom (session + IANA timezone).
- Regime Window: number of completed sessions (default 5).
- Statistic: Median (robust) or Mean.
- Include Open Gap: include overnight gap in the first in-session bar’s TR (default off).
- Big/Small thresholds: multipliers relative to RegimeStat (defaults: Big=1.5×, Small=0.67×).
- Colors: four independent colors for big/small × bull/bear.
- Panel position & text size.
- Hidden outputs: expose RegimeStat, TodayStat, Ratio, and Z-score to other scripts.
Alerts
- RegimeATR: BIG bar — triggers when a bar meets the “Big” condition.
- RegimeATR: SMALL bar — triggers when a bar meets the “Small” condition.
- Hidden outputs (for strategies/screeners)
- RegimeATR_stat, TodayATR_stat, Today_vs_Regime_Ratio, BarTR_Zscore.
Notes & limitations
- No look-ahead: calculations only use information available up to that bar. Historical colors reflect what would have been known then.
- Warm-up: colors begin once there are at least N completed sessions; before that, regime is undefined by design.
- Changing inputs (session window, multipliers, median/mean, gap toggle) recomputes the full series using the same rolling regime logic per bar.
- Designed for standard candles. Styling respects existing chart colors when no condition triggers.
Practical tips
- For a broader or tighter notion of “unusual,” adjust Big/Small multipliers.
- Prefer Median in markets prone to outliers; use Mean if you want Z-score alignment with the panel’s regime mean/std.
- Use the Ratio readout to spot compression/expansion days quickly (e.g., <0.7× = compressed session, >1.3× = expanded).
Roadmap
- More session presets:
- 24h continuous (crypto, index CFDs).
- 23h/Globex futures (CME ETH with a 60-minute maintenance break).
- Regional equities (LSE, Xetra, TSE), Asia/Europe/NY overlaps for FX.
- Half-day/holiday templates and dynamic calendars.
- Multi-regime comparison: track multiple overlapping regimes (e.g., RTH vs ETH for futures) and show separate stats/ratios.
- Robust stats options: trimmed mean, MAD/Huber alternatives; optional percentile thresholds instead of fixed multipliers.
- Subpanel visuals: rolling TodayATR and Ratio plots; optional Z-score ribbon.
- Screener/strategy hooks: export boolean series for BIG/SMALL, plus a lightweight strategy template for backtesting entries/exits conditioned on regime volatility.
- Performance/QOL: per-symbol presets, smarter warm-up, and finer control over sample caps for ultra-low TF charts.
Changelog
v0.9b (Beta)
Session presets (NYSE/CME RTH/FX NY/Custom) with timezone handling.
Panel enhancements: ratio + sample size n.
Four-state bar coloring (big/small × bull/bear).
Alerts for BIG/SMALL bars.
Hidden Z-score stream for downstream use.
Gap-in-TR toggle for the first in-session bar.
Disclaimer
For educational purposes only. Not investment advice. Validate thresholds and session settings across symbols/timeframes before live use.
Skrypt open-source
W duchu TradingView twórca tego skryptu udostępnił go jako open-source, aby traderzy mogli analizować i weryfikować jego funkcjonalność. Brawo dla autora! Możesz korzystać z niego za darmo, ale pamiętaj, że ponowna publikacja kodu podlega naszym Zasadom Społeczności.
Wyłączenie odpowiedzialności
Informacje i publikacje przygotowane przez TradingView lub jego użytkowników, prezentowane na tej stronie, nie stanowią rekomendacji ani porad handlowych, inwestycyjnych i finansowych i nie powinny być w ten sposób traktowane ani wykorzystywane. Więcej informacji na ten temat znajdziesz w naszym Regulaminie.
Skrypt open-source
W duchu TradingView twórca tego skryptu udostępnił go jako open-source, aby traderzy mogli analizować i weryfikować jego funkcjonalność. Brawo dla autora! Możesz korzystać z niego za darmo, ale pamiętaj, że ponowna publikacja kodu podlega naszym Zasadom Społeczności.
Wyłączenie odpowiedzialności
Informacje i publikacje przygotowane przez TradingView lub jego użytkowników, prezentowane na tej stronie, nie stanowią rekomendacji ani porad handlowych, inwestycyjnych i finansowych i nie powinny być w ten sposób traktowane ani wykorzystywane. Więcej informacji na ten temat znajdziesz w naszym Regulaminie.