Skip to content
All library documents

Time-Based Expert Advisor with Scheduled Entries and Exits

Article MQL5 code base

Summary

This Expert Advisor opens either a long or short position at a configured hour and minute, then closes it at a separately configured time. Users can set trade volume, stop loss and take profit in points, allowable slippage, and a spread multiplier for stop distances. The EA adjusts invalid stop and target distances to the symbol’s minimum permitted level and reduces an oversized lot when necessary; it skips a signal if even the minimum lot cannot be opened.

A special behavior allows another position after a stop order closes a trade, provided the current bar has not ended and the opening-time signal remains active. The document reports tests on EURUSD hourly data from early 2017 to early 2018, comparing long and short modes. It says the long mode performed well and notes an additional optimization of opening and closing times, but gives no detailed statistics here. This limited test description does not establish robustness across markets, periods, or costs, and the scheduled timing rules alone do not explain why a directional position should have an edge.

Key ideas

  • The EA schedules a long or short entry and a time-based exit using hour and minute settings.
  • It supports point-based stops and targets, slippage limits, and adjustable trade volume.
  • The EA modifies invalid stop distances and oversized lots to meet symbol or account constraints.
  • A stopped position may be reopened within the same bar under the described conditions.
  • The document reports a limited EURUSD hourly test but provides insufficient statistics to establish robustness.

Tags

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