Detecting a New Chart Bar by Comparing Historical Bar Counts
Summary
This short MetaTrader programming note shows how an expert advisor can detect the arrival of a new chart bar by comparing the current bar count with the count saved during initialization. It stores the baseline in an integer, refreshes a second count on each tick with the chart’s bar-history function, and treats an increase as a new bar. The example then updates the saved count and uses an alert and chart comment to display the counts for basic checking.
The method is presented as lighter and faster than checking bar time, but the document supplies no benchmark or comparative evidence. It is a simple event-detection pattern rather than a trading strategy. It depends on the bar count increasing, so the example does not discuss history refreshes, chart changes, or other circumstances that could affect the count; those cases may need handling in a production expert advisor.
Key ideas
- Save the chart’s bar count during expert initialization.
- Refresh the count on each tick and detect a new bar when it rises above the saved value.
- Update the saved count after detection to avoid repeatedly treating the same bar as new.
- Alerts and chart comments can help verify the behavior while debugging.
- The claimed speed advantage over time-based checks is not supported with benchmark data.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.