Skip to content
All library documents

Detecting New Bars Across Symbols and Timeframes in an Expert Advisor

Article MQL5 code base

Summary

This document explains how a multicurrency Expert Advisor can detect when a new bar begins on instruments other than the chart symbol. Because OnTick is driven by ticks on the chart instrument, the EA needs to track bar start times for each symbol and timeframe it monitors. The described library stores those times and provides functions to update its state and check for a new bar.

The usage pattern is to update tracked times at the start of each OnTick call, then query whether a new bar has appeared for selected symbol and timeframe pairs. The example checks several currency pairs at 15-minute and hourly intervals, and shows that a detected event can still be reported again later in the same tick if the update function is not called again. This is implementation guidance rather than a trading signal or performance study. It does not discuss data availability, missed ticks, or how to handle instruments that have no recent quotes, so those behaviors would need separate consideration.

Key ideas

  • A multicurrency EA may need to detect bars for instruments other than the chart instrument.
  • The library tracks each monitored symbol and timeframe using the start time of its current bar.
  • Call the update function at the beginning of OnTick before checking for new-bar events.
  • The example demonstrates checks across multiple instruments and timeframes, including repeated checks during one tick.

Tags

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