OPEN-SOURCE SCRIPT

EMA 30/50/100 Long Entries + MTF Trend

416
# EMA 30/50/100 Long Entries + MTF Trend

A long-only trend-following indicator that combines a 30/50/100 EMA stack with two entry triggers (breakout and retest) and an optional higher-timeframe trend filter. It was designed with Indian equities (NSE/BSE) in mind, but it works on any symbol and timeframe.

## How it works

### 1. Setup (yellow diamond)
A setup forms on the bar where all of these become true:
- The 30 EMA is above the 50 EMA
- The 30 EMA is above the 100 EMA
- The 50 EMA is above the 100 EMA

The setup stays active until the EMA stack loses alignment. While it is active, the background is shaded green if the trend filters pass.

### 2. Entry A: Breakout (green "BO" label)
While a setup is active, a Breakout fires when the close is above the highest high of the previous N bars (default 10).

### 3. Entry B: Retest (blue "RT" label)
While a setup is active:
- A candle dips to or below any of the three EMAs but closes back above it.
- The next candle closes above that candle's high, which confirms the bounce.

Each entry type fires only once per setup, so you do not get repeated signals in the same trend. The flags reset when a new setup forms.

## Trend filters

### Higher timeframe filter (on by default)
The higher timeframe is bullish when its last completed close is above its 30 EMA and its 30 EMA is above its 50 EMA. The higher timeframe is chosen automatically:

| Chart timeframe | Higher timeframe |
|---|---|
| 1 minute or lower | 5 minutes |
| 5 minutes | 15 minutes |
| 15 minutes | 1 hour |
| 1 hour to 4 hours | Daily |
| Daily | Weekly |
| Weekly and above | Monthly |

You can override this in the settings. The filter reads the last completed higher-timeframe bar, so it does not repaint. On a Daily chart, the weekly reading can lag by up to one week.

### Current timeframe filter (off by default)
Requires price to be above a rising 100 EMA. The EMA alignment already implies most of this, so it is optional.

### New listings
If a symbol does not have enough higher-timeframe history (about 50 bars), the higher-timeframe filter passes by default so recent IPOs are not blocked. You can turn this off in the settings.

## Inputs

| Input | Default | Description |
|---|---|---|
| Breakout lookback (bars) | 10 | Number of previous bars used to find the prior high |
| Use higher timeframe filter | On | Requires a bullish higher timeframe for entries |
| Use current timeframe filter | Off | Requires price above a rising 100 EMA |
| Pass HTF filter if not enough history | On | Lets new listings through |
| Slope lookback | 5 | Bars used to measure the 100 EMA slope (current timeframe filter) |
| Higher timeframe | Auto | Auto, 5, 15, 60, D, W or M |

## Visuals
- **EMAs:** 30 (aqua), 50 (orange), 100 (red)
- **Yellow diamond:** Setup formed
- **BO / RT labels:** Breakout and Retest entries
- **Green background:** Setup active and trend filters passing
- **Status table (top right):** Current timeframe state, higher-timeframe state, and whether entries are enabled or blocked

## Alerts
Four alert conditions are available:
- Setup Happened
- Setup Happened + Trend OK
- Long Entry - Breakout
- Long Entry - Retest

Alert messages include the symbol and timeframe. For best results, set the alert trigger to "Once Per Bar Close" so signals are confirmed.

## Screening
Three plots are available in the Data Window for use as columns or filters in the Pine Screener (1 = true, 0 = false):
- Setup
- Setup + Trend OK
- Setup Active

## Suggested use
- **Swing trading:** Daily chart (Weekly filter)
- **Intraday:** 15-minute chart (1-hour filter)

## Notes and limitations
- Long entries only. There are no exit rules, stop losses or targets. Manage risk with your own plan.
- The higher-timeframe filter intentionally uses completed bars to avoid repainting, which adds some delay.
- The strategy is EMA-based and lags price. It performs best in trending markets and can produce false signals in sideways markets.
- Results depend on the symbol, timeframe and period. Test it on your own instruments before using it.

## Disclaimer
This indicator is for educational and informational purposes only and is not financial advice. Trading involves risk, and past performance does not guarantee future results.

Thông báo miễn trừ trách nhiệm

Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.