Code Library / MACD

Pine Script MACD+EMA Filter

MACD filtered by 200 EMA trend direction.

Language: Pine Script · Category: MACD · Tags: MACD, EMA filter, trend filter, Pine Script, strategy

Source code

//@version=5
strategy("MACD+EMA",overlay=true)
ema=ta.ema(close,200)
[m,s,h]=ta.macd(close,12,26,9)
if ta.crossover(m,s) and close>ema
    strategy.entry("Long",strategy.long)
if ta.crossunder(m,s) and close<ema
    strategy.entry("Short",strategy.short)
plot(ema,"EMA200",color.yellow,2)

How to use this snippet

This is a building block, not a finished trading system. Paste it into your own Pine Script project, compile it, and test it on a demo account with your broker's real spreads before relying on it. You can convert it to MQL4 or MQL5 with the Pine Script converter.

Related snippets