.NET Framework and EA Support
Relevant source files
The following files were used as context for generating this wiki page:
The MetaTrader5 Docker environment provides robust support for Expert Advisors (EAs), including those with dependencies on the Windows .NET Framework. This support is achieved through a specialized Wine environment that replaces older Mono implementations with native Windows .NET Framework 4.8 capabilities when required. The architecture ensures that EAs, indicators, and scripts can execute in an isolated Linux container while maintaining compatibility with Windows-native binaries.
Support for EAs is a core feature of the v2.2.x fork, transitioning from an Alpine base to a Debian-based architecture to accommodate the larger Wine and .NET footprints required for production-ready trading bots.
Sources: README.md:14-17, README.md:43-51, README.md:65-68
Architecture and Environment Configuration
The environment leverages a Wine 10.0 base on Debian Bookworm to provide a high-fidelity Windows execution layer. For EAs specifically requiring .NET, the system utilizes winetricks to install .NET Framework 4.8 into the persistent Wine prefix.
Core Support Components
| Component | Description | Configuration Variable |
|---|---|---|
| Wine Mono | Provides initial .NET support and is included by default in the prefix build. | WINE_MONO_VERSION |
| Windows .NET 4.8 | Optional native framework installed via winetricks for EAs that fail under Mono. | ENABLE_WIN_DOTNET |
| SYS_PTRACE | Required Linux capability for MetaQuotes protection mechanisms in EAs. | N/A (Docker cap_add) |
| Seccomp | Set to unconfined to allow specific Windows-style syscalls used by MT5/EAs. | N/A (Docker security_opt) |
Sources: docker/compose.yaml:5-15, docker/compose.yaml:104-108, README.md:175-180
Dependency Flow for EA Execution
The following diagram illustrates how the container prepares the environment to support EAs from initial boot through framework installation.
The diagram shows the sequential setup where .NET 4.8 is conditionally installed based on environment variables before MT5 execution begins.
Sources: docker/container/metatrader/setup.sh:86-120, docker/compose.yaml:70, README.md:175-180
EA Deployment and Persistence
Expert Advisors, indicators, and scripts are managed through a persistent volume mapped to /config. This ensures that compiled binaries (.ex5) and source code (.mq5) persist across container restarts.
File Locations
Within the container, the MQL5 folder structure is located at:
C:\Program Files\MetaTrader 5\MQL5
In the host-mapped volume, this corresponds to:
config/.wine/drive_c/Program Files/MetaTrader 5/MQL5
Users can access the MetaEditor program via the IDE button in the MT5 interface (rendered via KasmVNC) to compile or modify EAs directly within the environment.
Sources: README.md:195-207, docker/container/metatrader/setup.sh:227-230
Security and System Permissions
For EAs to function correctly—particularly those utilizing MetaQuotes protection or complex DLL imports—specific container permissions are mandatory.
- SYS_PTRACE Capability: This is required for MetaTrader 5 to monitor its own processes and is often necessary for EAs to initialize properly.
- Unconfined Seccomp Profile: MetaTrader 5 and certain EAs perform low-level operations that are blocked by the default Docker seccomp profile.
- File Descriptor Limits: The
ulimitsfornofileare increased to65536to handle the high volume of concurrent file handles required by Wine and active trading EAs.
Sources: docker/compose.yaml:94-108, tests/test_static.py:339-343
Health Monitoring and Recovery
The system includes a health_monitor.sh script that provides auto-recovery for the MT5 terminal. This is critical for EAs, as it ensures the terminal is restarted if it crashes or stops responding.
The sequence shows the transition from failure detection to automated recovery using the RESTART_TOKEN mechanism.
Sources: docker/container/metatrader/health_monitor.sh, tests/test_static.py:448-460, README.md:255-257
EA Compatibility and MQL5 Support
The project supports full Wine environment execution for native MQL5 programs. Even if Python integration is not required, the Debian-based image provides a stable platform for EAs.
MQL5 Integration Parameters
EAs are enabled by default through the startup.ini generation, which includes the following [Experts] configuration:
[Experts]
AllowLiveTrading=1
AllowDllImport=1
Enabled=1
Account=0
Profile=0
Sources: docker/container/metatrader/setup.sh:317-322, tests/test_static.py:382-386
Support Tiers
| Feature | Support Level | Requirement |
|---|---|---|
| Native MQL5 EAs | Full | Base Wine Prefix |
| .NET-dependent EAs | Full | ENABLE_WIN_DOTNET=1 |
| DLL Imports | Full | AllowDllImport=1 and SYS_PTRACE |
| MetaEditor (IDE) | Full | KasmVNC / Browser Access |
Sources: README.md:175-180, docker/compose.yaml:70, docker/container/metatrader/setup.sh:317-322
Summary
The ".NET Framework and EA Support" module ensures that MetaTrader 5 is not just a trading terminal, but a fully functional automated trading host. By providing native .NET 4.8 installation via winetricks and granting necessary system capabilities like SYS_PTRACE, the project enables high-compatibility execution of complex Expert Advisors that would otherwise fail in standard Wine environments. Persistence is maintained through the /config volume, while health monitoring ensures continuous uptime for automated strategies.