Skip to content
All library documents

Synchronizing OHLCV Time Series for Portfolio Trading

Article MQL5 articles

Summary

The document presents a method for aligning bar data across instruments before portfolio analysis or trading. It uses one instrument’s bar opening times as a reference, matches other symbols to those timestamps, fills missing bars, and trims excess history so that all resulting arrays have equal length. Missing intervals can remain empty or be filled with the prior bar’s closing price and zero volume. The design also accounts for arrays stored in either chronological direction and for new bars arriving asynchronously across instruments.

The article proposes time-keyed sorted associative maps to store bars and describes a manager class for loading, synchronizing, and returning the data. Examples include multi-symbol charts and a portfolio-value indicator. It recommends choosing a liquid reference symbol and explains the tradeoff between waiting for every instrument’s new bar and recalculating as each arrives. Interpolated prices can simplify alignment but are synthetic observations; asynchronous updates can revise signals, and a poor reference choice can introduce artifacts. Correct synchronization supports portfolio calculations but does not itself validate a trading strategy.

Key ideas

  • Portfolio calculations require bars from different instruments to share matching timestamps.
  • Missing bars can be represented as empty observations or filled using the previous close with zero volume.
  • A reference instrument determines the shared timeline, and other series are aligned and trimmed to it.
  • Sorted time-keyed maps provide a way to organize bars and insert or retrieve them by opening time.
  • Waiting for all symbols reduces premature updates, while recalculating as bars arrive can produce earlier but changing signals.

Tags

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