Skip to content
All library documents

Moving Average Swing EA with Position Scaling

Article MQL5 code base

Summary

This document describes a MetaTrader expert advisor that uses a moving average as a reference for opening and adding positions. It opens buys when price is above the average by a configured distance and sells when price moves below it by that distance. Further trades are triggered when price moves beyond the highest or lowest existing position of a given side by the same distance, creating a swing-style sequence.

Position size can be entered directly or calculated as a share of free margin, and a multiplier can increase size across a series. The EA also supports take-profit settings and adjusts the distance threshold when the overall position group is profitable. The document outlines the CMoving class functions for indicator values, position tracking, order handling, and average take-profit management. It identifies GBPUSD on an hourly chart with real-tick testing, but gives no performance results or detailed risk controls; the described scaling approach may build exposure as positions accumulate.

Key ideas

  • The EA uses distance from a moving average to trigger initial buy and sell positions.
  • It adds positions when price moves beyond the highest or lowest existing position by the configured distance.
  • Position sizing can use fixed volume or a percentage of free margin, with an optional multiplier across trades.
  • The implementation tracks positions by direction and can manage a shared take-profit level.
  • The document names an hourly GBPUSD setup but provides no evidence of profitability.

Tags

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