Libraries: Local Timezones and Local Session Hours - page 8

 
Stanislav Korotky #:

Just a guess: try to disable the visual mode and/or choose real ticks.

Unfortunately... :( Neither disabling visual mode or choosing real ticks helps.

I also switched to a live account on the same provider (I was on demo) but didn't help.

After searching for a long time I discovered that the error arrives in that command:

datetime tGMT = ::TimeGMT();

second command in the `SetLocalTime`.

Strangely enough, the TimeGMT() method returns a strange date (a week later) even though no ticks have arrived inside the expert (I have breakpoint to be sure) and we are still inside the OnInit().

int OnInit()
  {
//---
   Print("\n========== Working with FTSE session hours  ==========");
   const ENUM_ZONE_ID FTSE_zone_id = ZONE_ID_LONDON;
   CSessionHours FTSE_tz(FTSE_zone_id);  <--------------- Here

Further more, when I comment out the `CheckLoadHistory(symbol, PERIOD_H1);` inside the `string CTimeZoneInfo::FindSymbol(string symbol)` method it returns correct values.

Not sure of what could affect the ::TimeGMT() method inside the CheckLoadHistory but I will continue investigating it and inform you about my findings.

In any case I don't believe that the TimeGMT should return different date on subsequent call unless new ticks arrive. As such I am thinking that Metatrader has some kind of bugs...

 

Latest findings...

There is definitely an issue with the `Sleep` method inside the `CheckLoadHistory`.

If I change it to something like:

bool CTimeZoneInfo::CheckLoadHistory(const string symbol, const ENUM_TIMEFRAMES period)
  {
    Sleep(5000);
  return true;
  }

I see the TimeLocal() switching by 5 seconds.

The problem becomes worse if I change it to:

bool CTimeZoneInfo::CheckLoadHistory(const string symbol, const ENUM_TIMEFRAMES period)
  {
  uint tick2=GetTickCount();
  while(GetTickCount()-tick2<=6000)
    Sleep(5);
  return true;
  }

The more loops using GetTickCount() and Sleep() and becomes worse.

Inside the `CheckLoadHistory` it has the following loop which is the one that creates the issue.

//--- wait for timeseries build
   while(!SeriesInfoInteger(symbol,period,SERIES_SYNCHRONIZED) && !IsStopped() && (GetTickCount()-tick<=6000))
      Sleep(5);
//--- second attempt

Did something change in the later versions of Metatrader?

Removing the Sleep statement as bellow it fixes the problem and returns correct day.

//--- wait for timeseries build
   while(!SeriesInfoInteger(symbol,period,SERIES_SYNCHRONIZED) && !IsStopped() && (GetTickCount()-tick<=6000))
      ;
//--- second attempt
 
Efthymios Kalyviotis #:

There is definitely an issue with the `Sleep` method inside the `CheckLoadHistory`.

Fixed in v2.17.

Thanks @Efthymios Kalyviotis and @Rob Josephus Maria Janssen for detecting this bug.

 
Hi Amrali Thanks for this excelant piece of code. I think the DST start and end is swapped on Sydney though. They do have DST now. Please confirm again on the mentioned website. Together we always help each other. Keep up the good work ... case ZONE_ID_SYDNEY: /// /// Sydney: https://www.timeanddate.com/time/change/australia/sydney /// DST begins at 03:00 local time on the first Sunday of April (-1), /// and ending at 02:00 local time on the first Sunday of October (+1) /// dst_start = Date(iYear, 04, (7 - (4 + Y) % 7), 03, 00); dst_end = Date(iYear, 10, (7 - (5 + Y) % 7), 02, 00);