TimeGMT() gives wrong time - mql4

Why is my EA not giving me the right time?
here is my code (I omitted a lot of stuff that i dont think contribute to the problem):
void OnTick() {
static int OpenHour=99;
if(OpenHour!=TimeHour(TimeGMT())){
OpenHour=TimeHour(TimeGMT());
if(OpenHour==8){
//some codes here
//execute order
}
}
}
The problem is, my server executes my trades on 7am GMT instead of 8am!
Look at my hosted server journal notes:
Notice how at 10AM SERVER TIME, my EA executed the sell stop trade. 10AM server time is 7AM GMT! I know this because right now, it says on the chart it's 12:00, and it's currently 9AM GMT. Therefore, 8AM GMT should be 11AM not 10AM!

Related

Googl Sheets - Time Range to Table

I want to take a time range and convert it to minutes within a table of 30 minute segments. For example, Bob works from 3:35 AM to 5:00 AM. So within the table from 3:30 AM - 4:00 AM should represent 25 minutes, because Bob was working a total of 25 minutes during that time slot. Then the time slots for 4:00 - 4:30 AM and 4:30 - 5:00 AM would both have 30 in their corresponding cells.
Apologies to leave this so broad but I honestly have no idea where to start and this forum has been immensely helpful.
https://docs.google.com/spreadsheets/d/1YpHU-UHlqXL6c8I27zSDZaRu72ViUw5W6RPru-HE3Iw/edit#gid=0
Any help is appreciated.
For each 30-minute interval, you have to check whether these two conditions are met:
The interval start time (3:30) falls between the employee start and end time (3:35 and 5:00).
The interval end time (4:00) falls between the employee start and end time.
If any of these conditions are met, the working time for that interval won't be 0. The working time will be the difference between the minimum of both end times (4:00 and 5:00) and the maximum of both start times (3:30 and 3:35).
Translated to sheets functions, you could do something like this:
=IF(MIN($D2,O$1)-MAX($C2,N$1)>0,TIMEVALUE(MIN($D2,O$1)-MAX($C2,N$1))*24*60,0)
Or, alternatively, this:
=IF(OR(AND($C2<N$1,N$1<$D2),AND($C2<O$1,O$1<$D2)),TIMEVALUE(MIN($D2,O$1)-MAX($C2,N$1))*24*60,0)

iOS/iCal switches times over daylight savings with recurring event from ICS file

I have an event that is set up using UTC and it recurs over daylight savings time. After the daylight savings time switch, the time is moved an hour. UTC does not use DST, so the time should stay the same. I can add an event after DST with the EXACT same UTC time value and the calendar shows the correct time. I've posted my ICS File below with the recurring event and the one that happens after. Has anyone run into this? Any suggested fixes or changes?
["BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//sethhill v1.0//NONSGML //EN\nCALSCALE:GREGORIAN\nMETHOD:PUBLISH\nBEGIN:VEVENT\nDTSTAMP:20120725T222602Z\nDTSTART:20120724T180000Z\nDTEND:20120724T183000Z\nRRULE:FREQ=WEEKLY;UNTIL=20130707T180000Z\nSUMMARY:Class 4 - NODST\nBEGIN:VALARM\nTRIGGER:-PT45M\nACTION:DISPLAY\nDESCRIPTION:NODST\nEND:VALARM\nEND:VEVENT\nBEGIN:VEVENT\nDTSTAMP:20120725T222602Z\nDTSTART:20121120T190000Z\nDTEND:20121120T193000Z\nRRULE:FREQ=WEEKLY;UNTIL=20130707T180000Z\nSUMMARY:Class 4 - TEST1DST\nBEGIN:VALARM\nTRIGGER:-PT45M\nACTION:DISPLAY\nDESCRIPTION:TEST1DST\nEND:VALARM\nEND:VEVENT\nEND:VCALENDAR"]
I was wrong about how DST and UTC work. I was thinking that having a set UTC time meant that the calendar would read it as a set time and display the correct local time auto-magically. In case anyone else is a little confused, think of it like this: MST is UTC-07:00 MDT (DST) is UTC-06:00. If you have a calendar event that is set to repeat throughout the year and it is 18:00 UTC, it will be at 12:00PM MDT or 11:00AM MST. For an ICS file you can either define a STANDARD timezone and a DAYLIGHT timezone, or break the event into multiple parts, with the correct UTC time for each.
I hope this clears things up for someone else.
public static DateTime GetDSTStart(int year, TimeZoneInfo timeZone)
{
DateTime finder = new DateTime(year,3,8);
finder = finder.AddHours(6);
for (int i = 0; i < 7; i++)
{
if(timeZone.IsDaylightSavingTime(finder.AddDays(i))){
return (finder.AddDays(i).AddHours(-6));
}
}
finder = DateTime.MinValue;
return finder;
}
public static DateTime GetDSTEnd(int year, TimeZoneInfo timeZone)
{
DateTime finder = new DateTime(year, 11, 1);
finder = finder.AddHours(6);
for (int i = 0; i < 7; i++)
{
if (!timeZone.IsDaylightSavingTime(finder.AddDays(i)))
{
return (finder.AddDays(i).AddHours(-6));
}
}
finder = DateTime.MinValue;
return finder;
}
iCal displays your calendar in your local time zone (or one you can set manually), but not UTC.
In an region using daylight saving time, the mapping from UTC to local time will change depending on the date. Thus, if the ics file has the date in UTC it will exhibit the problem you described. You need to:
store the time zone ID,
and also the definition of the time zone ID you use, mapping from the ID to the actual UTC offset, in your ics file.
Part 2 might not be needed on some systems, but it is better to store the TZID right in your file for maximum portablility.

