1

I found that the TimeGmt() function is not accurate if the server time is set up wrong, especially for getting other timezones with daylight savings.

Is there any way to scrape time data from the internet and into the expert advisor? I found the WebRequest function but I don't really understand the parameters.

The clock on my laptop synchronizes with time.windows.com. Is it also possible to do this in mt4? There are also other websites like time.is.

Thanks

Joseph Cho
  • 4,033
  • 4
  • 26
  • 33

1 Answers1

2

You can use WebRequest function and then parse the output. Quite a lot of silly work though. If your laptop is syncronized, you can ask current local time using TimeLocal() function, and obtain time of your laptop. It does not work in tester (actually, nothing except TimeCurrent() works correctly as specified in the official documentation).

If going to 'time.is' website, you have to find line that looks like '20:42:15' and extract current time (20:42 in my case) from that line. You should use GET request, so use the first WebRequest function. Keep in mind that WebRequest is async so it takes time to go to the website then parse the data etc and your ea waits for the reply before going further, so it probably makes sence to call that function once per week or so.

Daniel Kniaz
  • 4,603
  • 2
  • 14
  • 20
  • Thank you so much. So it is possible then. The problem is, I dont exactly understand how to use the WebRequest function. What do I put in the cookie, referer, data, and all the other parameters. Timeout is the only parameter i know. lol – Robert Simon Uy Sep 17 '18 at 23:44
  • Cookie and referrer can be replaced with `NULL`, for data - use am empty `char array`, its size is 0. If you have to pass reference - create it first (`char emptydata[], result[]; string result_headers;`) for others - put default values (`NULL` and `0`). Just follow the example #1 https://docs.mql4.com/en/common/webrequest with your website address and convert resulting array to string with string `ouput=CharArrayToString(result);` if `WebRequest` returned `200`. – Daniel Kniaz Sep 18 '18 at 07:47