Downloading a file using a custom indicator

 

Hi,

I've written a custom indicator that uses data from a csv file located in ../experts/files/ folder, and I've got it working great for my needs.

However, the source csv file changes each day, which means me downloading it and placing it in the correct location.

I've searched extensivly but cannot find out how to get the indicator to download the source csv file from a web address and place it in the default folder.

Can anyone point me in the right direction.

Thanks for any help.

PaulB

 
Use a windows batch file to do the download . . . google for methods.
 

Thanks, I had thought of that, but wanted to include the function within the indicator so I could distribute it as a standalone solution.

 
There was someone on here trying to send stuff to a web address recently, that might help you . . maybe . . have a look here: https://www.mql5.com/en/forum/103484
 

Thanks for the info. Managed to sort it with some code I found elsewhere. For information, it is as follows:

#property copyright "Integer"
#property link "for-good-letters@yandex.ru"

#import "wininet.dll"
#property show_inputs

#define INTERNET_FLAG_PRAGMA_NOCACHE 0x00000100

#import "wininet.dll"

int InternetOpenA(string sAgent, int lAccessType, string sProxyName = "", string sProxyBypass = "", int lFlags = 0);
int InternetOpenUrlA(int hInternetSession, string sUrl, string sHeaders = "", int lHeadersLength = 0, int lFlags = 0, int lContext = 0);
int InternetReadFile(int hFile, int& iBuffer[], int lNumBytesToRead, int& lNumberOfBytesRead[]);
int InternetCloseHandle(int hInet);

extern string url = "http://www...../.......csv?111565";
extern string FileName = "....csv";

int start()
{
int hInternetSession = InternetOpenA("Microsoft Internet Explorer",0,"","",0);
if(hInternetSession <= 0)
{
Print("Opening Internet FAILED...");
return(-1);
}
string temp;
int iBuffer[256];
int dwBytesRead[1];
int hURL = InternetOpenUrlA(hInternetSession, url,"",0,INTERNET_FLAG_PRAGMA_NOCACHE,0);
if(hURL >0)
{
int fh = FileOpen(FileName,FILE_BIN|FILE_WRITE);
if(fh>=0) {
while(True) {
if(!InternetReadFile(hURL, iBuffer, ArraySize(iBuffer)*4, dwBytesRead)) {
Alert("InternetReadFile Error!");
break;
}
if(dwBytesRead[0]==0) break;
for(int i=0; i<dwBytesRead[0]; i++) {
int byte = (iBuffer[i/4] >> ((i & 3)*8)) & 0xff;
FileWriteInteger(fh,byte,CHAR_VALUE);
}
}
FileClose(fh);
}
else Alert("Error opening file ",FileName);
InternetCloseHandle(hURL);
}
InternetCloseHandle(hInternetSession);
return(0);
}

 

Paul_B:

I've written a custom indicator that uses data from a csv file located in ../experts/files/ folder, and I've got it working great for my needs.

I've searched extensivly but cannot find out how to get the indicator to download the source csv file from a web address and place it in the default folder.

Indicators run in the GUI thread. If your indicator takes time to download, the entire terminal will be hung.

Create a separate program, perhaps scheduled.

Reason: