<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Source+Code+Pro:wght@400;600;700&family=Source+Sans+3:wght@400;500;600;700&display=swap">

MACD with a zero-line filter

The usual crossing of MACD and its signal line, but a trade opens only on the side of the zero line where the trend is: above zero for buys, below it for sells. Counter-trend signals are skipped.

  • MACD
  • Intermediate

Choose a platform: MT5 shows the chart and Inputs screenshots from MetaTrader 5, MT4 shows the chart with entries and the Inputs screenshot from MetaTrader 4.

How the robot trades

When it buys

MACD crosses its signal line upward above zero.

When it sells

MACD crosses its signal line downward below zero.

When it exits

The opposite crossing of MACD and its signal line.

Screenshot 1 of 5

EURUSD, H4. The robot indicators and the deals from the MT5 strategy tester: arrows are entries, crosses are exits, and the lines join an entry to its exit.

The conditions as constructor blocks

Open a buy

(MACD_Main ≥ MACD_Signal)
AND
(MACD_Main_Prev < MACD_Signal_Prev)
AND
(MACD_Main > MACD_Zero (0))

Open a sell

(MACD_Main ≤ MACD_Signal)
AND
(MACD_Main_Prev > MACD_Signal_Prev)
AND
(MACD_Main < MACD_Zero (0))

Close a buy

(MACD_Main ≤ MACD_Signal)
AND
(MACD_Main_Prev > MACD_Signal_Prev)

Close a sell

(MACD_Main ≥ MACD_Signal)
AND
(MACD_Main_Prev < MACD_Signal_Prev)

Inputs

These inputs appear in the expert advisor settings in MetaTrader 5 or MetaTrader 4, and they are what the strategy tester goes through when it optimises the robot.

InputDefaultWhat it means
InpMACD_Main_fastEma12Fast MACD period: how many recent candles the fast line averages.
InpMACD_Main_slowEma26Slow MACD period: the larger it is, the calmer the line and the rarer the signals.
InpMACD_Main_signal9Signal line period: the smoothing of the main MACD line.
MACD_Zero0The zero level: above it the trend counts as upward, below it as downward. Zero by default.
The inputs dialog of the MACD with a zero-line filter expert advisor in MetaTrader 5. Screenshot 1 of 2The inputs dialog of the MACD with a zero-line filter expert advisor in MetaTrader 5. Screenshot 2 of 2
This is how the expert's inputs look in MetaTrader 5

How to tune the robot to your style

  • Change the 12/26/9 periods and watch how the number of signals changes.
  • Put a small threshold instead of zero — signals right at the zero line will stop opening trades.
  • Compare it with the MACD and signal line robot: the same entry, but without the trend filter.

You can do all of this in the constructor without signing up. To save your changes and come back to them later, you need an account.

Risks

How a strategy behaved in the past does not predict its future results. Check the robot in the strategy tester and on a demo account first, and only then decide whether to trade it with real money. This robot is an example to adapt to your instrument, timeframe and risk rules.

Similar robots