Skip to content
All library documents

Calculating MACD with a Ring Buffer in MetaTrader

Article MQL5 code base

Summary

The document explains a MetaTrader class for calculating and accessing MACD values through a ring buffer. Initialization options cover fast, slow, and signal periods; their moving-average methods; buffer capacity; and array indexing orientation. The class can process a full input array or update from individual values, and exposes the MACD main line, signal line, configuration details, and required history length. An example shows copying calculated values from the buffer into indicator output arrays.

Two sample programs illustrate array-based and value-based calculations, including calculating another MACD from an existing indicator buffer. Ring-buffer indexing is described as matching time-series indexing, which matters when mapping values to chart bars. The text is software documentation, not a trading strategy: it gives no entry or exit rules, market tests, or performance results. Implementation also depends on companion ring-buffer and moving-average classes being available in the expected library folder.

Key ideas

  • The class calculates MACD using fast, slow, and signal moving-average settings stored in a ring buffer.
  • It supports processing a full array or updating the calculation one value at a time.
  • The buffer exposes the main and signal lines as well as configuration and history information.
  • Its indexing is designed to correspond to time-series order when values are copied to chart buffers.
  • The examples demonstrate implementation use but provide no evidence of trading performance.

Tags

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