OPEN-SOURCE SCRIPT
ATR Regime Filter Pro

What this indicator does
-This indicator solves one of the most common and most costly problems in systematic and discretionary trading: entering the market at the wrong time — not because the setup was bad, but because the market's volatility environment was incompatible with the strategy being traded.
-ATR Regime Filter Pro combines two independent, orthogonal filters — a normalised volatility regime classifier and a higher-timeframe EMA slope detector — into a single, real-time dashboard. The output is a clear, three-state market permission signal: Trade, Stay Out, or warning of Extreme conditions.
How it works — the normalised ATR ratio
-The raw Average True Range (ATR) on its own is useful within a single instrument but breaks down the moment you try to compare conditions across assets or even across time on the same asset. A EURUSD ATR of 0.0060 means something completely different in a period of forex calm than in a high-impact macro week.
-To fix this, the indicator normalises the ATR by dividing it by its own Simple Moving Average:
ATR Ratio = ATR(n) / SMA(ATR(n), m)
The result is a dimensionless ratio centred at 1.0 regardless of the asset, timeframe, or price level. A ratio of 1.0 means the current ATR exactly matches its recent average. A ratio of 0.70 means volatility is 30 % below average. A ratio of 2.10 means volatility is 110 % above average.
-Three regimes are classified from this ratio:
1. Dead zone (below the lower threshold, default 0.80)
Volatility is significantly compressed. Spreads and commissions consume a disproportionate share of any move. Mean-reversion traps are common. Breakout signals have a statistically higher failure rate in this environment because price can oscillate within the dead zone for extended periods before any directional resolution occurs. The ATR ratio line turns red, and the pane background turns red. The matrix shows "No Trade."
2. Healthy zone (between the two thresholds)
Volatility is within a normal range relative to recent history. Price moves are large enough to justify risk-reward ratios but not so large that position sizing becomes hazardous. This is the window where most systematic strategies were backtested and are expected to perform. The ATR ratio line turns green. The matrix shows "Trade OK."
3. Extreme zone (above the upper threshold, default 1.80)
Volatility has spiked far above average. This is characteristic of scheduled high-impact news releases, liquidity gaps, and flash events. The danger here is subtle: a stop set at 1× ATR during normal conditions may now represent less than 0.5× the actual daily range, exposing the position to far greater risk than the model assumed. The ATR ratio line turns yellow. The matrix shows "Extreme."
Three static reference lines are drawn at the lower threshold, at 1.0 (the long-term average), and at the upper threshold, giving the ratio line a meaningful visual frame of reference at all times.
The higher-timeframe EMA slope
-Even when the volatility regime is healthy, entering against the dominant trend on a higher timeframe dramatically reduces win rate on most strategies. The second filter measures the slope of an EMA on a user-selected higher timeframe (HTF) and classifies it into three directional states.
-The slope is computed as:
Slope (%) = (EMA[now] − EMA[N bars ago]) / close × 100
Expressing slope as a percentage of price normalizes it across instruments — a 50-pip EMA shift on a 1.1000 pair is not the same directional signal as a 50-pip shift on a 0.6500 pair. Dividing by close makes the signal scale-invariant.
-Three EMA states are classified:
- Bullish: slope percentage above +0.05. The HTF trend is rising. Long setups have macro wind behind them.
- Bearish: slope percentage below −0.05. The HTF trend is falling. Short setups have macro wind behind them.
- Flat: slope percentage between −0.05 and +0.05. The HTF EMA has no meaningful directional conviction. Counter-trend and mean-reversion environments are more likely. The matrix flags this as a warning state (yellow), and the composite permission signal switches to "Stay Out" regardless of ATR regime.
The flat threshold of ±0.05 % is intentionally conservative. It is designed to keep the indicator out of the many false-directional periods that appear during consolidations on higher timeframes, where a technically rising EMA is in fact moving so slowly that its directional claim is economically meaningless.
The composite market permission
-The two filters are combined into a single boolean condition:
Market Permission = ATR in Healthy zone AND EMA slope is NOT flat
When both conditions are true simultaneously, the bottom row of the matrix shows "Trade" in green. Any violation — dead ATR, extreme ATR, or flat EMA slope — sets the bottom row to "Stay Out" in red.
-This AND logic is the core of the indicator's value. Either filter alone is a useful volatility or trend-direction tool available in the public library. The deliberate combination creates something different: a pre-trade environment check that requires the market to be moving in a predictable direction and at a predictable pace before it grants permission. Traders who apply this filter will notice that many losing trades in their existing system occur during exactly the windows this filter would have flagged red.
Originality and how it differs from standard ATR indicators
-Standard ATR indicators display the raw ATR value. Comparing a raw ATR value across different days, instruments, or timeframes requires the user to manually assess whether the current reading is high or low relative to history. This indicator removes that cognitive load entirely by normalizing the value and classifying it into actionable regimes automatically.
-The second point of originality is the EMA slope calculation. A standard EMA displayed on a higher timeframe tells you direction visually, but it does not tell you how strong or weak that direction is in normalised terms. Computing the slope as a percentage of price creates a universally comparable metric. A slope of +0.10 % on a gold futures chart and a +0.10 % slope on a currency pair carry the same relative meaning, which allows consistent threshold values across all markets without requiring per-asset tuning.
-The composite filter — the AND logic combining volatility regime and slope strength — does not exist as a standalone, configurable, dashboard-style indicator in the public library in this form.
How to use it
Step 1 — Set up the ATR parameters for your instrument.
The default ATR length of 14 and average of 50 work well for most liquid markets on timeframes of 15 minutes and above. For very fast scalping timeframes (1–5 minutes), consider shortening the average to 20–30 to make the baseline adapt faster. For weekly or monthly swing trading, lengthening the average to 100 or 200 gives a more stable baseline.
Step 2 — Choose a higher timeframe that makes structural sense.
If you trade on the 15-minute chart, a 4-hour HTF EMA captures the session-level bias. If you trade on the 1-hour chart, Daily or Weekly captures the swing bias most institutional participants track. The HTF should be at least 4× larger than your trading timeframe to avoid redundancy.
Step 3 — Look only at the bottom row of the matrix before entering any trade.
If the bottom row says "Trade" in green, both conditions are met. If it says "Stay Out" in red, investigate the reason by reading the ATR Regime row and EMA Slope row individually — the colour of each tells you which filter triggered.
Step 4 — Use the ATR Ratio line as a continuous volatility context tool, not just a binary filter.
A ratio at 0.85 is close to the no-trade boundary — the regime is borderline, and entries taken here carry higher statistical risk of false breakouts. A ratio at 1.40 sits comfortably in the healthy zone and has historically been associated with cleaner trend-following performance. A ratio pushing toward the upper threshold warns you that a spike is beginning and position size should be pre-emptively reduced.
Step 5 — Configure alerts.
Nine alert conditions are included. The most operationally useful are "Market Permission: TRADE" and "Market Permission: STAY OUT," which fire exactly once when the composite status changes — eliminating the need to watch the indicator continuously.
Alerts included
The following alert conditions are available under the "Create Alert" dialog:
• ATR entered No-Trade zone — triggers when the ratio crosses below the lower threshold.
• ATR exited No-Trade zone — triggers when the ratio recovers above the lower threshold.
• ATR entered Extreme zone — triggers when the ratio crosses above the upper threshold.
• ATR exited Extreme zone — triggers when the ratio drops back below the upper threshold.
• EMA slope turned Flat — triggers once when the HTF slope loses directional conviction.
• EMA slope turned Bullish — triggers once when the HTF slope turns upward.
• EMA slope turned Bearish — triggers once when the HTF slope turns downward.
• Market Permission: TRADE — triggers once when both filters become green simultaneously.
• Market Permission: STAY OUT — triggers once when either filter turns red or yellow.
Input parameters reference
-ATR Length (default 14)
The lookback for the raw ATR calculation. Standard Wilder length. Hover each setting in the indicator panel to read the built-in tooltip.
-ATR Average Length (default 50)
The SMA length applied to the raw ATR to produce the normalisation baseline.
-ATR Lower Threshold (default 0.80)
The ATR Ratio below which the regime is classified as dead/no-trade.
-ATR Upper Threshold (default 1.80)
The ATR Ratio above which the regime is classified as extreme.
-EMA Length — Higher Timeframe (default 200)
The EMA period evaluated on the HTF.
-EMA Slope Lookback (default 10 bars)
How many HTF bars back the slope is measured from.
-Higher Timeframe for EMA (default 4H)
The timeframe on which the EMA is calculated. Should be higher than the chart's timeframe.
-Show Background on Extreme ATR (default off)
Toggles a semi-transparent yellow pane background during extreme volatility.
-Show Background on Healthy ATR (default off)
Toggles a semi-transparent green pane background during healthy-regime bars.
Suitable markets and trading styles
-This indicator is instrument-agnostic and has been designed to work on any liquid market: forex, crypto, equities, commodities, futures, and indices. The normalised ATR ratio ensures the thresholds carry the same meaning regardless of the asset's price level or typical daily range.
Timeframe and style suitability:
-Intraday scalping (1–15 minute charts): The filter is especially valuable here because low-volatility compression periods on intraday charts frequently produce stop-hunt price action that destroys scalping performance. Scalpers using this filter should consider tightening the ATR average length to 20–30 and selecting a 1H or 4H HTF EMA. This is systematic, volatility-filtered scalping — not news trading and not random entry scalping. The filter identifies periods where price has enough kinetic energy to reach a target without reverting before the position is filled.
-Day trading (30-minute to 4-hour charts): The composite filter is very natural here. The ATR regime identifies session-level volatility windows (for example, the first two hours of the London–New York overlap) where conditions are rich enough to trade, while the HTF EMA slope confirms the broader session bias.
-Swing trading (daily charts, 4H charts): The EMA slope filter on Weekly or Monthly adds a macro trend context layer that prevents swing entries against the dominant institutional flow. The ATR filter removes entries during holiday-period compression or pre-earnings illiquidity. This is not buy-and-hold investing; it is active swing trading with a hold period of several days to a few weeks.
-Position trading and investing (weekly or monthly charts): Useful for identifying macro volatility expansion and contraction phases, though the EMA slope filter at this timeframe scale will naturally be slower to react.
Disclaimer
This indicator is a market environment filter, not a standalone trading signal generator. It does not produce buy or sell signals. It identifies conditions where a strategy's edge is statistically more or less likely to hold, based on the two criteria described above. All trading decisions remain the full responsibility of the trader. Past performance of any filter applied to historical data does not guarantee future results. Trading involves substantial risk of loss. Use proper position sizing and risk management at all times.
Script open-source
Nello spirito di TradingView, l'autore di questo script lo ha reso open source, in modo che i trader possano esaminarne e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricordiamo che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.
Script open-source
Nello spirito di TradingView, l'autore di questo script lo ha reso open source, in modo che i trader possano esaminarne e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricordiamo che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.