如何使用 zmq 从自定义指标中获取值?

How to get a value from Custom Indicator with zmq?

我有一个 MQL4 自定义指标,我制作了 EA(智能交易系统)以将数据输入 MetaTrader 终端 4 (mt4)。

但是,如何将我的自定义指标 EA 导入客户端 zmq 以获取值?

Q : But, how can I import my custom indicators EA to client zmq to get the value ?

您的 MQL4ExpertAdvisor 代码或 Script ( 不是 CustomIndicator one) 必须先导入一个 DLL。然后您的 EA 代码能够 zmq_bind() 并接收远程 python-代码 .connect()-s,或者(相互)zmq_connect() 到远程 python-code .bind()-暴露的 ZeroMQ 的访问点地址(通过任何可行的传输-class { tcp:// | pgm:// | epgm:// | vmci:// | ... }(取决于 ZeroMQ API-版本在DLL 包装器('ve been using a v2.11 一个)和选定的 ZeroMQ 可扩展正式通信模式原型)

完成以上草图互连元平面的任何形式或形状后,您的代码可以 zmq_send() / zmq_receive() 在您选择实现的任何场景中获取数据。只需序列化/反序列化数据并 zmq_send() 它们。

extern string ZMQ_transport_protocol = "tcp";
extern string ZMQ_address            = "192.168.0.386";
extern string ZMQ_outbound_port      = "1985";

// Include the libzmq.dll abstration wrapper.
#include <mql4zmq.mqh>


...
//+------------------------------------------------------------------+
int init()
{
   int major[1],
       minor[1],
       patch[1];

   zmq_version( major, minor, patch );

   Print( "Using ZeroMQ version " + major[0] + "." + minor[0] + "." + patch[0] );
   Print( ping( "Hello World" ) );
   
   Print( "NOTE: to use the precompiled libraries you will need to have the Microsoft Visual C++ 2010 Redistributable Package installed. To Download: http://www.microsoft.com/download/en/details.aspx?id=5555" );
   
   context = zmq_init( 1 );
   speaker = zmq_socket( context, ZMQ_PUB );
   
   outbound_connection_string =         ZMQ_transport_protocol
                              + "://" + ZMQ_server_address
                              + ":"   + ZMQ_outbound_port;

   if ( zmq_connect( speaker, outbound_connection_string ) == -1 )
   {
      Print( "Error connecting the speaker to the listener's address:port!" );
      return( -1 );
   }
   return( 0 );
}

//+------------------------------------------------------------------+
//| Script start function -OR- re-use as an Expert Advisor int OnTick(...){...} template
//+------------------------------------------------------------------+
int start()
{
   ...

// Publish current tick value + any iCustom(...) data

   string current_tick = "tick|" + AccountName() + " " + Symbol() + " " + Bid + " " + Ask + " " + Time[0];

   if ( s_send( speaker, current_tick ) == -1 )
        Print( "Error sending message: " + current_tick );
   else
        Print( "Published message: " + current_tick );

   return(0);
  }

//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
{
   Comment( "Going to tidy-up..." );

// Protect against memory leaks on shutdown.
   zmq_close( speaker );
   zmq_term(  context );

   return(0);
  }