You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Is there a way to identify the 4th Thursday of November as it approaches each year using this library?
To be clear, I'm trying to get the U.S. Thanksgiving holiday date in advance of its arrival but it's a moving target in terms of its date.
Although trading is allowed in the U.S. on Thanksgiving, I would like to filter it out x days in advance and y days after.
Is there a way to identify the 4th Thursday of November as it approaches each year using this library?
To be clear, I'm trying to get the U.S. Thanksgiving holiday date in advance of its arrival but it's a moving target in terms of its date.
Although trading is allowed in the U.S. on Thanksgiving, I would like to filter it out x days in advance and y days after.
Please disregard the above. I found the holiday listed in MQ's U.S. Calendar even though it's not an FX market holiday in the U.S. Will access from there.
Thanks anyway. Nice library.
Is there a way to identify the 4th Thursday of November as it approaches each year using this library?
To be clear, I'm trying to get the U.S. Thanksgiving holiday date in advance of its arrival but it's a moving target in terms of its date.
Although trading is allowed in the U.S. on Thanksgiving, I would like to filter it out x days in advance and y days after.
This:
Result:
/* Thu, 24/11/2022 Thursday, 26 November 2020 Thursday, 25 November 2021 Thursday, 24 November 2022 Thursday, 23 November 2023 Thursday, 28 November 2024 Thursday, 27 November 2025 Thursday, 26 November 2026 Thursday, 25 November 2027 Thursday, 23 November 2028 Thursday, 22 November 2029 */Update 18 July 2026 - version 2.50
To trade only during the London session (08:00-17:00).
Or, if you prefer using strings:
For sessions spanning midnight (like, the Asian session):
Update 21 July 2026 - version 2.60
A faster way to calculate the day of the week.
I asked ChatGPT to analyze the article and write a benchmark script.
The benchmark will test my current implementation vs Joffe's artilcle optimized methods.
ChatGPT suggested another possible optimization in MQL5 is worth trying, also (combined implementation method #3).
The "DayOfWeekBenchmark.mq5" script is attached below.
Here are the results:
/* ============================================================ PERFORMANCE BENCHMARK ============================================================ Times are measured with GetMicrosecondCount(). Lower ns/call is better. Current best= 2425 us avg= 2530.200 us best= 2.42 ns/call checksum=4 Reciprocal best= 2266 us avg= 2300.600 us best= 2.27 ns/call checksum=4 Combined best= 1788 us avg= 1810.800 us best= 1.79 ns/call checksum=4 Joffe Narrow best= 1553 us avg= 1635.900 us best= 1.55 ns/call checksum=4 Joffe V3 best= 1986 us avg= 2005.700 us best= 1.99 ns/call checksum=4 ============================================================ RELATIVE PERFORMANCE ============================================================ Current relative= 1.000x speedup= 1.000x Reciprocal relative= 0.934x speedup= 1.070x Combined relative= 0.737x speedup= 1.356x Joffe Narrow relative= 0.640x speedup= 1.561x Joffe V3 relative= 0.819x speedup= 1.221x ============================================================ SUMMARY ============================================================ Current : original expression Reciprocal : replaces /86400 with fixed-point multiplication Combined : reduces seconds modulo one week first Joffe Narrow: 32-bit day-count multiply/add/shift Joffe V3 : 32-bit day-count high+low multiplication method */Edited:
I used a similar technique to Joffey’s methods in my random number generator: Xoshiro256.mqh.
This is particularly useful for a random number generator, where the bound function can be called millions of times.
For the DayOfWeek() function, however, applying this optimization would be more of an overkill, given how infrequently the operation is typically performed.
The technique replaces modulus division ( % ) with reciprocal multiplication, followed by right-shift and a correction step.
Joffe's found the optimal reciprocal and correction for modulus 7, plus some other micro-optimizations.