Skip to content
All library documents

Detecting New Bars Efficiently in MetaTrader 5 Indicators

Article MQL5 articles

Summary

This tutorial introduces chart objects through the example of a candle counter and explains how an MQL5 indicator can detect when a new bar appears. It compares checking bar-time data with using the integer values supplied to the calculation handler, such as the current and previously calculated bar counts. The article emphasizes choosing a lightweight check because indicators receive calculation events when prices change, potentially very frequently on volatile symbols.

It also explains why a script may disappear after a timeframe change and why timer use in indicators can affect other applications on the chart. The examples build toward displaying information with chart objects, including the practical need to manage object properties separately from indicator settings. This is programming guidance rather than a trading signal or tested strategy; the counter is presented as an educational exercise, and the article cautions that poorly optimized chart applications can degrade platform performance.

Key ideas

  • Indicators may receive calculation events whenever the displayed symbol's price changes.
  • Comparing bar-count values can provide a simple way to detect a newly formed bar.
  • Keeping calculation handlers fast helps reduce delays for other applications on the chart.
  • Scripts can be removed when a chart timeframe changes, which limits their use for persistent displays.
  • Chart objects can display text, but their properties may need to be changed through a separate dialog.

Tags

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