Testing WebRequest on MT5
Testing WebRequest on MT5
Loading saved threads...
Woody1193 · External communityPost link
External question — Stack Overflow Stack Exchange
Author: Woody1193
Original post: https://stackoverflow.com/questions/75292676
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I have an MQL5 object that sends a web request to a webserver:
class OrderSendMaster {
private:
string m_addr; // The endpoint of the server we'll send trade requests to
public:
OrderSendMaster(const string addr) : m_addr(addr) {};
int Disperse(const MqlTradeRequest &request);
};
int OrderSendMaster::Disperse(const MqlTradeRequest &request) {
// First, convert the trade request to JSON and write that to our buffer
char req[];
int len = ConvertToJSON(request, req);
// Next, attempt to send the JSON data to our web server; if this fails then return an error
char result[];
string headers;
int res = WebRequest("POST", m_addr, "", "", 1000, req, len, result, headers);
if (res == -1) {
res = GetLastError();
}
PrintFormat("Response Code: %d, Headers: %s, Response: %s", res, headers, CharArrayToString(result));
// Finally, return 0 to indicate that all the operations succeeded if we got a 200 response code
// Otherwise, return the response code we received
return res == 200 ? 0 : res;
}
The issue I'm having is that, when testing the Expert I added it to, the function always returns an error code of 4014. I have followed the
documentation
and added the URL to
Options > Expert Advisors > Allow Web Requests
and this code is not used by anything except the EA I'm testing. Judging by what I've seen on the MQL5 forums
here
,
here
and
here
; the issue appears to be a problem with expert testing but I haven't seen any confirmation of that. Does anyone know why this issue is occurring and any workarounds or fixes for it?
Quote
Report
Ramzy · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: Ramzy
Original post: https://stackoverflow.com/a/76067614
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
As per the
documentation
WebRequest() cannot be executed in the Strategy Tester which is written in both MQL4 and MQL5 documentation but still working in MQL4.
If you tested your EA in chart and still didn't work, try using a hostname instead of loopback address or the localhost as this solution worked for me.
Quote
Report
Ishmael Mavor Raines · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: Ishmael Mavor Raines
Original post: https://stackoverflow.com/a/79416907
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
Did u check firewall issue? But if it persist mt5 error 401(permission issue) then they likely blocked it. 10 requests per minute according documentation. No explanation and lots of frustration when ur fixing and testing. I guess metatrader assume error 401 = "blocked for sending too many request"? interesting. Anyway just speculating till somone find out. Use delay timer in code or reinstall mt5.
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External answer — Stack Overflow Stack Exchange Author: Ramzy Source score (net votes, not local likes): 1 Original post: https://stackoverflow.com/a/76067614 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. As per the documentation WebRequest() cannot be executed in the Strategy Tester which is written in both MQL4 and MQL5 documentation but still working in MQL4. If you tested your EA in chart and still didn't work, try using a hostname instead of loopback address or the localhost as this solution worked for me.
Checking account access…