some one can help me plz about offset with WebRequest

 

i wana get GMT with WebRequest

can some one plz help

string Read_URL(string _url){
string cookie=NULL;
string headers="";
char post[];
char result[];

string TXT="";
_url = "https://www.worldtimeserver.com";



ResetLastError();

//--- download html-pages
int timeout=5000; //--- timeout less than 1,000 (1 sec.) is insufficient at a low speed of the Internet

int offset=WebRequest("GET",_url,cookie,NULL,timeout,post,0,result,headers);
int last_error=GetLastError();
//Read_URL_ErrorCode = last_error;
//--- error checking
if(offset==-1) {


      Print("WebRequest error, err.code  =",GetLastError());
      MessageBox("You must add the address ' "+_url+"' in the list of allowed URL tab 'Advisors' "," Error ",MB_ICONINFORMATION);
      //--- You must add the address ' "+ url"' in the list of allowed URL tab 'Advisors' "," Error "
     }
   else
     {
      //--- successful download
      //PrintFormat("File successfully downloaded, the file size in bytes  =%d.",ArraySize(result)); 
      //--- save the data in the file
      int filehandle=FileOpen("news-log.html",FILE_WRITE|FILE_BIN);
      //--- ïðîâåðêà îøèáêè 
      if(filehandle!=INVALID_HANDLE)
        {
         //---save the contents of the array result [] in file 
         FileWriteArray(filehandle,result,0,ArraySize(result));
         //--- close file 
         FileClose(filehandle);

         int filehandle2=FileOpen("news-log.html",FILE_READ|FILE_BIN);
         TXT=FileReadString(filehandle2,ArraySize(result));
         FileClose(filehandle2);
        }else{
         Print("Error in FileOpen. Error code =",GetLastError());
        }
     }

   return(TXT);
   
  }
 
ALI AMRIOUI:

i wana get GMT with WebRequest

can some one plz help

There are functions both for Gmt and the LocalGmtOffset , but regardless ,where is it failing ?

 
Lorentzos Roussos #:

There are functions both for Gmt and the LocalGmtOffset , but regardless ,where is it failing ?

yes i know ..but i have (EA nwes filter) and this EA give me the news with GMT time

i wana this  EA give me automaticly the news at time current  of my  mt4

 
ALI AMRIOUI #:

yes i know ..but i have (EA nwes filter) and this EA give me the news with GMT time

i wana this  EA give me automaticly the news at time current  of my  mt4

the filter will probably expect a timezone , that is a massive headache to resolve so get the news in gmt and turn to server time on "download"

To turn the gmt times to Time of the server you will need to have an input that receives the offset or try to synchronize when the ea is live.

Meaning  when  a tick is received (so market is live + broker is alive) you can pull a snapshot of the TimeCurrent and the TimeGMT and find the offset .

Your problem will then be weekends . So , for a given week you must store the time difference discovered live , or , update it everytime a new bar forms .

 
Lorentzos Roussos #:

the filter will probably expect a timezone , that is a massive headache to resolve so get the news in gmt and turn to server time on "download"

To turn the gmt times to Time of the server you will need to have an input that receives the offset or try to synchronize when the ea is live.

Meaning  when  a tick is received (so market is live + broker is alive) you can pull a snapshot of the TimeCurrent and the TimeGMT and find the offset .

Your problem will then be weekends . So , for a given week you must store the time difference discovered live , or , update it everytime a new bar forms .

thanks bro for u  help ..i will try that ..  and i hope will slove my prbleme

 
Lorentzos Roussos #:

the filter will probably expect a timezone , that is a massive headache to resolve so get the news in gmt and turn to server time on "download"

To turn the gmt times to Time of the server you will need to have an input that receives the offset or try to synchronize when the ea is live.

Meaning  when  a tick is received (so market is live + broker is alive) you can pull a snapshot of the TimeCurrent and the TimeGMT and find the offset .

Your problem will then be weekends . So , for a given week you must store the time difference discovered live , or , update it everytime a new bar forms .

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()


  {

  

int time1 = StringFind (GMT_Time(),"GMT" ) ;
string time2 = IntegerToString(time1);
datetime time3 = StringToTime(time2  );


Comment (time2);// get GMT time



   }


string  GMT_Time()
 {
string cookie=NULL;
string strUrl;
   string headers;
   string ret;  
   char post[] ,result[];
   int res, timeout=5000;
   ResetLastError();
   strUrl= "https://www.worldtimeserver.com/time-zones/utc/"  ; 
   
   res= WebRequest("GET",strUrl ,cookie,NULL,timeout,post,0,result,headers);
   if (res ==-1) { 
        Alert("Web-Error: ",GetLastError()," (4060 ERR_FUNCTION_NOT_CONFIRMED/Url not allowed)" );
        return("");
   } 
   ret = CharArrayToString(result,0,-1);  
   return(ret);
}

and i dont know why the result give me the local time 

 
2023.06.29 04:48:51.484 2022.01.02 22:06:56  webrequest37 EURUSD,M1: HTTP/1.1 200 OK
Cache-Control: private
Date: Thu, 29 Jun 2023 02:49:13 GMT
Content-Length: 298271
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/10.0
Set-Cookie: ASP.NET_SessionId=fh1luoj5dkq4p3fmicueodmr; path=/; HttpOnly
Set-Cookie: wtsID=1:wav6RHeqI0aMw9N1soHH4ehWzTWUrpTM:WTsKWnak5oLiApMuz9KRxcjp2BdUjzWb; expires=Fri, 30-Jun-2023 02:49:13 GMT; path=/
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET

this the result of headers

 
ALI AMRIOUI #:

and i dont know why the result give me the local time 

you are looking to extract this part ? 


 
A lot of complication for nothing, all these information can be obtained directly from MQL and available data.
 
Lorentzos Roussos #:

you are looking to extract this part ? 


yes i wana get this part but i cnat

 
Alain Verleyen #:
A lot of complication for nothing, all these information can be obtained directly from MQL and available data.

but GMT of MQL is attached to  the time of computer

if u have time local not correct u will have worrong GMT of MQL

Reason: