Metatrader 4 to Binary.com

 

Goodmorning

i made a code in javascript that if i visit this page from browser it open a position in binary.com.

But if i made a webrequest from mt4, it doesn't work also if i get result 200 on webrequest and 4000 error of mt4.

Some one can help me? 

  string params="";
      char data[];
      int timeout=5000;
      string url="http://www.mywebsite.it/index.html";
      int data_size=StringLen(params);
      StringToCharArray(params,data,0,data_size);

      uchar result[];
      string result_headers;

      //--- application/x-www-form-urlencoded
     int res=WebRequest("GET",url+params,NULL,NULL,timeout,data,data_size,result,result_headers);
     Alert("Res  "+res+"  Error code =",GetLastError());
Files:
 

You must first set permissions on MetaTrader's Options in order to allow access to that website. Go to the "Tools->Options" (or Ctrl+O) and then go to the "Expert Advisors" tab. At the very end of those options, to will find and have to enable the "Allow WebRequest for the listed URL:" and then proceed to add the URL of the site.

NB! Also, depending on the data being retrieved, you may need to use the 2nd version of WebRequest as the first one is only valid for form data (Content-Type: application/x-www-form-urlencoded).

WebRequest

2. Sending a request of any type specifying the custom set of headers for a more flexible interaction with various Web services.

int  WebRequest(
   const string      method,           // HTTP method
   const string      url,              // URL
   const string      headers,          // headers 
   int               timeout,          // timeout
   const char        &data[],          // the array of the HTTP message body
   char              &result[],        // an array containing server response data
   string            &result_headers   // headers of server response
   );
 
FMIC:

You must first set permissions on MetaTrader's Options in order to allow access to that website. Go to the "Tools->Options" (or Ctrl+O) and then go to the "Expert Advisors" tab. At the very end of those options, to will find and have to enable the "Allow WebRequest for the listed URL:" and then proceed to add the URL of the site.

Also, depending on the data being retrieved, you may need to use the 2nd version of WebRequest as the first one is only valid for form data (Content-Type: application/x-www-form-urlencoded).

I added the url at list yet but doesn't work.  

Now doesn't matter data retrieved, also if don't come back nothing is good. The important is to open the position. How you programm the second version on this code?

 

 
duddas90: I added the url at list yet but doesn't work. Now doesn't matter data retrieved, also if don't come back nothing is good. The important is to open the position. How you programm the second version on this code?
Please read the documentation on WebRequest. There is an example of coding both versions, so look at the 2nd example.
Reason: