Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

Metatrader 4 Libraries | ZZ_TimeWinter 1-1000.mq4 | Source Code Included

Discover expert developed MetaTrader tools that can complement professional solutions.

Image for ZZ_TimeWinter 1-1000.mq4
////////////////////////////////////////////////////////////// 
//
// YURAZ yzh mail ru
//
// the function will return
// true   -  summer time
// false  -  winter time
// 
//  revert to standard time at night of the last Sunday of OCTOBER
//  switch to daylight saving time at night of the last Sunday of MARCH
// 
bool TimeWinter(datetime dt) 
{
   int i;
 
   if (   TimeMonth(dt) >= 11 || TimeMonth(dt) <= 2 ) // WINTER
   {
      return(false); //    Winter
   }
   if (   TimeMonth(dt) >= 4 && TimeMonth(dt) <= 9) // SUMMER
   {
      return(true); //    Summer
   }
 
// It can't be helped, let's determine
   datetime tSeek;
   string sTIM;
   if ( TimeMonth(dt) == 10 ) // october
   {
      if ( TimeDay(dt) >= 20 ) // at night of the last sunday of october - revert to standard time
      {
         tSeek = StrToTime( StringTrimRight(StringTrimLeft(DoubleToStr(TimeYear(dt),0)))+".10.31");  // determine the last day of october
         // search for the first sunday from the end
         for ( i = 31; i >= 20; i-- )
         {
            if ( TimeDayOfWeek(tSeek) == 0 ) 
            {
               break;   // found the last sunday of october
            }
            tSeek = tSeek - 86400; // another day
         }
         if ( dt >= tSeek  ) // already standard time
         {
            return(false); // yes winter
         }
      }
      return(true);
   }
   if ( TimeMonth(dt) == 3 ) // march
   {
      if ( TimeDay(dt) >= 20 ) // at night of the last sunday of march - switch to daylight saving time
      {
         tSeek = StrToTime( StringTrimRight(StringTrimLeft(DoubleToStr(TimeYear(dt),0)))+".03.31");  // determine the last day of march
        
         for ( i = 31; i >= 20; i-- )
         {
            if ( TimeDayOfWeek(tSeek) == 0 ) // search for the first sunday from the end
            {
               break; // found the last sunday of march
            }
            tSeek = tSeek - 86400; // another day
         }
         if ( dt >= tSeek  ) // already daylight saving time
         {
            return(true); //  already summer 
         }
      }
      return(false);
   }
}

Classic MACD strategy made fully automatic – the MACD Expert Advisor for MT4 handles it all. Check it out.

Thanks for reading. Discover premium MetaTrader solutions at RobotFX.

7357

Best MetaTrader Indicators + Profitable Expert Advisors