OPEN-SOURCE SCRIPT

Adaptive Support & Resistance Pro with EMA Momentum Filter

1 044
## Description
This indicator is an advanced tool designed to identify adaptive Support and Resistance (S/R) zones and combine them with an Exponential Moving Average (EMA) momentum filter. Unlike static S/R lines, this script uses a combination of momentum oscillators and dynamic pivot calculations to find high-probability reversal zones on higher or current timeframes.

The core philosophy of this indicator is to prevent "knife-catching." Instead of firing a signal immediately when a support or resistance level is formed, it waits for the price to confirm a change in momentum by crossing the EMA line in the direction of the trade.

---

## How It Works (Under the Hood)

### 1. Support & Resistance Detection
The script uses a multi-layered filter to detect true pivot points:
* **Legacy RSI & Modified RSI:** It evaluates overbought (>75) and oversold (<25) conditions using a 9-period Relative Strength Index.
* **Chande Momentum Oscillator (CMO) based on HMA:** It applies a 1-period CMO logic over Hull Moving Averages (HMA 5 and HMA 12) to detect immediate shifts in market velocity.
* **Close Pivots:** It uses deviation-free highest/lowest calculations (`ta.highest` and `ta.lowest`) combined with `ta.valuewhen` to fetch precise structural levels.

A **Support Zone** is formed only when the RSI is oversold, the CMO shows an upward momentum shift (>50), and a local low pivot is confirmed.
A **Resistance Zone** is formed when the RSI is overbought, the CMO shows a downward shift (<-50), and a local high pivot is confirmed.

### 2. S/R Timeframe Flexibility
Through the `request.security` function, users can plot these adaptive levels from higher timeframes (HTF) onto their current chart. To prevent **repainting** and back-shifting signals, the script strictly uses `barmerge.lookahead_off`.

### 3. EMA Momentum Trigger (The Confirmation Filter)
To filter out false breakouts and premature entries during heavy trend extensions, an EMA filter is introduced:
* **BUY Signal:** Triggered only when a new Support level has been established AND the price successfully closes above the EMA (`ta.crossover`).
* **SELL Signal:** Triggered only when a new Resistance level has been established AND the price successfully closes below the EMA (`ta.crossunder`).

**Strict Discipline:** The script uses an internal state machine (`waitForBuyBreak` / `waitForSellBreak`) ensuring that **only ONE signal** is fired per newly created S/R level. This completely eliminates the "whipsaw" effect (multiple false signals) when the price is consolidating or chopping around the moving average.

---

## Settings & Customization

* **Line Width / Colors:** Fully customize the visual thickness and color styling of your Support and Resistance zones.
* **S/R Timeframe:** Leave it blank for the current chart timeframe, or select higher timeframes (e.g., 4H or 1D) for macro level analysis.
* **Enable EMA Filter:** Toggle this option ON to use the momentum confirmation logic, or OFF to see signals immediately upon S/R level creation.
* **EMA Length:** Adjust the period of the confirmation line (Default is 50, but can be set to 20 for faster entries or 200 for macro trend-following).

---

## Alerts
The script includes three built-in alert conditions for automation:
1. `New S/R line` - Triggers whenever a new support or resistance level is plotted.
2. `BUY Signal` - Triggers when the EMA crossover confirms the support bounce.
3. `SELL Signal` - Triggers when the EMA crossunder confirms the resistance rejection.

## Disclaimer
This indicator is meant for educational and analytical purposes only. Past performance does not guarantee future results. Always practice proper risk management.

Haftungsausschluss

Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.