Delphi: Using XSDateTime without converting time to local time zone

I am programming in Delphi and consuming an API that returns an XSDateTime representing an appointment timeslot. When I try to create a local datatime the time is being converted to my EST timezone (Z-05:00 or Z-04:00 depending on DST). I need the time to remain in the original timezone of CST (Z-06:00). I am currently formatting the time as follows:
aApptListing := FormatDateTime('yyyy/mm/dd t', aSlots[i].StartDateTime.AsDateTime);
where StartDateTime comes in as the time in CST (Z-06:00). How can I keep the original time for CST? For instance, if the date/time comes thru the API as '2011-12-25T08:00:00-06:00' I want to show 12/25/2011 # 8:00 AM, not 9:00 AM which would be EST.
It looks like the following should work:
with aSlots[i].StartDateTime do
aApptListing := FormatDateTime('yyyy/mm/dd t', EncodeDateTime(Year, Month, Day, Hour, Minute, Second, 0));

What time am I dealing with in Quartz.net?

I am wondering when I set something like this
Trigger trigger = TriggerUtils.MakeDailyTrigger("abc", 5, 00);
I am setting it for 5:00am. Is this 5:00am server time or UTC time?
It uses UTC time, however this is not properly documented.
Edit: actually it looks like it has used both! Versions prior to 0.9 used local time, those after use UTC (source), so it should be UTC as long as you are using a recent version.
5:00am UTC time. Public Quartz.NET API always expects times in UTC format. Just FYI, MakeDailyTrigger is just a shortcut to CronTrigger with following format:
string.Format("0 {0} {1} ? * *", minute, hour)
I believe that when you enter an hour in the hour argument in the MakeDailyTrigger method that Quartz.Net is expecting local time...Internally Quartz.net converts this time to UTC, but if you enter 5 in the hour argument the trigger will fire at 5AM local time.
Try this
Trigger trigger =
TriggerUtils.MakeDailyTrigger("trigger",5,0);
var ttimes = TriggerUtils.ComputeFireTimes(trigger, null, 1);
foreach (DateTime ttime in ttimes)
{
Console.WriteLine(ttime);
'ttime is in UTC - so for EST, ttime.Hour would be 10AM
'however ttime.ToLocalTime().Hour would be 5AM
}

Problem in getting DST time?

I am trying to get the time of other GMT value by using
Calendar c1 = Calendar.getInstance(TimeZone.getTimeZone(gmt));
but how can i get the DST time at that time zone.
The TimeZone class provides a getDSTSavings() method for a specific TimeZone Object. (JavaDoc: "Returns the amount of time to be added to local standard time to get local wall clock time.")
The Calendar interface provides two getOffset() methods, which let you find out the offset from UTC. (JavaDoc: "Returns the offset of this time zone from UTC at the specified date. If Daylight Saving Time is in effect at the specified date, the offset value is adjusted with the amount of daylight saving. ")
please see this piece of code to grok the complicated ways of java time:
#Test
public void testDST() {
final TimeZone met = TimeZone.getTimeZone("MET");
Calendar gc = new GregorianCalendar(met);
final long timeInMillis = gc.getTimeInMillis();
final long gmtTime= timeInMillis-(gc.getTimeZone().getOffset(timeInMillis));
final Date gmtDate = new Date(gmtTime);
System.out.printf("%-40s: %tc\n%-40s: %tc\n%-40s: %tc\n%-40s: %d\n%-40s: %d",
"new Date() (local timezone)",new Date(),
"UTC", gmtDate ,
"now from Calendar with TC GMT+02:00",gc,
"zoneoffset",gc.get(Calendar.ZONE_OFFSET),
"dst savings",met.getDSTSavings());
}
You can also define your own SimpleTimeZone and provide custom DST rules, however, i have not found out how to get this information from the predefined TimeZones.
You should also be aware, that if TimeZone.getTimeZone(TZName) does not find the specified timezone, it does not throw an exception, but it just uses GMT, which can cause major misunderstandings.
You can find all this information (and a lot more) in javadoc for Calendar, TimeZone, Date, etc.
There are few methods available in java.util.TimeZone to get Daylight Saving Time. Please check out the BlackBerry Java Docs page.

Resources