EMA Slope Pro - Dual Higher Timeframe Structural Trend Filter
What the indicator does
-This indicator plots two independent Exponential Moving Averages, each sourced from a separate user-configurable higher timeframe, directly onto your execution chart. The key difference from a standard EMA is that each line is color-coded in real time based on a quantified slope measurement — a normalized percentage that tells you not just the direction of the trend but its actual rate of change. The slope value and directional state are displayed as a live label at the right edge of each line, so you can filter entries by momentum magnitude rather than visual impression.
-The two EMAs create a dual-layer structural filter. EMA 1 (default: 200-period on the 4-hour timeframe) tracks the intermediate trend. EMA 2 (default: 200-period on the Daily timeframe) tracks the primary trend. A dedicated confluence alert fires when both layers simultaneously agree on direction, identifying the highest-confidence setups.
How it works
-Both EMAs and their slopes are calculated entirely inside request.security() calls — all arithmetic runs on the higher timeframe dataset before the results are returned to your chart. This eliminates cross-timeframe contamination that occurs when HTF prices are fetched and then processed against lower-timeframe bar series.
-The slope formula is: ((EMA_now - EMA ) / close) * 100. Dividing by the current closing price normalises the result so it is dimensionally consistent across all instruments regardless of price magnitude. A crypto pair at $60,000 and a forex pair at $1.08 will show comparable slope readings for equivalent structural momentum. Without this normalisation, the raw EMA delta is meaningless for cross-instrument comparison.
-On repainting: all request.security() calls in this indicator use exclusively barmerge.lookahead_off — the only setting that does not introduce lookahead bias. The "Wait for Candle Close" toggle controls whether each EMA updates only on confirmed HTF bar closes (the default, recommended for signal use) or on every realtime tick using the current live close. The live-tick mode does not use lookahead_on and does not fetch future prices — it uses the current bar's close as it builds, which is the live market price, not a future value. Both modes are zero-repainting by design.
-A single shared flat threshold (default 0.05%) is applied to both EMAs. When the absolute slope of either EMA falls below this value, that line is painted in the sideways color and treated as a low-momentum zone. This threshold is configurable to match the volatility profile of the instrument you are trading.
What makes it original
-A standard EMA gives you a curved line. Whether that line is rising sharply or barely drifting upward is left entirely to visual interpretation. This indicator resolves that ambiguity by converting each EMA's motion into a live, normalized rate-of-change percentage shown directly on the chart. You can then apply a minimum slope threshold as a signal filter — for example, only take long setups when EMA 1 is above +0.08% and EMA 2 is above +0.05%, which means both the intermediate and primary trends are not just directionally positive but actively accelerating.
-The dual-HTF architecture means you get two independent structural readings simultaneously on a single chart without manually switching timeframes. The confluence alert fires only on the first bar where both layers agree, using state-transition detection — it does not repeat on every bar where the condition holds. This is the same approach institutional desks use to qualify trend regime entries: requiring agreement from multiple timeframe layers before considering a position.
How to use it
-Set your chart to your execution timeframe. Set EMA 1 to a timeframe approximately four times your chart (for a 15-minute chart, use 1H or 4H). Leave EMA 2 on the Daily default, or raise it to Weekly for broader confirmation.
-Both lines green (bullish): intermediate and primary trends are aligned upward. Look for long setups on your execution timeframe. Avoid counter-trend shorts.
Both lines red (bearish): both trend layers agree to the downside. Look for short setups. Avoid longs.
Mixed state (one green, one grey or red): structural disagreement between timeframes. Reduce position size or wait for alignment.
Both lines grey: low-momentum range conditions across both timeframes. Avoid trend-following entries entirely.
F-or precision filtering, use the slope label values directly. A reading of +0.10% or above on EMA 2 indicates an established, actively accelerating trend. Readings between 0.05% and 0.10% signal a trend building momentum — tradeable but with tighter risk parameters. Below the flat threshold on either line, treat that timeframe as structurally neutral regardless of the line's visual direction.
-For alerts, the "EMA 1 + EMA 2 - Confluence Agreement" alert is the primary signal. Set it to fire on bar close. Use the individual EMA 1 and EMA 2 bullish and bearish transition alerts as early-warning notifications for when one trend layer changes before the other has confirmed.
Settings
-EMA 1 - Length: Period of the first EMA. Default 200 tracks long-term institutional structure. Use 50 for intermediate-term trend tracking.
-EMA 1 - Timeframe: Higher timeframe source for EMA 1. Default 4H. For day trading on a 5-minute chart, 1H or 4H works well.
-EMA 2 - Length: Period of the second EMA. Default 200. Can be set to a different length than EMA 1 to monitor two distinct structural levels simultaneously — for example, EMA 1 at 50 on 4H for intermediate structure and EMA 2 at 200 on Daily for primary structure.
-EMA 2 - Timeframe: Higher timeframe source for EMA 2. Default Daily. For long-term swing trading, raise to Weekly.
-Show EMA 2: Toggles the EMA 2 line on or off. Alert conditions for EMA 2 remain active even when the line is hidden.
-Slope Lookback Bars: Number of higher timeframe bars over which the slope is measured. Default 10. On a 4H chart this covers 40 hours. On the Daily it covers two calendar weeks. Increase to smooth volatility spikes; decrease for faster response to structural changes.
-Wait for Candle Close: When on, both EMAs update only after their respective HTF bar closes. Strongly recommended for all signal-based use to avoid acting on in-progress, unconfirmed HTF values.
-Flat Threshold (%): The slope cutoff for the sideways classification. Default 0.05%. Raise to 0.10-0.15% for high-volatility crypto markets. Lower to 0.02-0.03% for low-volatility instruments such as major forex pairs.
-EMA 1 and EMA 2 Line Width: Independent visual thickness controls. Default 4 for EMA 1 and 2 for EMA 2, creating a clear visual hierarchy between the primary and secondary layers.
-Bullish / Bearish / Flat Colors: All three state colours apply to both EMAs simultaneously. The shared palette ensures instant visual comparison between the two lines.
-Show Slope Labels: Displays a live label at the right edge of each EMA showing the current slope percentage and directional state (BULL, BEAR, or SIDE).
-Bullish Color / Bearish Color / Flat Color: Line colours for each of the three states. Fully customisable. These apply to both EMA lines simultaneously so the colour coding remains visually consistent across both timeframe layers.
-Show Background Tint: Enables a subtle background colour wash driven by EMA 2 trend state. Green when EMA 2 is bullish, red when bearish, no tint when flat. The tint colour is independent from the EMA line colours — you can use a softer shade for the background without affecting the line colour logic.
-Background Bullish Color / Background Bearish Color: The exact colour used for the background wash in each directional state. Default values are a soft green and soft red. For traders using dark themes, a slightly more saturated colour at higher transparency reads more clearly than a very light shade at low transparency.
-Background Tint Transparency: Controls how prominent the background wash is. Range 0 (fully opaque) to 99 (invisible). Default 93 produces a subtle ambient tint. Raise to 96-98 for a near-invisible hint of direction, lower to 85-88 for a stronger zone marker. Does not affect the EMA line colours.
-Alerts: Six independent alert conditions — three for EMA 1 (bullish, bearish, and flat-zone transitions), two for EMA 2 (bullish and bearish transitions), and one confluence alert for when both EMAs agree on direction simultaneously. All fire once per state change only, not on every bar.
Markets and timeframes
Works on all markets: equities, indices, forex, crypto, and commodities. The slope normalisation formula makes readings comparable across all price scales.
For intraday traders (5-minute to 15-minute execution): set EMA 1 to 1H or 4H, EMA 2 to Daily. Use the confluence alert as the primary bias filter and apply your entry method only in the agreed direction.
For swing traders (1H to 4H execution): set EMA 1 to Daily, EMA 2 to Weekly. This layers a weekly structural view over a daily intermediate view.
For crypto traders: raise the flat threshold to 0.08-0.12% to account for the higher baseline volatility of crypto markets compared to equities or forex.
This is a structural bias filter, not a standalone entry system. It is designed to work alongside your existing entry methodology to eliminate low-probability setups taken against the dominant multi-timeframe trend.
Disclaimer
Past performance of any indicator is not indicative of future results. This tool is provided for informational and educational purposes and does not constitute financial advice. Suitable for all markets and all timeframes. Always apply appropriate position sizing and risk management.
Pine Script® göstergesi






















