OPEN-SOURCE SCRIPT
Signal Generator: HTF EMA Momentum + MACD

Signal Generator: HTF EMA Momentum + MACD
What this script does
This indicator combines a higher-timeframe EMA trend filter with a MACD crossover on the chart’s timeframe. The goal is to make MACD signals more selective by checking whether they occur in the same direction as the broader trend.
How it works
- On the higher timeframe, two EMAs are calculated (short and long). Their difference is used as a simple momentum measure.
- On the chart timeframe, the MACD is calculated. Crossovers are then filtered with two conditions:
1.They must align with the higher-timeframe EMA trend.
2.They must occur beyond a small “zero band” threshold, with a minimum distance between MACD and signal lines.
- When both conditions are met, the script can plot BUY or SELL labels. ATR is used only to shift labels up or down for visibility.
Visuals and alerts
- Histogram bars show whether higher-timeframe EMA momentum is rising or falling.
- MACD main and signal lines are plotted with optional scaling.
- Dotted lines show the zero band region.
- Optional large BUY/SELL labels appear when conditions are confirmed on the previous bar.
- Alerts can be enabled for these signals; they trigger once per bar close.
Notes and limitations
- Higher-timeframe values are only confirmed once the higher-timeframe candle has closed.
- Scaling factors affect appearance only, not the logic.
- This is an open-source study intended as a learning and charting tool. It does not provide financial advice or guarantee performance.
What this script does
This indicator combines a higher-timeframe EMA trend filter with a MACD crossover on the chart’s timeframe. The goal is to make MACD signals more selective by checking whether they occur in the same direction as the broader trend.
How it works
- On the higher timeframe, two EMAs are calculated (short and long). Their difference is used as a simple momentum measure.
- On the chart timeframe, the MACD is calculated. Crossovers are then filtered with two conditions:
1.They must align with the higher-timeframe EMA trend.
2.They must occur beyond a small “zero band” threshold, with a minimum distance between MACD and signal lines.
- When both conditions are met, the script can plot BUY or SELL labels. ATR is used only to shift labels up or down for visibility.
Visuals and alerts
- Histogram bars show whether higher-timeframe EMA momentum is rising or falling.
- MACD main and signal lines are plotted with optional scaling.
- Dotted lines show the zero band region.
- Optional large BUY/SELL labels appear when conditions are confirmed on the previous bar.
- Alerts can be enabled for these signals; they trigger once per bar close.
Notes and limitations
- Higher-timeframe values are only confirmed once the higher-timeframe candle has closed.
- Scaling factors affect appearance only, not the logic.
- This is an open-source study intended as a learning and charting tool. It does not provide financial advice or guarantee performance.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
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.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
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.