Directory of RSS feeds

RSS feeds in the directory: 2817

Added today: 0

Added yesterday: 0

Business / Finance

MQL4: study method WebRequest

Portal Forex trader 21.05.2019 at 12:16

Forex trading strategies, expert advisors, indicators, video training trade


Not so long ago in a lesson about the open positions of traders we took data from the website online. What we did in the lesson, can be done another way without using a dll, therefore, without depending on the operating system.

All you need is Metatrader 4 and mql code editor. Also the knowledge of mql4 standard method of WebRequest, which we are today and let's get acquainted.

the Method WebRequest

the Method of the WebRequest can be caused by two ways. The first suit to send simple queries to the server with standard http headers. It looks like this:

int WebRequest(

, const string method, // HTTP method

const string url, // url

const string cookie, // cookie

const string referer, // referer

int timeout, // timeout

const char &data;[], // array of the body of an HTTP message

int data_size, // size of array data[] in bytes

char &result;[], // array with the data server response

string &result;_headers // server response headers


the Second option allows you to fill in the array headers. It is useful in various difficult situations, for example, when you need to send to the server files.

int WebRequest(

, const string method, // HTTP method

const string url, // url

const string headers, // headers

int timeout, // timeout

const char &data;[], // array of the body of an HTTP message

, char &result;[], // array with the data server response

string &result;_headers // server response headers


the method can be any HTTP method. In this video lesson we will look at using the GET method;

the url of the server to which you are applying;

cookie, respectively, of cookies, for example, to login to the server;

referer — the value of the Referer header of the HTTP request;

timeout — a timeout in milliseconds, that is, the waiting time for a response from the server;

headers — your custom headers. When using the first variant of the method call automatically default the request is sent with header: Content-Type: application/x-www-form-urlencoded.

In the case of the browser, the header can look like this, for example:

GET /tutorials/ HTTP/1.1


User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv: Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: en-us,en;q=0.5

Accept-Encoding: gzip,deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive: 300

Connection: keep-alive

Cookie: PHPSESSID=r2t5uvjq435r4q7ib3vtdjq120

Pragma: no-cache

Cache-Control: no-cache

In our case, to send the file need a header:

Content-Type: multipart/form-data; boundary=--WebKitFormBoundaryePkpFF7tjBAqx29l

Content-Disposition: form-data; name="uploadedfile"; filename="hello.tlap" Content-Type: application/x-object

But sending files is quite a rare task, more often us from mql4 programs, you just need to get some data.

the method WebRequest returns an int that is the number. This number is nothing like the response code from the server, or -1 in case of error, execution of the method. Response code is a three digit number. Currently there are five classes of codes:

1xx: Informational — request received and understood, and processing continues;

2xx: Success — the request was successfully received, understood and processed;

3xx: Redirection — for-query execution needs to be further action taken;

4xx: Client Error — the request has bad syntax or cannot be fulfilled;

5xx: Server Error — the server is unable to fulfil a valid request.

Here are a couple of the most common examples are:

200 OK — Successful request. If the client requested any data that they are in the header or body of the message. This code comes in case of success;

301 Moved Permanently. The requested document has been permanently moved to a new URL specified in the Location header. This code means that the page was moved and is now available at a different address;

400 Bad Request. The request is not understood by the server due to the presence of syntax errors. This means that at query time, there is a misprint;

401 Unauthorized. The request requires user authentication. This code means that you first need to login — enter the username and password from the website;

403 Forbidden. The server understood the request, but he refuses to perform due to some restrictions to access;

404 Not Found. The server understood the request, but have not found the appropriate resource at the specified URL. Most often this code indicates that the page was simply deleted,

500 Internal Server Error. Any internal server error, which is not included in the scope of other error class 5xx.

In reality, of course, a lot more codes. In each class they are usually from a dozen to several dozen, but the result here makes no sense, especially because this information can be found in their network. I brought only the most common response codes.

don't forget to add the address of the website in the list of allowed URLs in the terminal, otherwise it will not work. To do this, press Ctrl+O or click on tools->options->tab expert advisors.

Settings should be similar to those depicted in the picture above.

In their work, it is worth considering that the method of the WebRequest waits for a response from the server, and while the answer didn't come, the further script execution is impossible. Therefore, in the indicator, this method cannot be used. Also, keep in mind that the execution of the method takes time, and during this time a script or EA to do anything no more. Especially this specificity should be considered when you are sending massive requests or get the tough answers, for example, are bulky files with any data.


Today we discussed the WebRequest method that provides a fairly simple way of interaction between your advisors and scripts with the outside world. Using this method you can obtain web page, download, and upload files in the manipulation in the automatic mode, and more.

this method is really limitless, especially if you don't know other programming languages. It can be used to solve and it is not trading objectives, for example, to make autoclicker or to emulate any other useful work, bringing money. Fun idea, but if you work hard, you can write your autosurfer that will for you to earn clicks at a time until your main bots merge the Deposit, — a trifle, but nice.

to Download the source script from lesson

forum Topic

best regards, Dmitry aka Silentspec