Skip to content
All library documents

MACD Sample Expert Advisor with Trailing Stops

Article MQL5 articles

Summary

This tutorial describes a single-position MQL4 Expert Advisor built around MACD crossovers, with an exponential moving average used as a directional filter. Long entries require MACD to be below zero and turning upward across its signal line; short entries use the converse condition above zero. The rules include a minimum MACD movement threshold to screen out small fluctuations. Positions can close at a take-profit level, through a trailing stop, or when MACD gives the specified exit crossover.

The article walks through external parameters, initial data checks, indicator value storage, account margin checks, order placement, and management of open positions. It is primarily a programming example rather than a strategy evaluation. It specifies illustrative parameter settings but supplies no performance study or evidence that the crossover rules are profitable. The example manages market positions rather than pending orders, and its risk controls and settings would need adaptation and testing before practical use.

Key ideas

  • The sample enters long or short positions on MACD and signal-line crossover conditions, filtered by MACD's position relative to zero.
  • An EMA direction check and a minimum MACD movement threshold filter entry signals.
  • Take-profit, trailing-stop, and opposing MACD crossover conditions provide position exits.
  • The tutorial demonstrates parameter checks, margin checks, order placement, and open-position management in MQL4.
  • The article provides implementation guidance but no evidence of strategy profitability.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.