Rollover Minute Learner
Not every broker charges overnight swap at server midnight. Some fire a minute or two either side of it, and MQL4 has no function that reports the exact minute directly - the only way to know for certain is to watch for it happening. This library polls the account balance on a regular cadence (a one-minute OnTimer is the natural fit for a live EA) and compares each reading to the previous one. When the balance has changed AND the count of open orders is unchanged and non-zero since the last poll, it credits that minute-of-day with one observation - the reasoning being that a genuine trade open or close would also move the open-order count, so an unexplained balance move with a stable order count is the signature of an overnight swap charge (or similar background account event) rather than trading activity. Over several nights of polling, the minute-of-day with the most credited observations is, empirically, the broker's actual rollover minute, and RolloverLearnerBestMinute() also reports what share of all observations landed on that minute as a simple confidence figure. Notes and limitations - The demo SIMULATES its "nights" synthetically, because an MQL4 script runs once and exits - it cannot literally sit and poll for two weeks in one execution. Wiring RolloverLearnerUpdate() into a real EA's OnTimer (as shown above) is what actually learns a live broker's minute over real elapsed time. - The detection heuristic (balance moved, open-order count unchanged and non-zero) can be fooled by anything else that silently moves the balance without changing the order count - a manual partial deposit adjustment some brokers apply, or a rebate/commission credit posted outside the order pool. A single broker-specific anomaly reads as one noisy off-minute observation; it takes several nights of consistent charges at the true minute to dominate the histogram. - Requires at least one order to stay open across the poll boundary to produce any credited observations at all - an account with zero open positions overnight has nothing to swap and nothing for this library to observe. - The 1440-entry per-minute counter array means this learns a single daily rollover minute, not a per-symbol or per-weekend-triple-swap distinction - Wednesday's typically larger triple-swap charge is still just one more observation at the same minute-of-day.
Script · MT5 · v1.0 · Free
About Rollover Minute Learner
Rollover Minute Learner is a script for MetaTrader 5. It has 3 settings, such as Simulated nights, True rollover minute and Jitter minutes. MQL source code included.
Files in the download: RolloverMinuteLearner.mq5.mqh, RolloverMinuteLearner.txt, RolloverMinuteLearnerDemo.ex5, RolloverMinuteLearnerDemo.mq5.
Settings
| Setting | Default | What it does |
|---|---|---|
| Simulated nights | 14 | How many synthetic nights to simulate |
| True rollover minute | 1439 | The synthetic "real" rollover minute-of-day (1439 = 23:59) the demo hides from the learner |
| Jitter minutes | 1 | Random +/- jitter applied to the true minute each simulated night |
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: MT5 Script · MQL5 Source Code