Code works on personal PC, does not on VPS

 

I've got a little snippet of code that works fine on my home PC at multiple brokers but fails on my forex.com VPS. External variables are defined as follows:

extern int GMT_StartHH = 11; // GMT Hour to start trading
extern int GMT_StartMM = 00; // GMT Minute to start trading
extern int GMT_EndHH = 02; // GMT Hour to stop trading
extern int GMT_EndMM = 00; // GMT Minute to stop trading

Code in the function:

datetime GMT_Time, TimeStart, TimeEnd;

GMT_Time = Time[0] - (GMT_Offset * 3600);
TimeStart = StrToTime(TimeToStr(GMT_Time, TIME_DATE) + " 00:00") + (GMT_StartHH * 3600) + (GMT_StartMM * 60);
TimeEnd = StrToTime(TimeToStr(GMT_Time, TIME_DATE) + " 00:00") + (GMT_EndHH * 3600) + (GMT_EndMM * 60);

The GMT_Time is calculated correctly, yet the VPS adds five hours to TimeStart and TimeEnd (Print statements show start as 16 and end as 7). Before I start pulling hair out over this, does anyone see a problem with the code or know of something on the VPS that would cause the problem? Using Build 225 of MT4 on VPS, works fine on 225 and 226 on home PC.

Thanks!

 

How sure are you that your GMT_Time is being calculated correctly?

According to you formula, the GMT_StartHH & GMT_StartMM are constants, so they cannot change, therefore by definition in your formula, the GMT_Time is the problem.

Off the top of my head I would suggest that your GMT_Offset is being calculated according to the TimeLocal() of your VPS/PC rather than the TimeCurrent() of your broker.

 
kennyhubbard wrote >>

How sure are you that your GMT_Time is being calculated correctly?

According to you formula, the GMT_StartHH & GMT_StartMM are constants, so they cannot change, therefore by definition in your formula, the GMT_Time is the problem.

Off the top of my head I would suggest that your GMT_Offset is being calculated according to the TimeLocal() of your VPS/PC rather than the TimeCurrent() of your broker.

GMT_Offset is an external parameter (type int). GMT_Time is calculated correctly, I used Print to verify. All I'm taking from GMT_Time is the date, which is done corrrectly. But it returns a time of 16:00 (for start) and 7:00 (for end) on VPS. It returns 11:00 and 2:00 as it should on my home PC.