Skip to content
All library documents

Signal-Based Averaging and Trade Management in an MQL4 Expert Advisor

Article MQL5 code base

Summary

This educational MQL4 expert advisor uses a moving-average crossover as an example entry signal and demonstrates how orders can be managed across currency pairs. Each order receives a distinct magic number, allowing the program to identify and manage its trades separately. Its order-management routine can open new positions or add layers based on a signal, or add layers based only on a minimum price distance.

The document also describes setting a take-profit level for one position or several orders at a shared price, plus applying a trailing stop to the initial position. It provides no performance results, risk controls, or detailed rules for sizing and limiting added positions. The example is presented as a way to learn MQL4 programming, so it should not be treated as evidence that signal-based averaging is profitable or safe.

Key ideas

  • The moving-average crossover serves as an example entry signal for the expert advisor.
  • Each order receives a distinct magic number to support trade management by pair.
  • New orders and averaging layers can be triggered by a signal or by minimum price spacing alone.
  • Take-profit settings can apply to one position or multiple orders at a shared price.
  • The trailing stop described applies to the initial position.

Tags

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