Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Metaquotes MQL 5 - API

    General Code/Help
    7
    18
    3451
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Nikolai
      Nikolai last edited by Nikolai

      Hi, everyone.

      We moved our strategy prototype development to backtrader. I decided to write an API for Metaquotes MQL5 based on ZeroMQ socket framework. Thanks to @ed-bartosh and @sandro-böhme for CCXT broker code examples.

      This is first alfa release. The code is not stable yet but historical/live datas work already. Next week we will start strategy testing. So, I think that stable beta will be in a few weeks.

      https://github.com/khramkov/MQL5-JSON-API
      https://github.com/khramkov/Backtrader-MQL5-API

      All ideas and improvements are welcome. I'll post updates here.

      1 Reply Last reply Reply Quote 5
      • Nikolai
        Nikolai last edited by Nikolai

        I have released stable beta MQL5 JSON API. Most part of the documentation is also ready. See it on github.

        Backtrader MQL broker stable beta is almost ready too. Don't use alfa release of the broker. The code would not work because MQL side was refactored.

        1 Reply Last reply Reply Quote 5
        • Nikolai
          Nikolai last edited by

          Hello everyone,

          I have released Backtrader-MQL5-API stable beta. MQL5 has complex order management logic, so i have some headache implementing it to backtrader. )) Only market orders working right now. It will take some time to finish pending orders.

          self.position doesn't work too. Because of threading next happens several times before position approval returns from MQL5. @backtrader Do you have any idea how to fix it? Thanks.

          1 Reply Last reply Reply Quote 1
          • C
            cgd last edited by

            Hey Nikolai!

            This is fantastic news, thank you so much! :)

            1 Reply Last reply Reply Quote 1
            • Nikolai
              Nikolai last edited by Nikolai

              New update of both repos.

              MQL5 JSON API is finished. Historical data load speed was optimized. I have to finish various features like:

              • expiration
              • deviation
              • hedging
              • error handling docs
              • etc.

              Reconnection and data uploading after reconnection were added to Backtrader-MQL5-API The main goal for now is to finish pending orders management.

              1 Reply Last reply Reply Quote 1
              • Nikolai
                Nikolai last edited by Nikolai

                Hi, everyone. New update of both repos.

                All goals in MQL5-JSON-API was done.
                Pending orders in Backtrader-MQL5-API was finished.
                We will start production testing next week.

                Jalal Ahmadi 1 Reply Last reply Reply Quote 2
                • Jalal Ahmadi
                  Jalal Ahmadi @Nikolai last edited by

                  @Nikolai hi Nikolai,
                  is it possible to use MQL5-api for optimization?
                  does it work ?
                  thanks

                  Nikolai 1 Reply Last reply Reply Quote 0
                  • Nikolai
                    Nikolai @Jalal Ahmadi last edited by

                    @Jalal-Ahmadi Hi.
                    What do you mean "for optimization"?
                    Yes, it works.

                    Jalal Ahmadi 1 Reply Last reply Reply Quote 0
                    • Jalal Ahmadi
                      Jalal Ahmadi last edited by

                      I mean is it possible to use this code to optimize an strategy in metatrader5?

                      1 Reply Last reply Reply Quote 0
                      • Jalal Ahmadi
                        Jalal Ahmadi @Nikolai last edited by

                        @Nikolai I mean is it possible to use this code to optimize a strategy in "optimize mode" in metatrader5?
                        for example send sell/buy order from your python client code to metatrader5 in optimize mode? and if the answer is yes is it possible to handle this scenario in multi-core optimization mode in metatrader?
                        thanks

                        1 Reply Last reply Reply Quote 0
                        • B
                          backtrader administrators last edited by

                          It is obviously not possible.

                          • https://www.metatrader5.com/en/terminal/help/algotrading/strategy_optimization

                          The code from Nikolai is a bridge to let something written in backtrader use MT5 as a data feed and as broker.

                          An optimization run in Metatrader runs agents which you select (and no, something developed in backtrader is not an agent). See the article and pictures.

                          1 Reply Last reply Reply Quote 0
                          • Paulo Urbano
                            Paulo Urbano last edited by

                            @Nikolai
                            Hello, Nikolai.

                            Awesome work on both the MQL5 JSON API and Backtrader MQL5 API. Congrats!

                            I was wondering if you have considered the Metaquotes maintained API package as a future inclusion in the Backtrader MQL5 API. Not disregarding the relevance of a language agnostic JSON API, the Metaquotes package could be used as an alternative to the Zero MQ, reducing that external dependency.

                            Thanks.

                            1 Reply Last reply Reply Quote 0
                            • Nikolai
                              Nikolai last edited by

                              @PAULO URBANO
                              Hi, thanks.
                              As i remember Metaquotes API works only on Windows OS. I don't use it at all.

                              1 Reply Last reply Reply Quote 0
                              • André Tavares
                                André Tavares last edited by

                                Hello @Nikolai.
                                Is there a limit to how many datafeeds can be used?
                                I am adding 100 datafeeds and keep getting these erros below:
                                zmq.error.Again: Resource temporarily unavailable
                                zmq.error.NotDone: Sending request ERROR

                                run-out 1 Reply Last reply Reply Quote 0
                                • run-out
                                  run-out @André Tavares last edited by

                                  @André-Tavares said in Metaquotes MQL 5 - API:

                                  Is there a limit to how many datafeeds can be used?

                                  There's no limit I'm aware of. For fun, I just added 1000 of the same datafeed to cerebro using a loop.

                                     data = bt.feeds.PandasData(dataname=df_new)
                                      for _ in range(1000):
                                          # add data to cerebro
                                          cerebro.adddata(data)
                                  

                                  Now to be fair cerebro is just populating a list and I'm not running it through the system. But I know I've used upwards of 700 equity datalines in the past when make equity portfolios based on the general market.

                                  RunBacktest.com

                                  1 Reply Last reply Reply Quote 0
                                  • André Tavares
                                    André Tavares last edited by

                                    @run-out I am asking using MT5 Broker.
                                    Using pandas I have done it also.

                                    run-out 1 Reply Last reply Reply Quote 0
                                    • run-out
                                      run-out @André Tavares last edited by

                                      @André-Tavares Sorry, misread the question.

                                      RunBacktest.com

                                      1 Reply Last reply Reply Quote 0
                                      • André Tavares
                                        André Tavares last edited by

                                        I managed to work it out.
                                        I had to incread the timeout.
                                        self.sys_socket.RCVTIMEO = sys_timeout * 100000
                                        self.data_socket.RCVTIMEO = data_timeout * 100000

                                        1 Reply Last reply Reply Quote 1
                                        • 1 / 1
                                        • First post
                                          Last post
                                        Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors