Guarda come scaricare robot di trading gratuitamente
Ci trovi su Facebook!
Unisciti alla nostra fan page
Script interessante?
Pubblica il link!
lasciare che altri lo valutino
Ti è piaciuto lo script? Provalo nel Terminale MetaTrader 5
Librerie

CME equity index futures holiday calendar - libreria per MetaTrader 5

Silviu-mihai Bere
Silviu-mihai Bere
I build and test automated trading systems for Nasdaq-100 futures (MNQ, NQ) and NAS100 CFDs on MetaTrader 5.
Visualizzazioni:
58
Pubblicato:
\MQL5\Include\ \MQL5\Scripts\
Freelance MQL5 Hai bisogno di un robot o indicatore basato su questo codice? Ordinalo su Freelance Vai a Freelance

An Expert Advisor that closes positions before the daily halt, or that should not open trades on a short session, has to know when the market stops. On a normal day CME Globex halts the equity index futures at 17:00 New York. On about twelve days a year it halts earlier or does not open at all, and a program that waits until 16:55 to close ends up holding its positions through the halt.

CMECalendar.mqh computes these days from the rules, for any year, with no list to update every December:

DaySession (New York time)
New Year's Day, Good Friday, Christmas Dayclosed
Martin Luther King Jr. Day, Presidents' Day, Memorial Day, Juneteenth (from 2022), Independence Day, Labor Day, Thanksgivinghalt at 13:00
The day after Thanksgiving, 3 July, 24 December (on weekdays that are not an observed holiday)halt at 13:15
Good Friday when the US jobs report is published that day (first Friday of the month)halt at 09:15
Everything else, Monday to Fridayhalt at 17:00

Holidays that fall on a Saturday move to the Friday before, and holidays on a Sunday move to the Monday after, except New Year's Day on a Saturday, which does not move. Easter, and with it Good Friday, is computed with the Gregorian algorithm. One-off changes that no rule can predict, such as the 09:30 halt on the national day of mourning, 9 January 2025, are kept in a short string, CME_SPECIAL_DAYS, that you can extend.

All functions work on New York dates and New York times. To use them in an Expert Advisor, convert the server time to New York time with your broker's offset first.

#include <CMECalendar.mqh>

// ny = the current New York time (server time converted with your broker's offset)
void CheckHalt(datetime ny)
{
   int halt;
   ENUM_CME_DAY kind = CMEEquityDayOf(ny, halt);
   if(kind == CME_DAY_CLOSED)
      return;                                // no day session today
   MqlDateTime t; TimeToStruct(ny, t);
   int minuteNY = t.hour * 60 + t.min;
   if(minuteNY >= halt - 5 && minuteNY < 18 * 60)
   {
      // within 5 minutes of today's halt: close, and wait for the next session
      // (18:00, or Sunday 18:00 after a Friday)
   }
}

CMECalendarScan.mq5 checks the calendar against real data. It reads the M1 bars of one or more symbols (for futures, list all the contracts, comma separated; the script uses the busiest contract of each day), finds the last trade before 17:00 New York on every day and compares it with the calendar. Set the broker's server clock in the inputs: hours from GMT in winter, and whether the server follows US or European summer time. The differences are printed in the Experts log, and the whole table is written to cme_calendar_scan.csv in the common Files folder.

The inputs of the script:

InputDefaultMeaning
InpSymbolschart symbolSymbols to read, comma separated. For futures, all the contracts of the period.
InpFrom, InpTo2019.06.01, 2030.01.01Period. The scan stops at the first and last bar of the history.
InpGmtBase0Server clock in winter, hours from GMT (0 for UTC, 2 for a GMT+2/+3 server).
InpDstRulefixed all yearWhether the server clock moves one hour forward during US or European summer time.
InpMinBars60A day counts as a session only with at least this many trade bars.
InpTolerance10Minutes without trades accepted before the halt, for thin contracts.
InpPrintAllfalseAlso print the holidays and early halts that match.

Some brokers' histories hold stray bars on weekends and after an early halt, built from quotes that only repeat the last trade price. The script counts a bar as a trade only when the price moved, and a day as a session only when it has at least 60 such bars. Thin contracts can go a few minutes before the halt without a trade, so a halt up to 10 minutes early is accepted (both values are inputs).

Verification. The scan was run on 30 quarterly Micro E-mini Nasdaq-100 contracts, from June 2019 to October 2026, on a broker whose server runs on UTC. Of 1,911 weekdays, 85 were holidays or early halts, including the three Good Fridays with a jobs report (2021, 2023, 2026), the day of mourning in 2025, and holidays moved from a Saturday or a Sunday. The calendar and the history agreed on every day. (The first two weeks of June 2019, a month after the Micro contracts were launched, were too thin to read and are left out.) The same prices rebuilt on a UTC clock and on GMT+2/+3 clocks (US and European summer time), September 2025 to March 2026, gave identical results on all three (the few differences, on days when that contract was still thin, fell on the same days on every clock), and a server clock set to the wrong summer-time rule showed up as differences in exactly the weeks between the US and European clock changes.

CME calendar against the M1 history, 2019 to 2026

Calendar halt and last trade in the history on every holiday and early halt, 2019 to 2026

Limits.

  • The rules are the current CME holiday schedule for equity index futures. Other CME products (interest rates, energy, metals, agriculture) have different hours on some holidays.
  • The jobs report rule follows the usual calendar of the US Bureau of Labor Statistics. When the report moves to another day, or CME announces a different schedule, add the day to CME_SPECIAL_DAYS.
  • CME publishes its holiday schedule a few weeks before each holiday. Running the scan once a year on your broker's history is a quick way to catch a change.

Neither file trades. They are free to use and change.

VpsToolkit - safe order send and restart-safe state for VPS EAs VpsToolkit - safe order send and restart-safe state for VPS EAs

Include for EAs running 24/7 on an MQL5 VPS or PC: run-where switch, order send with OK/FAIL/UNKNOWN result (no duplicate orders after a timeout), restart-safe counters, positions closed while the EA was off, append-only log and optional Telegram. No trading logic inside.

Garch: GARCH, GJR-GARCH and EGARCH volatility models with forecasts Garch: GARCH, GJR-GARCH and EGARCH volatility models with forecasts

Fits GARCH(1,1), GJR-GARCH and EGARCH with normal, Student t or GED shocks by maximum likelihood, with robust standard errors and variance forecasts.

RegimeHMM: market regimes with a hidden Markov model RegimeHMM: market regimes with a hidden Markov model

Gaussian hidden Markov model fitted by Baum-Welch: regime probabilities without look-ahead, most likely path, expected durations and regime forecasts.

Kalman: exact diffuse Kalman filter, local level and time-varying hedge ratio Kalman: exact diffuse Kalman filter, local level and time-varying hedge ratio

Kalman filter and smoother with an exact diffuse start, missing values and maximum likelihood: local level, local linear trend and a regression whose hedge ratio drifts.