MTF Trend Confluence [LeeG]

102
## What this script does

Overlays the trend state from three higher timeframes (defaults 1H / 4H / Daily) onto any chart. Each timeframe votes bull, bear, or flat based on two conditions: close relative to an EMA of chosen length (default 50), and the slope of that EMA over its last confirmed value. The background shades green when all three timeframes agree bullish and red when all three agree bearish. The rest of the time the chart is unshaded. A corner table shows each timeframe's state plus the EMA value it is using. An alert fires the moment all three agree, so you can leave it on in the background.

## How it works (plain-English mechanics)

For each of the three input timeframes, the script runs `request.security()` with `barmerge.lookahead_off` to pull the higher-timeframe `close` and EMA. The EMA is calculated inside the `request.security` call so it reflects the HTF context, not the current chart's. The slope condition uses `valuewhen` on the last confirmed EMA value, so slope is checked against the completed prior bar, not the still-forming current one.

A timeframe is counted bullish when close is above the EMA AND the EMA slope is positive against its previous confirmed value. Bearish is the mirror. Any other state is flat. When all three timeframes agree bull or bear at bar close, the alert condition is satisfied.

## How to use it

Load it on your execution timeframe (15m or 30m on a liquid FX pair is a clean starting point) and use the shaded background as a direction filter, not as a trade signal. The shade turning green does not mean "go long" — it means "the three higher timeframes are aligned bullish, so only look for longs you would have taken anyway." The table gives you the state of each HTF at a glance so you can see which timeframe is dragging.

The alert fires once per flip at bar close. If you only want to trade one direction per day, set the alert to "once per bar" and gate it by your own scheduler on the receiving side.

## Why this script, versus others in the same category

Most multi-timeframe scripts either drop one bool per TF (noisy) or stack three indicators (slow). This one uses a two-condition rule (close vs EMA + slope confirmation) per TF so it does not flip on a one-bar spike through the EMA. The slope check runs against the prior confirmed value, not the live bar, so there is no intraday EMA-wobble repaint. The alignment alert reads the three states in one condition at bar close — no three separate alerts to combine.

## Limitations (what it does NOT do)

- It does not generate entries or exits. It is a direction filter.
- It does not predict anything. All it does is read three HTF trends at the current bar.
- On very low-liquidity symbols or very short TFs, the EMA slope can flip bar to bar even with the confirmation. If that happens, raise the EMA length or move to a slower TF.
- The script uses only close-based EMA. If you prefer HL2 or Heikin-Ashi style smoothing, change the EMA source input — but note that Heikin-Ashi source can produce misleading signals (see TradingView's own guidance on non-standard chart types).

## Inputs

Three higher timeframe strings (default `60`, `240`, `D`). EMA length (default 50). EMA source (default close). Toggles for the background shade, the status table, flip labels, and the bar-close alert. Table position and size. Every input has a tooltip.

## Non-repaint declaration

`request.security()` uses `barmerge.lookahead_off` on every call. The slope comparison uses `valuewhen(..., 1)` so the "previous EMA" is the last confirmed value, not the live one. Alerts gate on `barstate.isconfirmed`, so a live-bar flicker never fires the alert. Repainting-at-bar-close (standard, documented Pine behavior) applies — the signal that fires at bar close is the signal that stays.

Open-source Pine v6.

คำจำกัดสิทธิ์ความรับผิดชอบ

ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน