Skip to content
All library documents

Building an OpenCL DLL for MQL5 and Linux

Article MQL5 articles

Summary

This article shows how to package OpenCL operations in a C++ DLL that can be called from MQL5, as a step toward adding GPU computation to MetaTrader programs. The example exposes functions to enumerate available OpenCL platforms and devices and to add two integer arrays on a selected GPU. It also describes building for Windows, testing natively on Linux, and using the library from a MetaTrader script.

A key interoperability detail is converting returned text to UTF-16 so MetaTrader displays it correctly. The computation flow selects a platform and GPU, creates a context, queue, program, kernel, and buffers, then reads the result back to host memory. The article reports a successful test script that checked the output array. This is a small demonstration rather than evidence of trading-system speed gains: it uses a simple addition kernel, selects the first available platform and GPU, and does not provide a comparative performance analysis. The approach also depends on compatible OpenCL drivers and DLL setup.

Key ideas

  • A C++ DLL can expose OpenCL device discovery and computation functions to MQL5.
  • Strings returned for MetaTrader display need conversion to UTF-16.
  • The example passes arrays through host-backed buffers and explicitly reads computation results back to host memory.
  • The successful addition test demonstrates integration, not the performance benefit of GPU processing for trading workloads.

Tags

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