Skip to content
All library documents

A Modular Expert Advisor Template for Signals, Stops, and Position Sizing

Article MQL5 articles

Summary

This article presents a modular Expert Advisor framework with configurable trade size, take-profit, stop-loss, trailing stop, slippage, and entry-condition switches. It explains how an EA can initialize parameters, check for a signal when no order is open, and manage an existing position. The sample combines stochastic crossover conditions with a direction filter based on recent fractals, then shows order-opening and closing helper functions.

The template also illustrates adjusting stops to broker minimum distances, capping calculated lots, moving stops as prices advance, closing after a specified profit retracement, and optionally exiting when an opposite signal appears. The author recommends using stop-losses and organizing repeated actions into functions. These are implementation examples, not a validated strategy: the article provides no backtest evidence, and its code includes legacy platform conventions and assumptions about instrument pricing and lot calculation. Readers would need to check broker constraints and verify the logic before use.

Key ideas

  • The framework exposes trade size, stop levels, slippage, and entry conditions as configurable parameters.
  • Entry signals combine stochastic conditions with a fractal-based direction check.
  • Position management includes optional stop-loss, take-profit, trailing-stop, and opposite-signal exits.
  • The lot-sizing example applies user and broker maximum limits to a balance-based calculation.
  • The template is not accompanied by evidence that its sample signals are profitable.

Tags

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