Libraries: Dealing with time (2) functions - page 6

 
Anil Varma #:

Hi @Carl Schreiber

There used to be methods to find First Bar and Last Bar of the day, do they still exist somewhere in your lib(s)? If true please share the link.

I remembered one of your post stating that they no longer works with updated Mql5 version, but not sure about it.

I am preparing a solution but I am packed with a range of jobs with deadlines...

 
Carl Schreiber #:

I am preparing a solution but I am packed with a range of jobs with deadlines...

Thanks for reply and your consideration @Carl Schreiber

 

Hi @Carl Schreiber

I found your code useful!

I needed to write a function to convert between two time zones and used your code. I thought I would share my function here in case you or others can make use of it:

#include <DealingWithTime.mqh>
datetime timezone_conversions(string time_zone_known, string time_given, string time_zone_required)export{
   // https://www.mql5.com/en/code/45287
   // https://www.mql5.com/en/articles/9926
   // https://www.mql5.com/en/articles/9929

   datetime tGIVEN = StringToTime(time_given);  
   checkTimeOffset(tGIVEN); // check changes of DST

   // Get GMT:
   datetime tGMT = NULL;
   if(time_zone_known=="GMT"     ){tGMT = tGIVEN;}
   if(time_zone_known=="Broker"  ){tGMT = tGIVEN + OffsetBroker.actOffset;}
   if(time_zone_known=="NY"      ){tGMT = tGIVEN + (NYShift+DST_USD);}
   if(time_zone_known=="Lon"     ){tGMT = tGIVEN + (LondonShift+DST_EUR);}
   if(time_zone_known=="Ffm"     ){tGMT = tGIVEN + (FfmShift+DST_EUR);}
   if(time_zone_known=="Syd"     ){tGMT = tGIVEN + (SidneyShift+DST_AUD);}   
   if(time_zone_known=="Mosc"    ){tGMT = tGIVEN + (MoskwaShift+DST_RUS);}  
   if(time_zone_known=="Tok"     ){tGMT = tGIVEN + (TokyoShift);}  

   // define the required time:
   datetime tREQ = NULL;
   if(time_zone_required=="GMT"     ){tREQ = tGMT;}
   if(time_zone_required=="Broker"  ){tREQ = tGMT - OffsetBroker.actOffset;}
   if(time_zone_required=="NY"      ){tREQ = tGMT - (NYShift+DST_USD);}
   if(time_zone_required=="Lon"     ){tREQ = tGMT - (LondonShift+DST_EUR);}
   if(time_zone_required=="Ffm"     ){tREQ = tGMT - (FfmShift+DST_EUR);}
   if(time_zone_required=="Syd"     ){tREQ = tGMT - (SidneyShift+DST_AUD) ;}
   if(time_zone_required=="Mosc"    ){tREQ = tGMT - (MoskwaShift+DST_RUS);}
   if(time_zone_required=="Tok"     ){tREQ = tGMT - (TokyoShift);}      

   return tREQ;
}


Cheers

 
if anyone gets the error " DealingWithTime_TestIndi (BTCUSD,M15) array out of range in 'DealingWithTime.mqh' (275,59) " this may be due to the symbol you applied the indicator too. You need to use EURUSD instead or change the  DealingWithTime.mqh code

 
Bitcoin and other cryptocurrencies do not follow the Forex session times, so you cannot use it.
Also, some brokers have an incorrect method of switching from summer to winter time and vice versa, so this indicator won't work as well.

You can check your broker with this script: https://www.mql5.com/en/code/55056
Again, it is based on Forex and not cryptocurrencies.
Dealing with time (2) functions
  • www.mql5.com
Calculate DST for USA, EUR, AUD and RUB and the offset time of the broker automatically from the 70's until 2030 - even in the Strategy Tester of MQ.