Skip to content
All library documents

Two Moving Averages for Entries, Exits, and Forward Testing

Article MQL5 code base

Summary

The described Expert Advisor uses the direction of a slow moving average to open positions and a fast moving average to close them. It buys when the slow average rises and exits when the fast average falls; it sells when the slow average falls and exits when the fast average rises. The method relies on changes in each average’s direction rather than crossings between the averages. A stop loss and optional trailing stop provide additional position controls.

The document reports an optimization over July 2007 to July 2008, followed by a forward test beginning in July 2008 and running into October, which it describes as profitable. That is a brief, single-period result, with no instrument, transaction costs, drawdown, or detailed performance statistics provided. The author notes that optimization results alone can be misleading and recommends testing on data not used for fitting. The system operates on new bars, so the stated backtest mode uses completed-bar opening prices; its suggested parameter ranges do not establish that optimized settings will generalize.

Key ideas

  • The slow moving average’s direction determines whether the system opens a long or short position.
  • The fast moving average’s direction determines when an open position is closed.
  • A stop loss is optimized, while the trailing stop can be disabled or used as a backup safety measure.
  • The document presents a short forward test after optimization as evidence, but gives too little detail to assess robustness.

Tags

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