MID NewsGuard
- Utilità
- Versione: 3.13
- Attivazioni: 5
Short Description
MID_NewsGuard_EA is a DLL-free MT5 Expert Advisor that reads the native MetaTrader 5 economic calendar, displays upcoming high/medium/low-impact news on your chart, and automatically protects your trading during configurable news windows by closing open positions, deleting pending orders, and blocking new entries. Fully MQL5 Market compliant — no DLL imports.
1. What It Is
MID_NewsGuard_EA is a news-aware risk-management utility for MetaTrader 5. It does not generate signals or place trades. It is a companion EA that runs alongside your existing strategy and shields it from volatility spikes around scheduled economic releases.
Three pillars:
-
Native MT5 calendar — reads CalendarValueHistory / CalendarEventById directly from MetaQuotes' servers. No scraping, no HTTP, no DLL. Times are already in broker server time.
-
Visual awareness — top-left news panel with countdowns, vertical lines per event, colored guard-zone rectangles, bottom-right parameter dashboard.
-
Automated protection — during a user-defined window around each selected news event, closes open positions, deletes pending orders, and blocks new entries, filtered by magic number and/or symbol.
Every action is logged and optionally alerted.
2. The Problem It Solves
Scheduled releases (NFP, CPI, FOMC, ECB, BoE, GDP, PMIs, holidays) produce spread explosions (3× to 20×), slippage, stop-level widening, gap risk, liquidity holes, and requote storms. For any EA or manual trader with a strict risk model, this can mean losses far beyond the intended stop-loss, grid systems filled at every level at once, and drawdowns that violate prop-firm rules.
Many prop firms now forbid holding or opening trades within minutes of high-impact news. Violations can invalidate a payout. Even where allowed, spread/slippage cost often makes such trades negative-expectancy.
Why existing solutions fall short: manual watching doesn't scale; calendar websites drift from broker time; DLL-based or scraped news EAs are fragile and forbidden on the Market; setting the Algo button OFF kills every EA at once.
What this EA brings: the same calendar your broker uses (perfect time alignment), impact-level selection, currency/symbol filtering, per-magic protection, logged close/delete/block, audio alerts, and full MQL5 Market compliance.
3. Features
Calendar ingestion — per-currency calls, refresh every InpRefreshMinutes (min 60 s on failure), last known list preserved on network error, server-time aligned.
Two independent impact filters — InpShow* controls what appears on chart; InpGuard* controls what triggers protection.
Currency & symbol filtering — InpCurrencies (CSV, empty = all), InpSymbolMatch (only trigger if news currency matches position symbol), InpOnlyChartSymbol (only current chart's symbol).
Guard window — [T − InpMinutesBefore, T + InpMinutesAfter] per event; overlapping windows are unioned per symbol.
Enforcement (from OnTick , OnTimer , OnTradeTransaction ):
-
Positions opened before window → close if InpClosePositions .
-
Positions opened inside window → close if InpBlockNew .
-
Pending orders opened before → delete if InpDeletePending ; inside → delete if InpBlockNew .
-
All filtered by InpMagics (empty = all magics), symbol filters, and union window.
Alerts — pre-news popup + sound InpAlertBeforeMin before each event (deduplicated); optional post-action alerts on every close/delete.
Visual layer — top-left panel (title, refresh status, color-coded guard status, per-news countdown + impact icon + currency + title + optional A/F/P values), next-day news in smaller font, vertical lines colored by impact, guard-zone rectangles (red = active, orange = upcoming), bottom-right dashboard, auto theme detection (dark/light).
Robustness — background created once and only updated (fixes MT5 z-order bug), orphan labels cleaned, counters (G_ClosedCount , G_DeletedCount ) shown in status, all in-memory, no files, no globals, no timer drift.
4. Who It's For
Suitable for: EA portfolio operators wanting a single news-guard layer by magic; discretionary traders wanting visual calendar + manual-trade protection; prop-firm traders needing rule compliance with logged evidence; grid/martingale/averaging EAs (most vulnerable to spikes); scalpers avoiding noisy 5–10 min windows; demo users evaluating news exposure without risk.
Not designed for: generating trades; replacing the global Algo toggle (v3.13 cannot toggle the terminal button — DLL-free constraint); fundamental forecasting (acts on scheduled time, not content); backtesting (Strategy Tester has no calendar; the EA correctly reports unavailable and does nothing).
5. Architectural Choices
Native MT5 calendar — same source as broker → no time-zone drift, no scraping breakage, official API, filterable at source.
Per-magic and per-symbol filtering — real portfolios mix strategies and symbols; a blanket close-all guard is too blunt. This EA can protect all of a specific EA's trades, only the current symbol, only symbols containing the news currency, or any combination.
Close-before / block-during — real strategy EAs cannot be paused externally without DLL, and the Algo button is global. Closing and blocking is the only mechanism in pure MQL5 that gives a portfolio-wide news guard, and it is auditable.
DLL-free — the Market forbids DLLs. v3.12 used user32.dll (PostMessageW + GetAncestor ) to click the Algo button: Windows-only, fragile, blockable, non-compliant. v3.13 removes it and replaces the global toggle with per-trade protection — a deliberate trade-off: loses ability to kill other EAs, gains portability and compliance.
Close and block — close handles existing exposure; block handles new exposure during release (including EAs that ignore the calendar and triggered pending orders). Doing only one leaves a hole.
6. Example Scenarios
A — EURUSD grid EA (magic 20240001 ): with InpMagics="20240001" , high-impact, −10/+20 min, close + block → at 14:20 the EA closes all grid positions and deletes pending limits; any leg opened at 14:31 is closed; normal activity resumes at 14:50.
B — Multi-EA portfolio (100,200,300 on EURUSD/GBPUSD/USDJPY): InpSymbolMatch=true , InpGuardHigh=true → US news protects GBPUSD and USDJPY but not EURUSD; EUR news protects EURUSD only.
C — Prop-firm compliance (±2 min on high impact): every close/delete logged with ticket and time; the log is your compliance evidence.
D — Demo observation: InpEnableGuard=false → panel + alerts only, no intervention, perfect to learn when your strategy is exposed.
7. Limitations
-
No global Algo toggle (v3.13): cannot stop EAs whose magics aren't listed. Freeze everything by listing all magics or using the terminal button.
-
Scheduled news only: does not react to surprise headlines or geopolitical shocks.
-
Requires MT5 calendar online: on server failure, uses last cached list and logs an error.
-
Broker-dependent: PositionClose may fail with 10018 /10030 if stops widen or fill mode rejected; retries every tick but cannot force a close the server refuses.
-
No Strategy Tester support: no calendar in tester; use demo.
-
Dangerous combo: InpMagics empty + InpSymbolMatch=false + InpOnlyChartSymbol=false = close ALL positions during news.
-
Multiple instances each fire their own alerts (by design).
8. Positioning
| Approach | Time accuracy | DLL-free | Market-compliant | Per-magic | Per-symbol |
|---|---|---|---|---|---|
| Manual watching | Good | N/A | N/A | No | No |
| News websites | ± minutes | N/A | N/A | No | No |
| DLL-based EAs | Good | ❌ | ❌ | Sometimes | Sometimes |
| Web-scraping EAs | ± minutes | ✅ | Sometimes | Rarely | Rarely |
| Terminal Algo button | Instant | ✅ | ✅ | No (global) | No (global) |
| MID_NewsGuard v3.13 | Exact | ✅ | ✅ | ✅ | ✅ |
9. Technical Snapshot
| Attribute | Value |
|---|---|
| Platform | MetaTrader 5 (build 3000+) |
| Language | MQL5 |
| DLL imports | None |
| External deps | Native MT5 economic calendar |
| Files / globals written | None |
| Timer | 1 s (EventSetTimer(1) ) |
| Calendar refresh | Every InpRefreshMinutes (min 60 s on failure) |
| Compilation | 0 errors, 0 warnings |
| Chart objects | OBJ_VLINE , OBJ_RECTANGLE , OBJ_RECTANGLE_LABEL , OBJ_LABEL (prefix MIDGuard_ ) |
| Cleanup | ObjectsDeleteAll(0, G_PREFIX) in OnDeinit |
10. Summary
MID_NewsGuard_EA v3.13 is a purpose-built, DLL-free, Market-compliant news guard for MT5. It combines the accuracy of the native MT5 calendar, the clarity of an on-chart news dashboard, and the safety of automated close/delete/block during high-impact events. It protects only the trades you designate (by magic and/or symbol), logs every action, and adapts visually to your chart. It is not a strategy — it is the risk layer your strategy should have been built on top of, especially for grid, martingale, scalping, and prop-firm use cases.
