//+------------------------------------------------------------------+
//|  Auto GMT                                      ShowGMToffset.mq4 |
//|  Use_Broker_Time True/False;  then>> GMT -12 to +12              |  
//+------------------------------------------------------------------+
#property indicator_chart_window

#import "kernel32.dll"
   void GetLocalTime(int& a0[]);
   int GetTimeZoneInformation(int& a0[]);
#import

extern string Timezone = " --- Timezone ---";
extern bool AutoGMTOffset = TRUE;
extern int Manual_GMTOffset = 0;
extern double RandomOpenMinuteDelay = 5.0;
int GMToffset;
int LoclTime;

int start() {

   if (!IsDllsAllowed()) {
      Alert("ShowGMT: DLLs are disabled.  To enable tick the checkbox in the Common Tab of indicator");
      return;
   }
 
   AutoGMTOffset();
   string display = display + "\n\n GMT: " + TimeToStr(LoclTime,TIME_MINUTES); 
   if (GMToffset>0) display = display + "\n Broker TimeZone GMT: +" + GMToffset;
   else display = display + "\n Broker TimeZone GMT: " + GMToffset;
   int Myoffset = + ((TimeLocal() - LoclTime) / 3500);
   if (Myoffset>0) display = display + "\n Your TimeZone GMT: +" + Myoffset;
   else display = display + "\n Your TimeZone GMT: " + Myoffset;
   Comment (display);

   return(0);
}

int AutoGMTOffset() {
   int Timezone[43];
      if (AutoGMTOffset == FALSE) {
         GMToffset = Manual_GMTOffset;
         LoclTime = TimeCurrent() - 3600 * GMToffset;
      } else {
         int offset1 = -420;
         int offset2 = GetTimeZoneInformation(Timezone);
         if (offset2 != 0) offset1 = Timezone[0];
         if (offset2 == 2) offset1 += Timezone[42];
         LoclTime = TimeLocal() + 60 * offset1;
         GMToffset = (TimeCurrent() - LoclTime) / 3500;
      }
   return (0);
}

//  if (Tradetime(19, 4) == 1) //when true,1 then trade time begins and checking for trades

//  if (Tradetime(18, 2) == 0) //when false,0 then trade time ends. Maybe close position(s)

int Tradetime(int StartTime, int StopTime) { //StartTime, StopTime
   bool Tradetime = FALSE;
   if (StartTime > StopTime) if (TimeHour(LoclTime) <= StopTime || TimeHour(LoclTime) >= StartTime) Tradetime = TRUE;
   if (StartTime < StopTime) if (TimeHour(LoclTime) >= StartTime && TimeHour(LoclTime) <= StopTime) Tradetime = TRUE;
   if (StartTime == StopTime)if (TimeHour(LoclTime) == StartTime) Tradetime = TRUE;
   if (DayOfWeek() == 5 && TimeHour(LoclTime) > 6) Tradetime = FALSE;
   if (TimeMinute(LoclTime) < RandomOpenMinuteDelay) Tradetime = FALSE;
   if (DayOfWeek() == 1 && TimeHour(LoclTime) < 2) Tradetime = FALSE;
   if (DayOfYear() < 7) Tradetime = FALSE;
   if (Month() == 12 && Day() > 20) Tradetime = FALSE;
   return (Tradetime);
}


