MT4通讯方式

MT4 communication methods

我试过了,但我自己想不出来。

我知道 MT4 提供 Pipe 和 WebRequest() 作为一种通信方式,但 WebSocket 并不是作为编程的一部分构建的。所以目前,Pipe 是唯一可用的。但是与 Pipe 的通信有时会中断。它在发送时会跳过一些信号。

请问我该如何解决这个问题?

MQL 中的管道是通过文件实现的,因此您可以使用文件而不是管道 - 您将收到相同或更快的结果,并且无需关心通信

How can I get around this please guys ?

免费使用 ZeroMQ 或 nanomsg 信号/消息传递框架

多年前就有这样的需求,开始使用 ZeroMQ / MQL4 绑定,以便让 MetaTrader 终端在 QuantFX 分析和基于 ML 的增强交易系统中工作。

没有 O/S 仅限本地主机的管道,没有基于文件的伪装,而是公平、分布式、低延迟 signalling/messaging,具有:

  • 远程键盘/终端系统控制台(是的,添加了 DSL 命令语言)
  • 远程集中日志(避免 MQL4 执行因资源争用而受阻)
  • 分布式远程AI/ML-predictive引擎,延迟低于<< 80 [ms] RTT
  • 分布式远程自动化交易管理处理

ZeroMQ 是一种可行的方法,如果集成需要保持在您自己的设计控制之下。在 [ ] 部分

中提供了一个简短的草图。

欢迎阅读更多 posts on this and about the differences between WebSockets and ZeroMQ here, in the 和其他相关帖子。

我试过 ZeroMQ,但无法正常工作。 我现在正在使用 WinSockets,到目前为止没有遇到任何问题。

参见:https://www.mql5.com/en/blogs/post/706665 在这里,您将找到一种在 MQL 中将 WinSockets 用作服务器或客户端或两者的方法。 我知道链接可能会失效,但无法将文件附加到此答案,而且代码格式不正确,因此我无法包含它。

然后您可以使用任何也支持套接字的编程语言与您的 MQL EA 通信。我正在使用内置节点实现。 参见:https://www.digitalocean.com/community/tutorials/how-to-develop-a-node-js-tcp-server-application-using-pm2-and-nginx-on-ubuntu-16-04

const net = require('net');
const port = 7070;
const host = '127.0.0.1';

const server = net.createServer();
server.listen(port, host, () => {
    console.log('TCP Server is running on port ' + port + '.');
});

let sockets = [];

server.on('connection', function(sock) {
    console.log('CONNECTED: ' + sock.remoteAddress + ':' + sock.remotePort);
    sockets.push(sock);

    sock.on('data', function(data) {
        console.log('DATA ' + sock.remoteAddress + ': ' + data);
        // Write the data back to all the connected, the client will receive it as data from the server
        sockets.forEach(function(sock, index, array) {
            sock.write(sock.remoteAddress + ':' + sock.remotePort + " said " + data + '\n');
        });
    });

    // Add a 'close' event handler to this instance of socket
    sock.on('close', function(data) {
        let index = sockets.findIndex(function(o) {
            return o.remoteAddress === sock.remoteAddress && o.remotePort === sock.remotePort;
        })
        if (index !== -1) sockets.splice(index, 1);
        console.log('CLOSED: ' + sock.remoteAddress + ' ' + sock.remotePort);
    });
});