Download signal history from script using WebRequest

 

I am trying to download the signal history using WebRequest function and the following function

bool SavePageFromInternet(string url, string filename){
   string cookie=NULL,headers; 
   char post[],result[]; 
   int res;
   bool returnResponse = true;
   ResetLastError(); 
   int timeout=5000;
   res=WebRequest("GET",url,cookie,NULL,timeout,post,0,result,headers); 
   
   //--- Checking errors 
   if(res==-1){ 
      Print("Error in WebRequest. Error code  =",GetLastError()); 
      returnResponse = false;         
   } 
   else{ 
      PrintFormat("The file has been successfully loaded, File size = %d bytes.",ArraySize(result)); 
      int filehandle=FileOpen(filename,FILE_WRITE|FILE_BIN); 
      if(filehandle!=INVALID_HANDLE){ 
         FileWriteArray(filehandle,result,0,ArraySize(result)); 
         FileClose(filehandle); 
        } 
      else {
         Print("Error in FileOpen. Error code=",GetLastError());
         returnResponse = false;
      }
     } 
     
     return returnResponse;
}

So I use as the url the address "https://www.mql5.com/en/signals/"+string(signal_number)+"/export/trading" as source, but the .csv file is not downloading. Instead, it saves the signal html page.

Thus, how could I do it properly?

 

Hi Pablo Rego,

I checked the result of your download. The content of the file created is a html page, if you change the extention to html and open it in a browser, you will see the login page of MetaQuotes.

Probably you have to login first.