How do you correctly get broker's GMT offset during weekend?

 

This piece of code I believe was working correctly until market closed for the weekend.


//server-time distance from GMT 
double srv_distance_from_gmt() {return MathRound( (double)(TimeCurrent()-TimeGMT()) /60); }//result is distance from GMT & minutes

//US session is 12-20GMT
bool TimeIsInUS(datetime time)
{
  datetime givenToGMT=(datetime) ( (long)time - (srv_distance_from_gmt()*60) ) ;
  MqlDateTime mqDate;
  TimeToStruct(givenToGMT,mqDate);
  if(mqDate.hour>=12 && mqDate.hour<=20)
    {
      return _true;
    }else return _false;
}


Now its plotting the session in wrong places of charts.  Is this because the last tick arrival is locked at  23:59:59?

How can you accurately get broker's GMT offset(even during weekends)?

 

Check how many daily bars are in last week. If 5 - broker's time is GMT+DST+2, if 6 - check how many hours are in first and last. One would be less than 24 and you will need to add/subtract that value to GMT+DST+2.

Or, since you need to recalculate it twice per year per broker at the worst case, you might as well hardcode it.

 
kypa:

Check how many daily bars are in last week. If 5 - broker's time is GMT+DST+2, if 6 - check how many hours are in first and last. One would be less than 24 and you will need to add/subtract that value to GMT+DST+2.

Or, since you need to recalculate it twice per year per broker at the worst case, you might as well hardcode it.

Thanks for the idea. The calculation seems to be a bit complex. 

However, i did a quick test & found that broker (fxpro) had 5 daily candles last week. But their server's GMT offset is +3.(asked their support)

Maybe I'm doing something wrong. Not sure.


Files:
Capture.PNG  23 kb
Reason: