I've lost count of how many times I've seen that red "DLL imports are not allowed" error pop up right when you're about to launch a new Expert Advisor. It's frustrating because most of the time, you've done everything right—compiled the EA, placed it in the right folder, and even double-checked the code. And yet, MetaTrader just refuses to cooperate.
Let me walk you through how I actually solve this, based on a few dozen times of banging my head against the table.
Step 1: The Obvious (but often overlooked) setting
The first thing I do is navigate to Tools > Options > Expert Advisors. Under the "Allow automated trading" checkbox, there's a specific option: "Allow DLL imports." Make sure it's checked. This is the first gatekeeper.
But here's the catch: checking this box doesn't always work, especially on Windows 11. I've noticed that if your EA uses a third-party DLL (like one for database connectivity or advanced mathematical functions), MetaTrader might still block it. The official MQL5 documentation (docs.mql5.com) states that the
#import directive loads the DLL, but it doesn't go into detail about Windows-level permissions. That's where the real issue lies.Step 2: The Hidden Windows Permission Wall
This is where I stumbled onto something that isn't explicitly stated anywhere. On Windows 10, I used to just run MetaTrader as an administrator and everything worked. On Windows 11, even as admin, the EA sometimes fails to load because of Core Isolation and Memory Integrity features. These security settings can block unsigned DLLs from being loaded into the terminal process.
The workaround? I add the entire
MQL4\Libraries folder to the Windows Defender exclusion list. Not just the DLL file itself, but the whole folder. Here's how:C:\Users\[YourUserName]\AppData\Roaming\MetaQuotes\Terminal\[TerminalID]\MQL4\Libraries\.Note: If your terminal data folder is in a different location (like if you installed it on a separate drive), you'll need to point to that specific folder.
Step 3: The "Portable" Version Quirk
If you're running the portable version of MT4 (the one that doesn't require installation), you have an entirely different set of problems. The terminal doesn't register itself with Windows the same way, so the DLL loading mechanism can be more restrictive. I've had to manually add the entire portable folder to the exclusion list AND run the terminal as administrator.
Step 4: A Quick Test
Before you go nuts adjusting settings, do this quick test: open the
Experts tab in the Terminal window at the bottom. If you see "DLL function call failed" along with the function name, you've got a permission issue. If you see "cannot open file" or "file not found," the DLL isn't actually in the Libraries folder. Double-check the file name—case sensitivity matters.Reference: MetaQuotes MQL5 Documentation. "DLL Import." docs.mql5.com.
Reference: Microsoft Support. "Windows 10 and 11 Core Isolation." support.microsoft.com.
本文首发于FXEAR.com,原创内容,未经授权禁止转载。