MT5 error 4014: Function is not allowed for call (ERR_FUNCTION_NOT_ALLOWED)

The MQL5 function can't be called from this kind of program or in this context, such as WebRequest from an indicator.

4014ERR_FUNCTION_NOT_ALLOWED
After a fixSafe to retry?
Not a tradeCould it have executed?

What it means

You see this code in GetLastError() in MQL5, after a function fails.

Some MQL5 functions only work in certain program types or settings. When one is called where it isn't allowed, it fails and GetLastError() returns 4014.

The function itself is fine. The problem is where, or under what settings, it was called.

Common causes

  • WebRequest() or socket functions called from an indicator. Indicators can't use them.
  • WebRequest() to a URL that isn't in the allowed list under Tools, Options.
  • WebRequest() in the strategy tester, where network calls are blocked.
  • A trading function called from a program type that can't trade.

How to fix it

  • Move network or trading calls into a program type that allows them, such as a script or a trading program, and pass data to the indicator.
  • Add the exact URL, with its scheme, to the allowed list in the terminal options.
  • Skip network calls when MQLInfoInteger(MQL_TESTER) is true.

Example in MQL5:

string headers;
char   body[], reply[];
ResetLastError();
int status = WebRequest("GET", "https://example.com/ping", "", 5000, body, reply, headers);
if(status == -1)
{
   int err = GetLastError();
   if(err == 4014)
      Print("Not allowed here: add the URL under Tools > Options, and don't call it from an indicator or the tester");
   else
      Print("WebRequest failed, error ", err);
}

Is it safe to retry?

Only after you move the call or change the setting. The same call in the same place fails again.

Could the order have executed?

Not a trade code. If the blocked call was a trade function, nothing was sent.

All MetaTrader error codes

One API for MT4 and MT5

Clear trade outcomes, idempotent orders and an audit log. Read the error reference or the quickstart.