Skip to content
All library documents

Using Protocol Buffers to Bridge MQL5 Inference Calls to a Python gRPC Server

Article MQL5 articles

Summary

The article presents an architecture for sending live MetaTrader 5 feature vectors to a Python model service. Since MQL5 does not natively support gRPC’s HTTP/2 transport, the design uses a hand-written Protocol Buffers encoder and length-prefixed TCP messages from the Expert Advisor to an asyncio Python shim. The shim forwards requests to a genuine gRPC model server, which supports unary and streaming inference.

A shared schema defines the feature vector, request, response, and model version fields, while the MQL5 client mirrors the field numbers manually. The article also describes framing, retries, response parsing, consistency checks, and a cached inference path for Strategy Tester use. It includes a transport benchmark and identifies TLS, direct stream use from MQL5, and a properly trained and validated model as future work. The bridge enforces message structure, but does not itself establish model quality or trading performance.

Key ideas

  • MQL5 sends length-prefixed Protocol Buffers messages over TCP to a Python relay.
  • The relay forwards requests to a Python server using actual gRPC over HTTP/2.
  • A shared schema defines message fields, but MQL5 field numbers must be kept aligned manually.
  • The design includes retries, a feature-count consistency check, and cached inputs for Strategy Tester use.
  • Transport benchmarks do not validate the model’s predictive quality or trading results.

Tags

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