Detecting New Minute Bars with Time Checks and a One-Shot Flag
Summary
The document describes a MetaTrader 5 approach for detecting the close of a one-minute candle. It reads the timestamp of the prior bar, adds 60 seconds to estimate the current bar’s closing time, and compares that value with the current time. When they match, a Boolean flag allows the detection block to run once; after the time passes the estimated close, the flag resets for the next bar.
The example uses a sound and chart comment to inspect the timing calculations, and notes that these checks can be removed. Its usefulness is limited by the exact equality comparison: if the tick handler does not run at the calculated second, the detection may be missed. The code is specific to one-minute bars and uses tick events for checking, despite also setting a timer whose handler is empty. It is an implementation example rather than a tested evaluation of robustness across feeds or timeframes.
Key ideas
- The example estimates a candle close by adding one minute to the previous bar timestamp.
- A Boolean flag prevents repeated execution during the same detected close.
- The flag resets after current time exceeds the estimated closing time.
- An exact timestamp match can miss detection if no tick arrives at that moment.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.