Runtime error
4014 ERR_ FUNCTION_ NOT_ ALLOWED
Function not allowed: called where MQL5 does not permit it
What it means
A function was called from a program or context where it is not allowed. The reference names the classic case: "If you try to call the function from an indicator, GetLastError() will return error 4014" for WebRequest(), which is available only in Expert Advisors and scripts, because indicators share one thread per symbol.
Common causes
WebRequest()called from a custom indicator (for example, to send signals to a server or a messenger).- Code moved from an EA into an indicator without checking which functions indicators may use.
- Separately:
WebRequest()"cannot be executed in the Strategy Tester", and a server that is not in the allowed URL list makes it return -1.
A real scenario
A signal indicator posts each new arrow to a web service with WebRequest(). On the chart it never sends anything and the journal shows error 4014. The fix was to keep the indicator for drawing and move the sending into a small EA that reads the indicator's buffer with CopyBuffer() and calls WebRequest() itself.
How to fix it
- Call
WebRequest()only from an EA or a script; read the indicator's values there withiCustom()andCopyBuffer(). - Skip it in the Strategy Tester (
MQLInfoInteger(MQL_TESTER)). - Add the server to Tools > Options > Expert Advisors > allowed URLs; when the call returns -1, print
GetLastError()and that hint.
Fixed MQL5 code
// In an EA or a script, not in an indicator: WebRequest() is not available in indicators (error 4014).
bool PostSignal(const string url, const string json, string &reply)
{
if(MQLInfoInteger(MQL_TESTER))
return false; // WebRequest cannot run in the Strategy Tester
char body[], answer[];
string headers;
StringToCharArray(json, body, 0, StringLen(json), CP_UTF8);
ResetLastError();
int status = WebRequest("POST", url, "Content-Type: application/json\r\n", 5000, body, answer, headers);
if(status == -1)
{
PrintFormat("WebRequest failed, error %d: is %s in Tools > Options > Expert Advisors > allowed URLs?", GetLastError(), url);
return false;
}
reply = CharArrayToString(answer, 0, WHOLE_ARRAY, CP_UTF8);
return status >= 200 && status < 300;
}
A focused example for MetaTrader 5: adapt names, magic number and limits to your EA, and test it on a demo account first.
Related codes
- 4109Chart Property or Trade Not AllowedERR_CHART_WRONG_PROPERTYA wrong chart property (MQL5), trade not allowed (MQL4)
- 4752Trading by EAs ProhibitedERR_TRADE_DISABLEDTrading by Expert Advisors prohibited
EA Doctor rules that catch it
- LowTimer started but never stoppedThe EA starts a timer with EventSetTimer() but never calls EventKillTimer(), which the MQL5 reference pairs with it in OnDeinit().
Sources
Get your EA fixed
Still failing with 4014? Send us the EA and the journal lines: we find the cause in the code and fix it. Or check it yourself first with the EA Doctor.