Skip to content
All library documents

Moving Average Expert Advisor with Separate Entry and Exit Signals

Article MQL5 code base

Summary

This document describes an Expert Advisor that extends a standard moving-average example by using separate moving-average settings for four actions: opening and closing buy positions, and opening and closing sell positions. Each signal can have its own averaging period, shift, method, and applied price. Inputs also let users disable either trade direction and control position sizing through a maximum-risk setting and a factor that reduces exposure after losses.

An optional rule compares a prospective trade price with the price of the most recently closed trade: buys must be at or below that price, while sells must be at or above it. The EA tracks the last exit through trade transactions and holds no more than one position at a time. The document gives an EURUSD 15-minute example period and suggests a staged optimization process, first searching parameters with simplified tick data and then checking a selected result using more detailed tick data. It provides no performance results, and the suggested optimization ranges are starting points rather than evidence of a robust strategy.

Key ideas

  • Separate moving-average configurations can govern each of four entry and exit signals.
  • Buy and sell trading can be enabled or disabled independently.
  • An optional last-exit price filter constrains the price of the next position.
  • The EA maintains at most one open position and supports netting and hedging accounts.
  • The optimization workflow uses a faster initial search followed by a more detailed single test.

Tags

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