Skip to content
All library documents

Implementing FIFO and Circular Queues for Efficient MQL5 Data Handling

Article MQL5 articles

Summary

This programming tutorial introduces queue behavior through MQL5 examples, connecting data organization with the processing needs of indicators and Expert Advisors. A FIFO queue appends incoming values and removes the oldest item when it is read. The article explains how an array can implement this behavior by taking the value at the first index and shifting the remaining elements forward. It then introduces a circular queue, which uses index counters to reuse a bounded storage area instead of repeatedly shifting values.

The examples are intended to clarify how insertion and retrieval rules determine a structure’s behavior and suitability. A circular queue is suggested for cases such as maintaining a fixed window of recent prices for a moving average, where retaining older observations beyond the window is unnecessary. This can reduce data movement and simplify maintenance. The article is instructional rather than a benchmark: it offers no measured speed comparisons, and the best structure depends on the application’s data access and update requirements.

Key ideas

  • A FIFO queue returns values in the order they were inserted.
  • An array-based FIFO implementation can remove the first element and shift remaining values toward the start.
  • A circular queue uses moving indices to reuse a bounded buffer without shifting every stored item.
  • A fixed-size recent-price window can be represented with a circular queue when older values are no longer needed.
  • The article explains structure behavior but reports no performance benchmark.

Tags

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