News Time Auto Flat
A news guard is only as good as its data, and the usual failure mode is silent: the calendar file is missing, or empty, or stale, and the guard reports "clear" because it has nothing to say otherwise, and a trader or an automated strategy proceeds straight through a Non-Farm Payrolls print thinking it is protected. This EA treats that as the worst possible outcome and refuses to allow it - a missing or empty calendar produces a loud "no protection is active" state on the chart and in the log, every relevant check, rather than a quiet, reassuring "clear." The calendar itself is a plain CSV with a header row and four columns: time_iso, currency, impact, title. That shape is deliberately simple enough that a companion export script, reading from any calendar API or a scraped page, could produce it without a full CSV parser - the one constraint this buys is that a title containing a comma will misalign the row, since there is no quoting. time_iso is parsed as literal wall-clock digits and compared directly against the terminal's server time - there is no time zone conversion applied anywhere. Export the calendar in your broker's server time, the same time every other guard in this catalogue already operates in, not UTC and not your own local time, or the block windows will land at the wrong moment. Only HIGH-impact rows on a watched currency are kept after the file loads, which keeps the per-tick scan small regardless of how large the source calendar is. The file is re-read on a timer (InpReloadSeconds) rather than every tick, since a calendar does not change tick to tick, but the window-membership check against the current time runs every tick so the block, and the optional flatten, fire on time rather than waiting for a new bar. Notes and limitations - This EA does not fetch or generate calendar data itself. It only reads a file that something else - a script, a manual export, a scheduled task - has to keep current. An out-of-date file produces stale block windows, not wrong ones; an event two weeks old sitting in the file simply never matches "now" again. - Only HIGH impact rows are honoured. Medium and low impact events, however labelled in the source file, are loaded and counted but never trigger a block. - A title containing a comma will misalign that row's columns, since the parser does not support quoted CSV fields. Keep titles comma-free at export time. - time_iso is compared to server time with no time zone conversion. A calendar exported in UTC or local time against a broker running a different server offset will block the wrong minutes. - Like Trading Hours Restrictor in this catalogue, "blocking" here is reporting only - this EA does not intercept orders placed by another EA or by hand. InpFlattenDuringNews is the one input that actually acts, and only by closing, never by placing anything. - If AutoTrading is off when InpFlattenDuringNews needs to fire, the EA cannot flatten the account. It logs and comments this plainly. - The sandbox here is this terminal's own Files\ folder (MQL4\Files\ or MQL5\Files\), not the shared Common\Files\ location used by the Local Trade Copier trio elsewhere in this catalogue - a calendar file has no reason to be visible to another terminal on the same PC.
Expert advisor · MT5 · v1.0 · Free
About News Time Auto Flat
News Time Auto Flat is an expert advisor (trading robot) for MetaTrader 5. It has a news filter. It has 10 settings, such as Calendar file name, Watched currencies and Minutes before. MQL source code included.
Files in the download: NewsAutoFlat.ex5, NewsAutoFlat.mq5, NewsAutoFlat.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Calendar file name | NewsCalendar.csv | Calendar file, in MQL5\Files\ (the sandbox) |
| Watched currencies | USD,EUR | Comma-separated currency codes to watch |
| Minutes before | 30 | Minutes to block before a HIGH-impact event |
| Minutes after | 30 | Minutes to block after a HIGH-impact event |
| Flatten during news | false | Close every open position when a block window begins |
| Reload seconds | 300 | How often the calendar file is re-read |
| Slippage pips | 3 | Slippage tolerance when flattening, in pips |
| Max retries | 5 | Close attempts per position before giving up |
| Retry wait ms | 500 | Pause between retry attempts, milliseconds |
| Status log seconds | 300 | How often the status line repeats while blocked |
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 → Experts.
- 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 expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: News Trading · MT5 Expert Advisor · MQL5 Source Code