OPEN-SOURCE SCRIPT
Zaktualizowano

Post 9/21 EMA Cross — Paint X Bars

210
* Watches for **9 EMA crossing the 21 EMA** (a classic momentum/trend trigger).
* When a cross happens, it **paints exactly X bars** after the cross in a color you choose:

* **Bullish cross (9 > 21):** paints your bullish color for X bars.
* **Bearish cross (9 < 21):** paints your bearish color for X bars.
* You decide whether the **cross bar itself counts** as the first painted bar.
* Optionally plots the 9 & 21 EMAs so you can see the cross visually.

# Why that’s useful

* **Focus:** It reduces noise by spotlighting the **immediate post‑cross window** when momentum often continues.
* **Discipline:** “Exactly X bars” forces consistency, avoiding “just one more bar” bias.
* **Speed:** Color‑coded candles make it easy to scan charts fast (great for intraday work).

# How signals are defined

* **Bullish condition:** `ta.crossover(EMA9, EMA21)` — the fast EMA crosses **up** through the slow EMA.
* **Bearish condition:** `ta.crossunder(EMA9, EMA21)` — the fast EMA crosses **down** through the slow EMA.

# Key inputs (and what they control)

* **Fast EMA Length (default 9)** and **Slow EMA Length (default 21)**
Change these if your system uses different lookbacks (e.g., 8/21 or 10/20).
***CURRENTLY THE EMA REMAINS STATIC ON THE CHART. PLOT EMA FROM EXTERNAL INDICATOR FOR NOW
* **Bars to Paint After a Cross (default 5)**
How many bars get highlighted post‑cross.
* **Include the Cross Bar Itself? (default off)**
Turn on if you want painting to start **on** the cross candle; off to start **after** it.
* **Bullish/Bearish Paint Colors**
Set your preferred colors (e.g., green/red).
* **Plot EMAs on Chart?**
If off, the logic still works; it just hides the EMA lines.

# What you’ll see on the chart

* Candles **recolored** for exactly X bars after each cross, matching the direction.
* (Optional) 9 & 21 EMA lines so you can confirm the cross visually.
* When the X‑bar window ends, candles return to normal until the **next** cross.

# Practical trading uses

* **Entry timing:** Consider entries only during the painted window to align with fresh momentum.
* **Scaling logic:** Scale in/out within the painted window; stop adding when painting ends.
* **Context filter:** Use the paint as a **“go / no‑go” overlay** on top of your pattern or level setups (breakouts, pullbacks to EMA, ORB, etc.).



Informacje o Wersji
**Post 9/21 EMA Cross — Paint X Bars (Confirm on 2nd Bar)**

This indicator highlights price candles after a **9 EMA / 21 EMA crossover**, but with a unique confirmation filter designed to help traders focus on higher-probability setups.

---
🔑 **How It Works**

1. **EMA Cross Trigger**

* When the **9 EMA** crosses above the **21 EMA**, that’s a bullish trigger.
* When the **9 EMA** crosses below the **21 EMA**, that’s a bearish trigger.

2. **Two-Bar Confirmation Rule**

* The **first bar** after the cross is **tentative** and left unpainted.
* The **second bar** must show **displacement** (momentum):

* Bullish: the 2nd candle’s close > previous candle’s high.
* Bearish: the 2nd candle’s close < previous candle’s low.
* Only if this displacement occurs does the script retroactively paint the cross bar (bar 0) and continue painting the next candles.
* If the 2nd bar fails to confirm, no candles are painted — keeping charts clean and avoiding weak signals.

3. **Painted Window**

* You choose how many candles to paint (e.g. 5).
* Once confirmed, candles are recolored for that many bars.
* After the window expires, the script waits for the next cross.

---
🎨 **Visuals**

* **Bullish confirmation:** candles are painted in your bullish color (default lime green).
* **Bearish confirmation:** candles are painted in your bearish color (default red).
* Optionally plots the **9 EMA** and **21 EMA** for easy visual tracking.

---
⚙️ **Inputs**

* **Fast EMA Length (default 9)**
* **Slow EMA Length (default 21)**
* **Bars to Paint After a Cross (default 5)**
* **Bullish/Bearish Paint Colors**
* **Strict Displacement Option** (tighter filter that requires a stronger candle body breakout)
* **Show/Hide EMA Lines**

---
📈 **Why Traders Use This**

* **Clarity** – Only highlights confirmed momentum after a cross, reducing noise.
* **Discipline** – Forces you to wait for confirmation instead of chasing weak crosses.
* **Focus** – Visually marks the short-term momentum window after fresh EMA alignment.

🕒 **Sessions**

By default, the script runs on **all visible chart sessions**. If your chart includes pre-market/after-hours candles, those are part of the logic. You can add a session filter (e.g., 09:30–16:00 ET for U.S. stocks) if you want to restrict signals to regular trading hours.

🚨 **Practical Use**

* Best used as a **confirmation overlay**:

* Combine with your own support/resistance or breakout levels.
* Treat painted bars as a **“green light”** to look for setups.
* Not a standalone buy/sell signal — it’s a **visual filter** to highlight when momentum aligns after an EMA cross.

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.