Skip to content
All library documents

Lazy-Loading Indicator Handles with a Reference-Counted MQL5 Cache

Article MQL5 articles

Summary

The article describes a resource manager for Expert Advisors that creates indicator handles only when requested and reuses them for matching requests. Cache identity combines symbol, timeframe, indicator type, and serialized parameters, so distinct configurations receive separate handles. Reference counts track active users: acquisitions increment the count, releases decrement it, and an entry is removed with the terminal handle when the count reaches zero.

A centralized flush releases remaining handles at shutdown. The article also outlines session statistics for cache hits, misses, and estimated memory, plus a dashboard and demonstration EA. Its motivating example is a multi-symbol, multi-timeframe strategy whose full indicator set could create many handles at startup, while only some may be used at once. The proposed design aims to reduce initialization work and resource use while simplifying cleanup. These are implementation claims rather than reported benchmarks; memory is estimated, and the text does not provide comparative measurements of latency or resource savings.

Key ideas

  • A composite key should include every input that changes an indicator instance.
  • Lazy creation defers setup until a handle is requested and permits reuse of existing instances.
  • Reference counting lets multiple consumers share a handle and releases it when its final consumer is done.
  • A central shutdown flush can release all remaining handles.
  • Hit, miss, and estimated-memory statistics can help monitor cache behavior.

Tags

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