Japan Bank Holiday and Gotobi Library
- Libraries
-
Mikoto Hamazono
AI Trader Kyo | MQL Developer & Forex Innovator
As an MQL developer and a passionate innovator in FX, I build cutting-edge trading solutions that make full use of artificial intelligence. - Version: 1.0
Japan Bank Holiday and Gotobi Library answers the calendar questions of the yen market inside your own Expert Advisor, indicator or script: is today a Japanese bank holiday, is it a gotobi day, when is the next Tokyo fixing, and what time is it in Japan on your broker's server.
All rules are calculated, so there is no holiday table to update. For 1980-2027 the results match the Cabinet Office list of Japanese national holidays day by day. No DLL, no web requests, no files, no trading functions.
What it answers
- Japanese national holidays, including substitute holidays and citizens' holidays, with the English name of each holiday.
- Japanese bank holidays: Saturdays, Sundays, national holidays and December 31 - January 3. All other days are business days.
- Gotobi days: the 5th, 10th, 15th, 20th, 25th and the last day of the month. When that day is a bank holiday, the gotobi moves to the previous business day.
- The Tokyo fixing time: 09:55 Japan time.
- Broker server time to Japan time and back. Japan has no summer time (JST = UTC+9).
Functions
- JpIsBankHoliday(date) - true on Saturdays, Sundays, national holidays and December 31 - January 3.
- JpIsBusinessDay(date) - true on Tokyo bank business days.
- JpIsNationalHoliday(date) - true on national holidays, including substitute and citizens' holidays.
- JpHolidayName(date) - the English name, for example "Marine Day", "Substitute Holiday" or "Bank Holiday"; an empty string on other days.
- JpIsGotobi(date) - true on gotobi days.
- JpGotobiDaysOfMonth(year, month, days[]) - all gotobi days of a month; returns the count.
- JpNextGotobi(date) / JpPrevGotobi(date) - the first gotobi on or after the date / the last gotobi on or before the date.
- JpTokyoFixing(date) - 09:55 Japan time of that day.
- JpNowJst() - the current Japan time.
- JpServerToJst(time) / JpJstToServer(time) - converts between server time and Japan time.
- JpServerGmtOffsetSeconds() - the server's GMT offset in seconds (automatic: TimeTradeServer() - TimeGMT(), rounded to 15 minutes).
- JpSetServerGmtOffset(seconds) - a fixed offset, for example 7200 for GMT+2.
- JpSetServerTimeZone(seconds, rule) - the offset outside summer time and a summer time rule: 0 none, 1 US, 2 EU.
- JpSetServerGmtOffsetAuto() - back to the automatic offset (default).
- JpLibraryVersion() - the version, "1.00".
Date arguments are Japan time; any time of the day can be passed. Holiday and gotobi dates are returned as 00:00 Japan time.
How to use it
The Market installs the library as MQL5\Libraries\Market\Japan Bank Holiday and Gotobi Library.ex5. Paste this import block at the top of your program (or save it as MQL5\Include\JpMarketCalendar.mqh and include that file):
#import "Market\\Japan Bank Holiday and Gotobi Library.ex5" string JpLibraryVersion(); bool JpIsNationalHoliday(datetime date_jst); bool JpIsBankHoliday(datetime date_jst); bool JpIsBusinessDay(datetime date_jst); string JpHolidayName(datetime date_jst); bool JpIsGotobi(datetime date_jst); int JpGotobiDaysOfMonth(int year, int month, datetime &out[]); datetime JpNextGotobi(datetime from_jst); datetime JpPrevGotobi(datetime from_jst); datetime JpTokyoFixing(datetime date_jst); int JpServerGmtOffsetSeconds(); bool JpSetServerGmtOffset(int seconds); bool JpSetServerTimeZone(int standard_offset_seconds, int dst_rule); void JpSetServerGmtOffsetAuto(); datetime JpServerToJst(datetime server_time); datetime JpJstToServer(datetime jst); datetime JpNowJst(); #import
Example for an Expert Advisor:
int OnInit()
{
// In the Strategy Tester TimeGMT() returns server time: set the offset yourself
if(MQLInfoInteger(MQL_TESTER))
JpSetServerTimeZone(2 * 3600, 1); // GMT+2, +1 hour in US summer time
return(INIT_SUCCEEDED);
}
void OnTick()
{
datetime jst = JpNowJst(); // Japan time now
if(JpIsGotobi(jst))
Comment("Gotobi - Tokyo fixing at ",
TimeToString(JpJstToServer(JpTokyoFixing(jst))), " server time");
else if(JpIsBankHoliday(jst))
Comment("Japanese bank holiday ", JpHolidayName(jst));
else
Comment("Next gotobi: ", TimeToString(JpNextGotobi(jst), TIME_DATE));
} Rules used
- Act on National Holidays as amended: fixed dates, Monday holidays (Coming of Age Day and Health and Sports Day from 2000, Marine Day and Respect for the Aged Day from 2003), Mountain Day from 2016, the Emperor's Birthday by era, and the moved days of 2020 and 2021.
- Substitute holiday: when a national holiday falls on a Sunday, the next day that is not a national holiday is a holiday (from 2007; before that, only the next day).
- Citizens' holiday: a day between two national holidays (from 1986), for example September 22, 2026.
- One-off holidays: 1989-02-24, 1990-11-12, 1993-06-09, 2019-05-01 and 2019-10-22.
- Equinox days: the standard approximation formula, valid for 1980-2099. It gives the official date in every year up to 2027 and agrees with an astronomical calculation in every year to 2099. The government announces each equinox day in February of the previous year.
- Bank holidays: Saturdays, Sundays, national holidays and December 31 - January 3 (Banking Act; today's rule is applied to every year).
- Gotobi: on a bank holiday the day moves to the previous business day of the same month. If the 5th would move into the previous month (for example in May 2027), that business day is already the previous month's month-end gotobi, so it is listed only there.
Things to know
- Valid years: 1980-2099. Outside this range the functions return false, 0, an empty string or -1.
- Strategy Tester: there TimeGMT() returns the server time, so the automatic offset is 0. Call JpSetServerGmtOffset() or JpSetServerTimeZone() in OnInit(), as in the example. When the automatic offset is used in the tester, the library writes one reminder to the tester journal.
- The automatic offset needs a terminal that is synchronized with the trade server. Right after the terminal starts it can read 0 for a few seconds; it is read again on every call.
- The automatic offset is the current offset. To convert past bars across a summer time change, set the server's rule with JpSetServerTimeZone().
- Settings apply to the program that calls them: call them in OnInit() of each Expert Advisor or indicator.
- JpGotobiDaysOfMonth() needs a dynamic array: datetime days[];
- Results are cached per year; a repeated call within the same year takes about 0.01 microseconds.
Support
If anything is unclear, please send me a private message on MQL5.
