Skip to content
All library documents

Timer-Based Pauses for MQL4 Expert Advisors

Article MQL5 articles

Summary

This article compares MQL4’s blocking Sleep function with timer-based pauses for Expert Advisors and indicators. The alternative records a pause’s expiry time and checks it during later code execution, allowing unrelated work to continue while waiting. It describes both a loop-based pattern for scripts and a tick-driven pattern for EAs or indicators, then outlines a timer library with wait counters and stopwatches for managing multiple intervals.

The examples demonstrate how the two approaches affect program flow and include use cases such as timed order updates and minimum intervals between order submissions. Timer-based waiting avoids blocking execution, but a delayed action runs only when a later tick arrives and may be missed if ticks stop; its resolution is also coarser than Sleep. Sleep resumes execution as soon as its interval ends but blocks the program and is unavailable to custom indicators. The author frames the choice as dependent on the project’s timing and responsiveness needs.

Key ideas

  • Sleep blocks program execution for the requested interval and cannot be called from custom indicators.
  • A timer can store an expiry time so an EA or indicator continues running other work while waiting.
  • Tick-driven timer checks may execute late or fail to run if no later tick arrives.
  • A timer library can manage multiple wait intervals and elapsed-time counters.
  • Choose between blocking and timer-based pauses according to the program’s timing requirements.

Tags

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