How to extract images from a website into the background MT4?

 
I need a way to extract images from a website into the background.

May I have a sample code or EA?

I don't want to copy files from the MQL folder. //Images//...

 
Use Webrequest to save to PC then load it to chart.
 
Trinh Dat:
Use Webrequest to save to PC then load it to chart.

Thank you.

But, I don't want to copy files from the MQL folder. //Images//...

 

Use this to download 

#property strict
input string image_url="https://upload.wikimedia.org/wikipedia/commons/4/43/07._Camel_Profile%2C_near_Silverton%2C_NSW%2C_07.07.2007.jpg";//image url (with file)
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
  // EventSetTimer(60);
  string temp_file_name="tempfilename.jpg";
  bool filepull=WRequest(wr_get,false,"","","",image_url,"",5000,true,temp_file_name,ft_bin);
    if(filepull)
    {
    Print("File Downloaded!");
    }
//---
   return(INIT_SUCCEEDED);
  }
void OnTick()
  {
//---
   
  }
enum wr_type
{
wr_get=0,//GET
wr_post=1//POST
};
enum fil_type
{
ft_txt=0,//TXT
ft_bin=1//BIN
};
bool WRequest(wr_type wrt,bool login,string user_name,string pass_word,string extra_fields,string url,string referer,uint timeout,bool write_to_file,string file_name,fil_type ftype)
{
string usernameid="user";//username field id
string passid="password";//password field id
string returnio="error";
string cookie=NULL,headers;
char post[],result[];
int res;
string target_url=url;
string specs=usernameid+"="+user_name+"&"+passid+"="+pass_word;//specs for get requests
if(login==true&&wrt==wr_get) target_url=target_url+"?"+specs;
char data[];
int data_size=0;
int slen=StringLen(specs);
if(wrt==wr_post) data_size=StringToCharArray(specs,data,0,slen,CP_UTF8);
ResetLastError();
string req_string="GET";
if(wrt==wr_post) req_string="POST";
res=WebRequest(req_string,target_url,cookie,referer,timeout,data,data_size,result,headers);
if(res==-1)
{
Print("Error in WebRequest. Error code  =",GetLastError());
MessageBox("Add the address '"+target_url+"' in the list of allowed URLs on tab 'Expert Advisors'","Error",MB_ICONINFORMATION);
return(false);
}
else
{
PrintFormat("The file has been successfully loaded, File size =%d bytes.",ArraySize(result));
int tit=ArraySize(result)-1;
string html="";
int fhandle=0;
if(write_to_file==true)
  {
  if(ftype==ft_bin) fhandle=FileOpen(file_name,FILE_WRITE|FILE_BIN);
  if(ftype==ft_txt) fhandle=FileOpen(file_name,FILE_WRITE|FILE_TXT);
  } 
for(int xx=0;xx<=tit;xx++)
{
string wri=CharToStr(result[xx]);
if(write_to_file==true)
  {
  if(ftype==ft_txt) FileWriteString(fhandle,wri);
  if(ftype==ft_bin) FileWriteInteger(fhandle,result[xx],CHAR_VALUE);
  }
html=html+wri;
}
returnio=html;
if(write_to_file==true) FileClose(fhandle);
return(true);
}  
}
 
Lorentzos Roussos #:

Use this to download 

Hi Lorentzos,

How to put a picture on chart like this?

This is an EA on market.

I think the picture should be in web and author use WebRequest() to copy on PC and then show the photo.

but I didn't add any photo address to "allowed URLs list".

appreciate it if you can guide me.


 
FFF MM #: How to put a picture on chart like this? This is an EA on market. I think the picture should be in web and author use WebRequest() to copy on PC and then show the photo. but I didn't add any photo address to "allowed URLs list". appreciate it if you can guide me.

Forum on trading, automated trading systems and testing trading strategies

How can I save a photo from the web to my PC in MQL4?

Fernando Carreiro, 2022.08.19 19:13

Use DLL calls to the Windows API for HTTP network interactions. That is what was done before WebResquest even appeared in MQL. There are many forum posts, codebase publications and articles from those days. Start there.
EDIT: Only realised now that it is for a Market product, so DLL calls are not allowed. You will have no other option than to use WebRequest and have the user allow the URL in the terminal options.
 
FFF MM #:

Hi Lorentzos,

How to put a picture on chart like this?

This is an EA on market.

I think the picture should be in web and author use WebRequest() to copy on PC and then show the photo.

but I didn't add any photo address to "allowed URLs list".

appreciate it if you can guide me.


Yeah if its on the market the user will need to add your url in their allowed urls . 

Furthermore if you are loading a volume profile image (likely) you will then need to adjust it to the users screen too , not to mention the zoom levels , time range and price scale of the charts .

You are better of at sending the actual data in that case . 

Now if you are willing to load advertisements on the EA that is another story , but i think its not allowed in the market. 

Reason: