OPEN-SOURCE SCRIPT

Dynamic 9 EMA

159
What this script does

**Dynamic 9 EMA State by 20 EMA & MACD** is a visual trend and momentum tool built around a single idea:

> Turn the classic 9 EMA into a **three-state engine** (Bullish / Bearish / Neutral) by requiring agreement between the **9 vs 20 EMA trend** and a **MACD signal filter**, then display that state directly on price with one clean, readable overlay.

Instead of stacking multiple separate indicators, this script fuses them into one decision layer that is easy to see at a glance.

---

Core Logic

This script is not a random mashup. Each component has a specific role in a single, unified model:

1. **Trend Backbone: 9 EMA vs 20 EMA**
- When `9 EMA > 20 EMA`, price is in a short-term bullish environment.
- When `9 EMA < 20 EMA`, price is in a short-term bearish environment.
- The 20 EMA is treated as the reference bias; the 9 EMA tracks short-term behaviour.

2. **Momentum Filter: MACD Line vs Signal Line**
- MACD is calculated from user-defined lengths.
- When `MACD line > Signal line`, momentum confirms bullish pressure.
- When `MACD line < Signal line`, momentum confirms bearish pressure.

3. **Three-State Engine**
- **Bullish State (Green)**:
`9 EMA > 20 EMA` **and** `MACD line > Signal line`.
-> Short-term trend and momentum are aligned up.
- **Bearish State (Red)**:
`9 EMA < 20 EMA` **and** `MACD line < Signal line`.
-> Short-term trend and momentum are aligned down.
- **Neutral / Caution State (Yellow)**:
Any situation where EMAs and MACD **do not agree**.
-> Potential transition, chop, or indecision.

The color of the **9 EMA line** reflects this state in real time.

---

Visual Design and Why It Matters

All visuals are built to make the state engine intuitive and clean:

- **Dynamic 9 EMA line**
- Changes color (Bullish / Bearish / Neutral) based on the combined EMA + MACD logic.
- This is the core signal; you don’t need extra subwindows to interpret it.

- **Optional 20 EMA**
- Plotted as a simple reference trend line.
- Can be hidden if you only want the state color and glow.

- **Glow Effect (optional)**
- Multiple soft layers drawn around the 9 EMA.
- Uses the same state color to emphasize regime changes without adding extra indicators.
- Purely visual; no separate signals.

- **Cross Markers (optional)**
- Marks when the 9 EMA crosses the 20 EMA.
- Helps visually confirm where state bias may start to shift.
- Fully optional and configurable in size.

No unrelated scripts are required. The chart is meant to be published **clean**, with this indicator as the primary visual element.

---

How to Use It

1. **Trend Confirmation**
- Focus on the line color:
- Green: Look for long setups only (or manage shorts aggressively).
- Red: Look for short setups only (or manage longs defensively).
- Yellow: Be cautious; conditions are conflicting or transitioning.

2. **Regime Shifts via Alerts**
- Built-in alerts trigger **only when the state changes**:
- Bullish → Bearish
- Bearish → Bullish
- Any → Neutral / Caution
- This lets you track market regime shifts without staring at every candle.

3. **Multi-Timeframe Adaptation**
- Works on any symbol and timeframe supported by TradingView.
- You can tune:
- EMA lengths (9/20 by default),
- MACD parameters,
- Colors, glow, and cross markers,
- To fit scalping, intraday, or swing workflows.

---

Originality & Publication Notes

- This script:
- Uses standard components (EMA, MACD), but
- Combines them into a **structured, three-state regime model** directly encoded into a single EMA line + visual layer.
- Provides **state-based alerts** focused on regime transitions, not just raw indicator values.

- It is **not** a one-click clone of an existing public script.
- It is designed as a single, self-contained tool that replaces the need to stack separate 9 EMA, 20 EMA, and MACD panels just to answer one question:
- “Is the short-term trend and momentum aligned, and in which direction?”

For best compliance with House Rules:
- Publish with a **clean chart** showing only:
- This indicator,
- Candles,
- And any drawings strictly needed to demonstrate usage (or none).
- Avoid emojis in the **title**; they are fine in the description if used sparingly and not as decoration only.

Penafian

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.