Bar Clock Predictor
Anything that wants to act "right as the next H1 bar opens" - a scheduled recalculation, a news-avoidance timer, a session-change alert - needs to know when that moment actually is, and a plain "add PeriodSeconds() until now" loop gets it wrong across the weekend: it happily predicts bar opens during the many hours the forex market is actually closed. BcpBarOpenAtOrBefore/BcpNextBarOpen align to the bar grid by flooring the timestamp to a multiple of the timeframe's period length in seconds - the same anchoring MetaTrader itself uses - so predictions never drift out of step with the terminal's own bars even over a long look-ahead. BcpPredictOpens walks candidate opens forward and, when skipWeekend is on, advances any candidate landing inside the weekly closed gap straight to the reopen moment rather than simply omitting it - the bar that actually reopens the week is the answer a caller wants, not a silent gap in the returned sequence. An optional holiday date list is skipped the same way. BcpNextOpensMulti runs the same prediction across several timeframes in one call, useful for a dashboard. This library is intentionally self-contained rather than depending on TradingCalendarEngine.mqh elsewhere in this catalogue - house style keeps every Library submission standalone. A caller who wants full CSV-driven holiday awareness can load a calendar with that library and pass the resulting dates into BcpPredictOpens's holidayDates parameter. Notes and limitations - MQL4 does not allow a default value on an array-reference parameter, so the full BcpPredictOpens/BcpNextOpensMulti forms require every argument explicitly, including an empty holiday array with holidayCount=0 when no holiday list applies - use the *Simple overloads for the common case instead of fighting that restriction at every call site. - The weekly gap model (close day/hour, open day/hour) defaults to Friday 22:00 / Sunday 22:00 server time, a common convention, but real broker servers vary - check your own broker's actual weekly close/open times before relying on the defaults for anything time-critical. - Predictions are computed from the given "from" timestamp only; this header does not read the chart's actual bar history, so it will predict an open even for a timeframe/symbol combination with no real data, and it does not detect broker-specific holiday closures unless the caller supplies them via holidayDates.
Script · MT5 · v1.0 · Free
About Bar Clock Predictor
Bar Clock Predictor is a script for MetaTrader 5. It has 1 setting, such as Opens to predict. MQL source code included.
Files in the download: BarClockPredictor.mq5.mqh, BarClockPredictor.txt, BarClockPredictorDemo.ex5, BarClockPredictorDemo.mq5.
Settings
| Setting | Default | What it does |
|---|---|---|
| Opens to predict | 6 | How many upcoming bar opens to list |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Alerts · Trading Sessions · News Trading · MT5 Script · MQL5 Source Code