OPEN-SOURCE SCRIPT
Updated

EMA Buy/Sell & Smart Zones(5Min TF only)

5 577
### **Indicator Title:**

**EMA Buy/Sell & Smart Zones**

---

### **Description:**

**EMA Buy/Sell & Smart Zones** is a specialized intraday trading tool designed to combine trend analysis with precise market structure zones. This script utilizes a custom tracking algorithm to identify the **specific candle** that formed the previous session's high or low, allowing it to plot accurate Supply and Demand zones for the current trading day.

This indicator has been rigorously tested on the **Nifty Index** and is optimized for use on the **5-minute timeframe**.

### **Key Features**

**1. Smart Session Wick Zones ("True Wick" Logic)**
The indicator automatically scans every candle of the previous session to locate the exact price action that formed the day's extremes.

* **Smart High Zone:** Identifies the specific candle that made yesterday's High and plots a zone from that High down to that candle's Open or Close (based on body direction).
* **Smart Low Zone:** Identifies the specific candle that made yesterday's Low and plots a zone from that Low up to that candle's Open or Close.
* **Close Range:** Highlights the High-Low range of the very last candle of the previous session to show the closing sentiment.

*All zones automatically stop extending at the end of the current session, ensuring the chart remains clean and historically accurate.*

**2. EMA Trend System**
The script plots three key Exponential Moving Averages to define market direction:

* **EMA 21:** Captures short-term momentum.
* **EMA 63:** Defines the medium-term trend.
* **EMA 1575:** Establishes the long-term baseline.

**3. Buy/Sell Signals**
Clear signals are generated on the chart based on specific criteria:

* **BUY Signal:** Generated when a green candle closes above the EMA 21 and EMA 63.
* **SELL Signal:** Generated when a red candle closes below the EMA 21 and EMA 63.
* *Note: The logic includes a filter to alternate signals (Buy -> Sell -> Buy), preventing clutter during choppy markets.*

### **How to Use**

* **Recommended Timeframe:** **5 Minutes**.
* **Recommended Markets:** Indices (Nifty, Bank Nifty) and high-volume stocks.
* **Workflow:**
* Use the **Smart Zones** (Red/Green boxes) to identify potential rejection areas or breakout targets.
* Use the **Buy/Sell Labels** as confirmation triggers when price is reacting near these zones or trending strongly above/below the EMAs.



### **Settings & Customization**

* **Visibility Control:** Toggle each box type (High, Low, Close) and text labels on or off individually.
* **Color Customization:** Fully adjustable colors for all EMAs, Zone Backgrounds, Borders, and Text Labels to suit your chart theme.
* **Label Size:** Adjust the text size of the zone labels directly from the settings menu.

---

**Disclaimer:** This tool is for educational purposes and should be used to assist your analysis. Always manage your risk appropriately.
Release Notes
What's New in This Update?
This update introduces a Dynamic Stop Loss (SL) Line to assist with active trade management and risk assessment.

1. Dynamic SL Visualization

Automatic Placement: Whenever a Buy or Sell signal is generated, a horizontal line is automatically plotted at the signal candle's protective level:

For Buy Signals: The line plots at the Low of the signal candle.

For Sell Signals: The line plots at the High of the signal candle.

2. Smart Status Coloring The SL line changes color dynamically based on real-time price action to instantly show the status of the setup:

Green (Safe): The price is respecting the Stop Loss level (e.g., price is above the SL in a Buy trade).

Red (Breached): The price has crossed the Stop Loss level.

Note: If price recovers back into the safe zone, the line automatically reverts to Green.

3. Auto-Extension & Reset

The line extends automatically to the right as the session progresses.

It stops extending immediately when a New Signal appears (creating a new SL line) or when the Session Ends, keeping your chart clean and focused only on the active trade.

How to Use: Use the Green/Red line as a visual guide for your Stop Loss placement. If the line turns red, it indicates the setup's protective level has been breached.

(Settings Update: You can now adjust the width of the SL Line in the settings menu.)
Release Notes
What's New in This Update?
This major update introduces an intelligent Dynamic Stop Loss System designed to filter out market noise and adapt to price recovery. This SL system is purely for scalping purpose in 1min timeframe

1. The "10% Body Break" Rule (Smart Filter) We have upgraded the breakout logic to prevent false alarms caused by simple wicks.

How it works: The Stop Loss line will only turn Red (Broken) if 10% or more of the breaking candle's body crosses the line.

