MQL4 Time and Time Related Issues Guide
MQL4 Time and Time Related Issues Guide
MQL4 Time and Time Related Issues Guide
It is often referred to as either Universal Time (UT) or Universal Time, Coordinated (UTC).
This time is considered to be the most accurate.
It is almost always referenced by a 24 hour clock: 0000 to 2359. Sometimes a Z is
appended to the time to indicate a Zero Hour offset because we are referencing the time at
the zero longitudinal meridian, as in 1030Z. Pronounced One Zero Three Zero Zulu.
UTC is considered to be more accurate for weather, and astronomical applications. UTC can
also be obtained readily from the Global Positioning System (GPS) satellites for navigation
purposes. 3
UTC is equivalent to the civil time for Iceland, Liberia, Morocco, Senegal, Ghana, Mali, Mauritania, and several
other countries. During the winter months, UTC is also the civil time scale for the United Kingdom and Ireland.
http://aa.usno.navy.mil/faq/docs/UT.html
4
Source: http://aa.usno.navy.mil/faq/docs/international_date.html
http://imagine.gsfc.nasa.gov/docs/ask_astro/answers/980225a.html
Worthless Trader information, but fun: There is never truly a Sunrise or Sunset, because
it is the Earths rotation which brings the Sun into view! It would be more accurate to say,
What a beautiful Earth rotational view this evening.
The circumference of the Earth is 40,008 kM, and is rotating at 1667 kM/Hr or, 27.78
kM/Min. In the 12 seconds it took you to read this paragraph, the earth rotated about 5.56
kM!
The Right Hand Rule: Hold your Thumb towards the North Pole and point your index finger
to the East. The earth rotates in the direction of your finger from West to East. As you move
East around the world, time increases. Paradoxically, if you travel far enough East, you will
arrive at Yesterday, when you cross the International Date Line.
Daylight Saving
Time by Country
Standard Time:
Fall Move the
Clock Back (-1)
Hour
United States
before 2007. 6
The Uniform Time
Act of 1966, and
1986
United States,
2007 +
European Union
All Time zone
change at the
same time.
Russia (accuracy
of information
unknown)
China
Japan
None
Equatorial and tropical countries (lower latitudes)
generally do not observe Daylight Saving Time. Since
the daylight hours are similar during every season, there
is no advantage to moving clocks forward during the
For the U.S. and its territories, Daylight Saving Time is NOT observed in Hawaii, American Samoa, Guam, Puerto
Rico, the Virgin Islands, Arizona, and most of the Eastern Time Zone portion of Indiana. The Navajo Nation
participates in the Daylight Saving Time policy, even in Arizona, due to its large size and location in three states.
summer.
Australia
http://www.statoids.com/tau.html
All Other
Countries
http://webexhibits.org/daylightsaving/g.html
Seasons:
The Northern Hemisphere is the upper half of the planet, and the Southern Hemisphere is
the lower half. The Seasons are opposite from each other in each half of the planet.
For example:
Winter
Spring
Summer
Autumn
USA
Dec. to Feb.
March to May
June to Aug.
Sept. to Nov.
Australia
June to Aug.
Sept. to Nov.
Dec. Feb.
March to May
http://www.wealth-lab.com/cgi-bin/WealthLab.DLL/topic?id=4894
World FOREX Markets
Zolero: http://www.metatrader.org/cgi-bin/yabb2/YaBB.pl?action=search2
I had some problems to define how to make a program buy or sell only at first tick of new bar. I tried
volume and time methods and somehow nothing worked.
if(volume[0]>1) return(0); -- it is a good code if market is slowly moving but there is always a risk
that just a moment before new bar is created a bigger move starts and your code just doen't react.
so I made a little thinking and came up with a code that works very accurately... at least my tests
show that
at the beginning where you normally define extern int
datetime x;
x=iTime(NULL, 0, 0);
and then to the control line inside of start()
if(x==iTime(NULL, 0, 0)) return(0);
x=iTime(NULL, 0, 0);
that's it! just wanted to save some time for others who are trying to get their code act at this
moment.
Checkforelapsedtimefromlastentrytostopmultipleentriesonsame
bar
Five why:
MT doesn't use your local time, it uses whatever time the server is set to. You just happen to live in
the same time zone as your server.
you can call it a bug in MT4, I do, but the regardless you can't change the time and you can't make
the H4 bars span different hours than it already does. If you think it will help, goto MQ's website and
complain. But I doubt it will do any good.
Parameters
value
mod
e
Sample
strign var1=TimeToStr(CurTime(),TIME_DATE|TIME_SECONDS);
int
ArrayBsearch(
Returns the index of the first occurrence of a value in the first dimension of array if possible, or the
nearest
one,
if
the
occurrence
is
not
found.
The
function
cannot
be
used
with
string
arrays
and
serial
numeric
arrays.
Note: Binary search processes only sorted arrays. To sort numeric arrays use ArraySort() functions.
Parameters
array[]
value
count
start
Starting index to search for. By default, the search starts on the first element.
directio
n
Sample
datetime daytimes[];
int
shift=10,dayshift;
// All the Time[] timeseries are sorted in descendant mode
ArrayCopySeries(daytimes,MODE_TIME,Symbol(),PERIOD_D1);
if(Time[shift]>=daytimes[0]) dayshift=0;
else
{
dayshift=ArrayBsearch(daytimes,Time[shift],WHOLE_ARRAY,0,MODE_DESCEND);
if(Period()<PERIOD_D1) dayshift++;
}
Print(TimeToStr(Time[shift])," corresponds to ",dayshift," day bar opened
at ",
TimeToStr(daytimes[dayshift]));
Value
Description
PERIOD_M1
1 minute.
PERIOD_M5
5 minutes.
PERIOD_M15
15
15 minutes.
PERIOD_M30
30
30 minutes.
PERIOD_H1
60
1 hour.
PERIOD_H4
240
4 hour.
PERIOD_D1
1440
Daily.
PERIOD_W1
10080
Weekly.
PERIOD_MN1
43200
Monthly.
0 (zero)
datetime CurTime()
Returns the last known server time, number of seconds elapsed from 00:00 January 1, 1970.
Sample
if(CurTime()-OrderOpenTime()<360) return(0);
int Day()
Returns the current day of the month.
Sample
if(Day()<5) return(0);
)
int DayOfWeek(
Returns the current zero based day of the week (0-Sunday,1,2,3,4,5,6).
Sample
// do not work on holidays.
if(DayOfWeek()==0 || DayOfWeek()==6) return(0);
int DayOfYear()
Returns the current day of the year (1-1 january,..,365(6) - 31 december).
Sample
if(DayOfYear()==245)
return(true);
int Hour()
Returns current hour (0,1,2,..23)
Sample
bool is_siesta=false;
if(Hour()>=12 || Hour()<17)
is_siesta=true;
datetime LocalTime()
Returns local computer time, number of seconds elapsed from 00:00 January 1, 1970.
Sample
if(LocalTime()-OrderOpenTime()<360) return(0);
int Minute()
Returns current minute (0,1,2,..59).
Sample
if(Minute()<=15)
return("first quarter");
int Month()
Returns current month as number (1-January,2,3,4,5,6,7,8,9,10,11,12).
Sample
if(Month()<=5)
return("first half of year");
int Seconds()
Returns current second (0,1,2,..59).
Sample
if(Seconds()<=15)
return(0);
Parameters
dat
e
Datetime is the number of seconds elapsed since midnight (00:00:00), January 1, 1970.
Sample
int day=TimeDay(D'2003.12.31');
// day is 31
int TimeDayOfWeek(datetime date)
Returns zero based day of week (0-Sunday,1,2,3,4,5,6) for specified date.
Parameters
dat
e
Datetime is the number of seconds elapsed since midnight (00:00:00), January 1, 1970.
Sample
int weekday=TimeDayOfWeek(D'2004.11.2');
// day is 2 - tuesday
int TimeDayOfYear(datetime date)
Returns day (1-1 january,..,365(6) - 31 december) of year for specified date.
Parameters
dat
e
Datetime is the number of seconds elapsed since midnight (00:00:00), January 1, 1970.
Sample
int day=TimeDayOfYear(CurTime());
int Year()
Returns current year.
Sample
// return if date before 1 May 2002
if(Year()==2002 && Month()<5)
return(0);
int TimeYear(datetime time)
Returns year for specified date. Return values can be in range 1970-2037.
Parameters
time
Datetime is the number of seconds elapsed since midnight (00:00:00), January 1, 1970.
Sample
int y=TimeYear(CurTime());
int TimeMonth(datetime time)
Returns month for specified time.
Parameters
time
Datetime is the number of seconds elapsed since midnight (00:00:00), January 1, 1970.
Sample
int m=TimeMonth(CurTime());