Watch how to download trading robots for free
Find us on Telegram!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Libraries

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

Views:
3830
Rating:
(13)
Published:
2023.07.05 12:50
Updated:
2023.08.20 11:13
Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

The version of DealingWithTime.mqh v. 1.01 of the article "Dealing with Time (Part 2): The Functions" (https://www.mql5.com/en/articles/9929) did not work any more because MQ changed the behavior 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, among other things, in order to determine the offset of the broker time, this now results in incorrect values!

This calculation has been changed in v. 2.03. But also the calculation of the time changes was changed altogether, so that now also the complicated times of the time change from Sydney (Australia) back to the 70's are covered.

Attached is also the table DST 1975 - 2030.xlsx as zip-file with all time changes since the 70's in a way that everybody can check the correct working of the formulas, here a sample series of the table:

On 01/01/1982 it is wintertime in the USA (DST==0) and the next changeover is on 04/25/1982, which is the last (25th of the month) Sunday of April (4). The table is already sorted by the geographic time zone (column A), then by the time zone of the year (column L, spr=spring, aut=autumn,), and finally by the query date (column C). The table can be created automatically by the included EA (a script cannot run in debug mode) Test_DST 2.mq5 if you run it in debug mode and copy the rows of the journal log in the debugger and paste them into a table program; the cell separator would be the space character.

Also, there is now a new, simple function SecTillClose() that gives you the remaining time in seconds (the time currency of MQ) until the forex market will close - without CopyTime(). This is interesting for those who want to close their positions before the weekend or do not want to enter a new position in a defined period of time before the weekend.

The included indicator DealingWithTime_TestIndi.mq5 shows as a comment on the chart not only the summer/winter time of Europe, USA and Australia (Sydney), but also current time and time shift of different cities. Here you can find a table of different local times of big cities for your comparison: https://www.timeanddate.com/worldclock/. You can thus check the values at any time. This indicator also demonstrates how these values are determined and used (what is subtracted or added from what), So it is easier to use it yourself - copy & paste, the fastest form of programming.

The last two lines also show the last second of the current FX session and the remaining time in hours (is easier to judge) and in seconds. If in NY on Fridays at 17:00 local time the FX session is closed, then there is no valid bar with an opening time 17:00 NY time. Therefore, 1 second is subtracted in this function to be able to get the last valid opening time of the last bar in the broker's time. However, some brokers end their FX session a few minutes earlier by not providing any more prices and not accepting any more trade orders.



Strength Index Signal Strength Index Signal

provides clear arrows which clearly show the direction of the currency pair.

Indicator PriceScale.mq5 - price scale for the visually impaired. Indicator PriceScale.mq5 - price scale for the visually impaired.

Tortured small print in the terminal? This indicator makes price numbers visible!

New Concept: Trailing Take Profit New Concept: Trailing Take Profit

On contrast with Trailing Stop which a stop loss trails price until the price hits the stop loss and the position gets closed in profit, introducing Trailing Take Profit which take profit trails price when a position is in loss and ultimately the position gets closed with loss.

Dynamic Support and Resistance Dynamic Support and Resistance

The "Dynamic Support and Resistance" Indicator is a versatile tool that combines support and resistance levels with real-time market dynamics. By incorporating previous daily highs and lows, it provides valuable insights into market psychology and identifies potential areas of price reversals or breakouts. With its ability to adapt to changing market conditions and customizable options, traders can stay ahead of trends and make informed decisions. This indicator is suitable for various trading styles and timeframes, empowering both experienced and novice traders with a competitive edge.