The Benefit: If a candle merely wicks below your SL or barely closes past it (less than 10% body overlap), the line remains Green (Safe). This helps you stay in trades during minor stop-hunts.

(Note: This percentage is customizable in the settings).

2. Intelligent Recovery Logic What happens if the price breaks your SL (turns Red) but then immediately reverses back into the profit zone?

The Fix: If the price "recovers" (closes back above the broken Buy SL or below the broken Sell SL), the indicator automatically stops the old broken line and draws a NEW Green SL Line at the recovery candle's Low (for Buy) or High (for Sell).

This ensures your trailing stop adapts to the most recent support/resistance formed during the recovery.

3. Dynamic Visuals

Centered Labels: The "SL" text label now automatically moves to the center of the line as it extends, keeping it distinct from the Buy/Sell signal icons.

Style Control: You can now choose between Solid, Dotted, or Dashed lines to keep your chart organized.

How to Use:

Green Line: Safe zone. Hold the trade.

Red Line: Danger zone. The price has significantly breached the level (by >10% body mass).

New Green Line after Red: The market has recovered; adjust your risk to this new level.
Release Notes
What's New in This Update?
This major update transforms the indicator into a complete trade management system by adding automatic Target Lines and giving you full control over chart visibility.

1. Dynamic Target Lines (Take Profit)

Automatic Targets: Whenever a Buy or Sell signal appears, a target line is automatically plotted based on the signal candle's range.

Customizable Ratios: You can set your preferred Risk:Reward ratio (e.g., 1:2, 1:3) in the settings. The target distance calculates automatically.

Smart "Hit" Logic:

If price hits the target, the label updates to "Target Hit" and the line freezes to mark the win.

If the trade hits Stop Loss (SL) first, the Target line disappears to keep your chart clean.

If the price recovers and creates a new SL line, a new Target line is instantly calculated for the re-entry.

2. EMA Visibility Controls

Clean Default Look: To reduce clutter, EMA 21 and EMA 63 are now hidden by default. You can easily enable them in the settings menu if you use them for confirmation.

Styled Lines: EMAs now default to a "Cross/Dotted" style to distinguish them clearly from price action and other trend lines.

How to Use the New Features:

Enable/Disable: Go to settings to turn on the Target Line or the hidden EMAs.

Set Your Ratio: Adjust the "Reward Ratio" input to match your trading style (e.g., set to 2.0 for a 1:2 Target).

Trade Management: Use the Green/Red SL line for protection and aim for the Purple Target line for exits.
Release Notes
What's New in This Version?
1. Fixed Point Risk Management

New Input: You can now define your Stop Loss and Target in exact price points (e.g., 20 points SL, 40 points Target) rather than relying on candle size.

Consistent R:R: This removes the variability of setups based on small or large signal candles.

3. "Step" Trailing System

New Logic: Once the first Target is hit, the indicator switches to a "Step Trailing" mode. Both the SL and Target lines will move forward in locked increments (e.g., every 20 points) to secure profits.

Visual Ticks: Target hits are now marked with clear Green Ticks (✔) and labels (T1, T2...), making it easy to track trade progress at a glance.

4. Optimized Recovery Logic

Refined Re-Entry: The "Returning Candle" recovery trade logic has been improved. It now only triggers if the original Fixed SL was broken. If a trade has already trailed and booked profit, the recovery logic is disabled to prevent over-trading on reversals.

5. Chart Cleanup

Session Reset: Old trade lines are automatically removed when a new session starts or an opposite signal is detected, keeping your charts clean while preserving the "Highest Target Hit" labels for performance review.

How to Update Settings:

Go to the Indicator Settings.

Under "Fixed SL & Target Settings", input your desired point values for SL, Target, and Trailing Step.

Toggle "Auto-Adjust SL" based on your risk preference for volatile candles.
Release Notes
Update Release Notes
1. Active Trade Signal Suppression

New Logic: Added an optional feature to "Suppress Opposite Signals" if a trade is currently active. (Default OFF)

Behavior: If enabled, the indicator will ignore new Buy/Sell signals if the current trade has not yet hit its Stop Loss or its first Target. This prevents "whipsaw" signals during active trades.

2. Smart Reversal Mechanism

Pending Signals: If a signal is suppressed due to an active trade, it is marked as "Pending."

Instant Trigger: If the original Stop Loss is subsequently broken, the indicator checks for a Pending Signal. If one exists, it immediately forces a reversal entry on the breakout candle, ensuring you don't miss the reversal move.

Disclaimer

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.