News Blackout for MT5
- Yardımcı programlar
-
Themistokli Kola
MQL4 / MQL5 and Pine Script developer.
What I do:
- Pine Script to MQL5 / MQL4 conversions (TradingView indicators and strategies into MT5/MT4 indicators or EAs)
- Fixes and changes to existing EAs and indicators: bugs, new inputs, filters, daily limits, breakeven and trailing logic - Sürüm: 1.0
- Etkinleştirmeler: 5
News Blackout for MT5 reads the economic calendar that is built into MetaTrader 5 and keeps a blackout window around the news you choose. During a blackout it can delete pending orders, close positions or move their stop loss to break even, and it sets a terminal global variable that your other Expert Advisors can read to skip new trades. A panel shows the countdown to the next blackout and the next events. It never opens trades and gives no signals. It is useful when your own rules, or your account's rules, forbid trading around news.
Important: News Blackout cannot switch other Expert Advisors off or press the AutoTrading button, because MetaTrader 5 does not allow that without a DLL. Other EAs keep running; they skip new trades only if they read the blackout flag described below.
Setup in 5 steps
- Attach it once per terminal. Drag News Blackout for MT5 onto any one chart. One copy covers the whole account; do not attach it to several charts.
- Choose the news. Pick the importance (high only, or high and medium) and the currencies: either automatic (the currencies of every symbol with an open position or pending order, plus the chart symbol) or a fixed list such as USD,EUR,GBP. Optional keywords narrow the events further, for example NFP,CPI,FOMC,Rate.
- Set the window. Minutes before and after each event. Overlapping windows are merged into one.
- Choose the actions. Delete pending orders (on by default), close positions at the blackout start, move SL to break even instead of closing, re-place the deleted pending orders afterwards, and the symbol and magic number filters.
- Allow algorithmic trading in the toolbar and in the EA settings (needed to delete and close orders), press OK and check the panel: Status: Clear with the countdown to the next blackout, and the next events below it.
Calendar settings
- Importance - High only (default) or High and medium.
- Currencies - Auto: the base and profit currencies of every symbol with an open position or pending order, plus the chart symbol. Fixed list: the currencies in the next input.
- Fixed currency list - comma list, for example USD,EUR,GBP (fixed mode only).
- Only events whose name contains - comma list of words; an event is used only if its name contains one of them. Empty = all events.
- Skip events whose name contains - comma list of words; matching events are ignored.
- Events listed without an exact time (all-day or tentative) are not used, and the Experts log says how many.
Window
- Blackout starts N minutes before the event - default 15.
- Blackout ends N minutes after the event - default 15.
Actions
- Delete pending orders during the blackout - deletes pending orders in scope at the start, and any new one placed while the blackout lasts.
- Close open positions at blackout start - closes positions in scope once, when the blackout starts. Requotes are retried; every failure is shown with the trade server code.
- Move SL to break even instead of closing - a position that is ahead by at least the next input is moved to break even instead of being closed. The stop loss is never widened.
- Minimum distance for break even, points - default 50.
- Re-place deleted pending orders after the blackout - puts the deleted orders back with the same type, price, SL, TP, volume, comment, magic number and expiry. An order whose price is no longer valid, or whose expiry has passed, is skipped and the panel says why.
- Symbol scope - symbols of the affected currencies (default), or all symbols.
- Magic number - only orders and positions with this magic number; -1 = all, including manual trades.
Blackout flag for your other EAs
With Set global variables on, the EA sets NB_BLACKOUT (1 during a blackout, 0 otherwise) and NB_NEXT_EVENT (server time of the next selected event, 0 if none). When the EA is removed, NB_BLACKOUT goes back to 0. Use it in your own EA before opening a trade:
bool NewsBlackoutActive()
{
return(GlobalVariableCheck("NB_BLACKOUT") && GlobalVariableGet("NB_BLACKOUT")==1.0);
}
// in OnTick: if(NewsBlackoutActive()) return; // skip new trades during the blackout
Alerts
- Alert N minutes before a blackout - a terminal alert before each blackout; 0 = off.
- Alert at blackout start and end - a terminal alert when a blackout starts (with the event names) and when it ends.
- Also send push notifications - the same alerts as push notifications to your MetaQuotes ID (notifications must be enabled in the terminal options). Failed closes, deletes and re-placings are always alerted.
Panel
Product name; status (Clear, BLACKOUT ACTIVE until hh:mm, Calendar data not received, Tester: idle); the countdown to the next blackout or the events of the current one; the next 1 to 5 events with time, currency, importance and name; the last action; the last error in plain words. All times are trade server times, the same as the calendar in the terminal. The minus button collapses the panel, the plus button opens it.
Notes
- The calendar is read for the next 48 hours and refreshed every minute and after a reconnect. If no calendar data arrives for 10 minutes while the terminal is connected, the panel shows Calendar data not received - it never assumes the coast is clear.
- A restart during a blackout does not repeat its actions or alerts: the EA remembers the blackout it has handled.
- In the Strategy Tester the economic calendar is not available; the EA stays idle and says so.
- Screenshot 2 shows example events created for the demonstration, so you can see the panel during an active blackout.
