Skip to content
All library documents

Moving Average and Envelope Breakouts with Equity-Based Cycle Exits

Article MQL5 code base

Summary

This Expert Advisor description combines a moving-average trend filter with two envelope breakout modules. Each module checks the previous completed candle and current candle open: both must sit above the relevant line for a buy, or below it for a sell. The third cycle duplicates the second cycle's signal logic while using separate settings. Entry availability is also toggled between buy and sell cycles, creating a loosely alternating reversal or grid structure.

Positions are managed by cycle using aggregate floating profit, swap, and commission. When a cycle begins, the EA records account equity and sets monetary profit and loss thresholds as percentages of that baseline; reaching either threshold closes the cycle's positions. The text identifies a calculation error in one buy path that makes its target ten times smaller than intended. It gives no backtest or live trading evidence, and equity-based exits, per-cycle aggregation, and the unusual alternating state logic all require implementation and risk review.

Key ideas

  • The first entry module follows the moving-average direction, while envelope modules seek breakouts.
  • Signals require both the previous close and current open to lie beyond the relevant indicator line.
  • Cycle exits use aggregate floating profit, swap, and commission relative to starting equity.
  • Buy and sell cycle flags alternate which side can act after an execution.
  • One buy-side threshold calculation is described as using a divisor that makes the target ten times smaller.

Tags

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