Skip to content
All library documents

Using Tick Counters to Repeat or Pause Expert Advisor Actions

Article MQL5 code base

Summary

This programming note explains two counter patterns for an Expert Advisor that runs on each market tick. The first increments a counter on every tick, executes a chosen code block when it reaches a configurable limit, and resets it so the block can run again after another cycle. The second alternates between a specified number of active ticks and a specified number of waiting ticks, then resets both counters to repeat the cycle. The limits can be exposed as inputs, making them adjustable or available for optimization.

The examples show the counters declared as global variables and updated inside the tick handler. A final variation describes counting to a limit and then stopping until another part of the program resets the counter. These are execution-control patterns rather than trading signals: the note gives no entry or exit logic, market data analysis, backtest, or trading results. Their timing is measured in ticks, so they do not represent fixed elapsed time; activity depends on how frequently ticks arrive.

Key ideas

  • A tick counter can trigger a code block after a configurable number of ticks and then reset for another cycle.
  • A second counter can alternate active and waiting phases before restarting the sequence.
  • Global counter variables allow other parts of an Expert Advisor to reset or control the cycle.
  • Tick-based limits measure market events rather than fixed durations.
  • The examples explain program flow and do not provide a trading strategy or performance evidence.

Tags

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