【问题标题】:How to get a value from Custom Indicator with zmq?如何使用 zmq 从自定义指标中获取值?
【发布时间】:2022-01-06 16:51:47
【问题描述】:

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

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

【问题讨论】:

    标签: python zeromq algorithmic-trading mql4 pyzmq


    【解决方案1】:

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

    您的MQL4-side ExpertAdvisor 代码或Script不是 CustomIndicator 之一)必须首先导入 DLL。然后,您的 EA 代码将能够zmq_bind() 并接收远程 python 代码 .connect()-s,或(相反地)zmq_connect() 到远程 python 代码 .bind()-exposed ZeroMQ's接入点地址(通过任何可行的传输类{ tcp:// | pgm:// | epgm:// | vmci:// | ... }(取决于在 DLL 包装器中实现的 ZeroMQ API 版本('ve been using a v2.11 one)和选定的 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);
      }
    

    【讨论】:

    • 你的意思是在我的 EA 代码上导入 libsodium.dll 和 libzmq.dll ?
    • 使用v2.11 DLL的详细信息在上面的链接中,奥斯汀康拉德的DLL详细信息在这里(github.com/AustenConrad/mql4zmq
    • 谢谢我已经完成了那个案子!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-17
    • 1970-01-01
    • 2021-03-13
    • 2021-10-24
    • 2019-02-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多