Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

Processing Time (2) Function - MetaTrader 5 Library | MT5 EA Download - MetaTrader 5 Resources

author EAcpu | 5 reads | 0 comments |

Dealing with time (2) functions - library for MetaTrader 5

Dealing with time (2) functions - library for MetaTrader 5

Dealing with time (2) functions - library for MetaTrader 5

The version of Processing Time.mqh v. 1.01 article "Processing Time (Part 2): Features" ( https://www.mql5.com/en/articles/9929 ) no longer works because MQ changed the replication time() function which took some time after this article was published. Now, if the future time value is greater than current(), the function will no longer return the time specified for the start_time and/or stop_time parameters. Instead, the last open time of the current bar will be returned as the maximum possible value.

Since the end of the Forex trading session is determined this way, among other things, in order to determine the offset of the broker's time, this now leads to wrong values!

This calculation has changed in v. 2.03. And the calculation of time changes has been completely changed so that complex time changes from Sydney (Australia) back to the 1970s are now also covered.

Also attached is the table Daylight Savings Time 1975 - 2030.xlsx as zip file, all times have changed since the 70's, everyone can check the correct working of the formulas, here is a sample series of tables:

Dealing with time (2) functions - library for MetaTrader 5

Additionally, there is now a new simple function SecTillClose() which gives you the remaining time in seconds until the Forex market closes (MQ's time currency) - without copying time() . This is interesting for those who want to close their positions before the weekend or do not want to open new positions within the prescribed time before the weekend.

The included indicator DealingWithTime_TestIndi.mq5 annotation on the chart shows not only the summer/winter time in Europe, the United States and Australia (Sydney), but also the current time and time shift in different cities. Here you can find a table of different local times in big cities for you to compare: https://www.timeanddate.com/worldclock/ . So you can check these values ​​at any time. The indicator also demonstrates how to determine and use the values ​​(subtract from what or add what), so it is easier to use it yourself - copy and paste, the fastest form of programming.

The last two lines also show the last second of the current Forex trading session and the remaining time in hours (easier to judge) and seconds. If the Forex trading session is closed at 17:00 New York local time on Friday, there will be no valid bars with an opening time of 17:00 New York time. Therefore, 1 second is subtracted from this function in order to be able to obtain the last valid opening time of the last bar in the broker's time. However, some brokers end Forex trading a few minutes early, no longer offer any prices, and do not accept any trading orders.

Dealing with time (2) functions - library for MetaTrader 5


Attachment download

📎 test_dst_2.mq5 (3.04 KB)

📎 dealingwithtime_testindi.mq5 (3.93 KB)

📎 dealingwithtime.mqh (63.38 KB)

Source: MQL5 #45287

Verification code Refresh