Skip to content
All library documents

Connecting MetaTrader 4 to MATLAB Through the MATLAB Engine

Article MQL5 articles

Summary

The article outlines a software architecture for running MATLAB calculations from MetaTrader 4 through MATLAB Engine, using a C++ DLL wrapper as the bridge. It organizes the work into three parts: develop the MATLAB function, build the wrapper, and write the MQL4 program. The wrapper starts the MATLAB desktop, transfers numerical arrays as MATLAB matrices, evaluates commands, retrieves results, and releases arrays and the engine when finished. The article uses a high-frequency filter as its example calculation and mentions a filtered MACD indicator.

It also explains interface constraints, including exported functions’ calling convention, array passing by reference, memory cleanup, and file placement. The author favors the engine approach for compatibility across MATLAB versions and shared use by multiple trading programs, while acknowledging startup delay and deployment requirements. The discussion is tied to older MetaTrader 4 and MATLAB versions and a particular C++ compiler. It is integration guidance, not evidence that the example filter or indicator improves trading performance.

Key ideas

  • The proposed bridge runs MATLAB Engine through an exported C++ DLL wrapper.
  • The workflow separates MATLAB algorithm development, DLL integration, and MQL4 implementation.
  • Numerical data is transferred through MATLAB matrix objects, with explicit cleanup required.
  • MQL4 imposes constraints on DLL function signatures and array handling.
  • The article describes integration mechanics but provides no evidence of trading edge.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.