Skip to content
All library documents

Reducing Duplicate Bar-Building Logic in a Forex Replay Simulator

Article MQL5 articles

Summary

This installment of a market replay series refactors tick-to-bar construction so the same one-minute bar-building logic can serve both data loading and replay playback. The shared routine reports when a new bar begins and updates price and volume fields, while the replay routine uses its result to add ticks and update the simulated chart. The article also describes generating bid-based forex ticks from bar data, setting custom-symbol properties, and varying simulated spread under specified conditions.

The author motivates the changes with bugs and maintenance difficulties caused by duplicated code, and explains the control flow through code examples. The system is intended for forex simulation; the article explicitly cautions that its simulation approach is not suitable for exchange-traded assets, where it is disabled. The discussion is an implementation account rather than a quantitative comparison: it reports that the approach worked reasonably in the author's forex use, but provides no measured fidelity assessment or trading results. Simplifications remain, including ignoring certain one-sided bid or ask movements in real tick data.

Key ideas

  • A shared tick-to-bar routine can reduce inconsistent behavior between data loading and replay playback.
  • The conversion routine tracks one-minute OHLC values and tick or real volume while signaling bar boundaries.
  • Replay code can use the same conversion result to update both simulated ticks and chart rates.
  • The described bid-based data simulation is intended for forex and is disabled for exchange-traded assets.
  • The author reports practical use but provides no quantitative measure of simulation fidelity.

Tags

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