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
The version of DealingWithTime.mqh v. 1.01 from the article Dealing with Time (Part 2): Functions ( https://www.mql5.com/en/articles/9929 ) stopped working because MQ changed the behaviour of the CopyTime( ) function some time after this article was published. Now this function no longer returns future time values if they are greater than TimeCurrent() specified for the start_time and/or stop_time parameters. Instead, the opening time of the last current bar is returned as the largest possible value.
Since the end of the FX session was determined in this way to determine the broker's time shift, this now leads to incorrect values!
This calculation has been changed in version 2.03. This version is already available on CodeBase here: https://www.mql5.com/en/code/45287.
But also the time shift calculation has been completely changed, so that now the complicated times of the Sydney (Australia) time shift back to the 1970s are covered.
Also attached is the DST 1975 - 2030.xlsx table in zip file with all the time changes since the 1970s so that everyone can check that the formulae work correctly, here is an example of a series from the table:
1st January 1982 is standard time in the USA (DST==0) and the next change will be on 25th April 1982, the last (25th of the month) Sunday in April (4). The table is already sorted by geographical time zone (column A), then by time zone of the year (column L, spr=spring, aut=autumn,) and finally by date of enquiry (column C). The table can be created automatically by the included EA (a script cannot be run in debug mode). Test_DST 2.mq5 if you run it in debug mode and copy the lines from the diary log in the debugger and paste them into a spreadsheet; The cell separator would be space.
In addition, there is now a new, simple SecTillClose() function, which provides the time remaining in seconds (the MQ time currency) until the forex market is closed - without CopyTime(). This is interesting for those who want to close their positions before the weekend or don't want to open a new position in a defined period before the weekend.
The included indicator DealingWithTime_TestIndi.mq5, as a comment on the chart, shows not only daylight saving time in Europe, the USA and Australia (Sydney), but also the current time and the time difference of various cities. Here you can find a table with different local times in the main cities for comparison: https://www.timeanddate.com/worldclock/. So you can check the values at any time. This indicator also shows how these values are determined and used (what is subtracted from or added to what), making it easy to use on your own - copy and paste, the quickest form of programming.
The last two lines also show the last second of the current FX session and the time remaining in hours (which is easier to judge) and in seconds. In New York, when the FX session closes at 5pm local time on a Friday, there are no valid bars open at 5pm New York time. Therefore, in this function, 1 second is subtracted to get the last valid open time of the last bar in the broker's time. However, some brokers close their FX session a few minutes early, ceasing to provide prices and no longer accepting trade orders.
Article Processing Time (Part 2): The DealingWithTime.mqh v. 1.01 version of the function ( https://www.mql5.com/en/articles/9929 ) stopped working because MQ changed CopyTime() to work some time after this article was published. Now, the function no longer returns the future time value if it is greater than the TimeCurrent() specified for the start_time and/or stop_time parameters. Instead, the opening time of the last current bar is returned as the maximum possible value.
Since the end of the FX session is determined in this way in order to determine the broker time offset, this now results in an incorrect value!
This calculation has been changed in version 2.03. This version is now available in the code base: https: //www.mql5.com/en/code/45287.
Also the calculation of the time change has been completely changed so that it now covers the complex time of the time change from Sydney (Australia) to the 1970s.
Also attached as a zip file is the table DST 1975 - 2030.xlsx with all the time changes since the 70s so that everyone can check that the formulas are working correctly, and below is a sample series of the table:
1 January 1982 is in US Standard Time (DST==0) and the next change will be on 25 April 1982, the last (25th day of the month) Sunday (4) of April. The table has been sorted by geographic time zone (column A), then by year time zone (column L, spr=spring, aut=autumn), and finally by query date (column C). The table can be created automatically by the included EA(the script cannot be run in debug mode). Test_DST 2.mq5 If you run it in debug mode and copy the rows of the logbook log from the debugger and paste them into the spreadsheet; the cell separators are the spaces.
In addition, there is now a new simple function SecTillClose() which gives you the remaining time in seconds before the forex market closes (MQ's time currency) - no need for CopyTime(). This is interesting for those who want to close a position before the weekend or do not want to open a new position within the specified time before the weekend.
The included indicator DealingWithTime_TestIndi.mq5 as a note to the chart shows not only the daylight saving time in Europe, USA and Australia (Sydney), but also the current time and the time difference between the individual cities. Here you can find tables for comparison of different local times in major cities: https: //www.timeanddate.com/worldclock/. Thus, you can check these values at any time. The indicator also shows how to determine and use these values (what to subtract from or add to what), making it easier for you to use it yourself - copy and paste, which is the fastest form of programming.
The last two lines also show the last second of the current Forex session as well as the remaining time in hours (easier to judge) and seconds. In New York, when the Forex session closes at 5:00pm local time on Friday, there are no valid bars open at 5:00pm New York time. Therefore, in this function, subtract 1 second to get the last valid opening time of the last bar in the broker's time. However, some brokers close forex trading a few minutes early and no longer offer prices or accept trade orders.
The version of DealingWithTime.mqh v. 1.01 from the article Dealing with Time (Part 2): Functions ( https://www.mql5.com/en/articles/9929 ) stopped working because MQ changed the behaviour of CopyTime( ) some time after this article was published. Now this function no longer returns future time values if they are greater than the TimeCurrent( ) specified for the start_time and/or stop_time parameters. Instead, it returns the maximum possible opening time value of the last current bar.
Since the end of the currency session was defined in such a way as to determine the broker's time offset, this now results in incorrect values!
This calculation has been changed in version 2.03. This version is now available in CodeBase here: https://www.mql5.com/en/code/45287.
But also the time translation calculation has been completely changed, so that the complex time translation times from Sydney, Australia back to the 70s are now covered.
Also attached is the DST table 1975 - 2030.xlsx as a zip file with all the time changes since the 70s so everyone can check the formulas are working correctly, here is an example of the table series:
1 January 1982. - US Standard Time (DST == 0), and the next change is on 25 April 1982, the last (25th of the month) Sunday in April (4). The table is already sorted by geographic time zone (column A), then by time zone of the year (column L, spr=spring, aut=autumn), and finally by the date of the query (column C). The spreadsheet can be created automatically by the enabled EA (the script cannot be run in debug mode). Test_DST 2.mq5 if you run it in debug mode and copy the log lines in the debugger and paste them into the spreadsheet; The cell separator will be a space.
In addition, there is now a new simple function SecTillClose(), which gives you the remaining time in seconds (MQ time currency) until the forex market closes - without CopyTime(). This is interesting for those who want to close their positions before the weekend or don't want to open a new position in a certain period before the weekend.
The included indicator DealingWithTime_TestIndi.mq5, as a comment on the chart, shows not only daylight saving time in Europe, USA and Australia (Sydney), but also the current time and time difference of different cities. Here you can find a table with different local times of major cities for comparison: https://www.timeanddate.com/worldclock/. This way you can check the values at any time. This indicator also shows how these values are defined and used (what is subtracted or added from what), which makes it easy to use on your own - copy and paste, the fastest form of programming.
The last two lines also show the last second of the current FX session and the time remaining in hours (which is easier to judge) and seconds. In New York, when the FX session closes at 17:00 local time on Friday, there is no valid bar open at 17:00 New York time. Therefore, this function subtracts 1 second to get the last valid open time of the last bar in the broker's time. However, some brokers end their currency session a few minutes early, no longer providing prices or accepting trade orders.
Hi @Anil Varma
I read the last post of the author @Carl Schreiber about CopyTime() function but since I'm finding more understandable the 1st version I'm still using DealingWithTime.mqh v. 1.01.
In my indicator I want to:
Assign NY raw time seconds), NY hour and NY minute to each bar using the following buffers in order to displaying them in the data window: double NyRawTimeBuffer[]; double NyHourBuffer[]; double NyMinuteBuffer[];The function works just when the timeframe chart where the terminal starts it's set to H1.
If I close the terminal and the timeframe is set to let's say M5, and then I restart the terminal it gives me the following error:
2024.02.18 15:33:38.048 MyFractals_V4 (EURUSD,M5) 240: CopyTime() FAILED for EURUSD H1: need times from 2024.02.12 02:00:00, but there are only from 1970.01.01 00:00:00 error: 4401
You already suggested me through messaging to use CheckLoadHistory() from this article ( https://www.mql5.com/en/code/1251 ) and placing it before CopyXXXX() function in your library:
But the issue is still there.
In the checkhistory.mqh (row 19) I noted the following comment but I don't understand if it could be an issue. I tried to comment it ad test the program again but did not work.
Is there a way to adjust the bug without to switch to the updated library DealingWithTimeV2.03.mqh without to re-write all the code?
Hello,
As I understand from the article, the function "setBokerOffset ()" should work in the strategy tester as well, but it doesn't work.
Does the "The Alternative using it via Input Variables" the only way to get correct times in the strategy tester?
Hi
I have tried to modify the code as below and so far it is working for me. Note that I have converted the Class with constructors and all methods are part of class. Class needs to be called in and initialized in your EA/Strategy Class.
CDealWithTime.OnTick() should be placed in EA/Strategy OnTick()
This code calculates the DST automatically for European and US brokers:
https://www.mql5.com/en/code/27860
The above code was used in Forex Market Hours https://www.mql5.com/en/code/27771 to calculate the day-light saving time changes.
Similar functions can be constructed for different areas of the world.
Hi Amrali
Nice and simple code as an alternative to DealingWithTime v2.03 article. Will look into it for more detailed study.
DealingWithTime.mqh v. 1.01.
Hi Daniel
DealingWithTime.mqh v. 1.01. This article and its code does not work any more due to changes in MQL calculation methods, as explained by Carl in DealingWithTime.mqh v 2.03 article https://www.mql5.com/en/code/45287
You should not be using it at all.