Code Monkey home page Code Monkey logo

mql5-python-integration's Introduction

Mql5-Python-Integration

I am working on a new project based on this one! This new project is splitted into modules. You can find the release of the first module on the links below.

Keep in mind that some features that you can find on Mql5-Python-Integration are not presented yet on the new one, but I will add the features and many new ones.

My page: https://joaopeuko.github.io/

Pypi of the first module: https://pypi.org/project/metatrader5EasyT/

GitHub project https://github.com/Joaopeuko/metatrader5EasyT

Project documentation https://joaopeuko.github.io/metatrader5EasyT/

Patron who makes the difference!

Help me make it possible. Be my Patreon.

Introduction

I created this library because the development of an Expert Advisor in MQL5 can be complicated,while, in python, the same task flows better.

I believe that the main advantage of using python, instead of MQL5, to develop an expert advisor is the possibility to implement machine learning, deep learning, and reinforcement learning to your code in a faster way. However, I still don´t cover these.

I find that using the “MetaTrader module for integration with Python” is straightforward; yet, there is space for improvement.

Thus, I created this library, aiming to transform the experience of Expert Advisor Creation. Python is a versatile language; it counts with a wide range of useful libraries, which, in turn, allows the implementation of diverse ideas, easily.

Installation

pip install MetaTrader5

pip install MetaTrader5

Expert Advisor

There is an expert advisor example for each different technology in the Expert Advisor folder.

Simple Example

example.py

It uses just the MetaTrader5 library in the implementation.

Socket Example

example_sockets_connection.py

The “MetaTrader module for integration with Python” enables a wide range of possibilities; still, there is space for improvement. For instance, it lacks a connection to indicators.

That problem can be solved:

  • Using Python indicators libraries that already exist through the internet.
  • Re-creating all the indicators
  • Creating a connection with MetaTrader5, asking for some indicators.

This example uses a socket connection to simplify the usage of indicators and it shows how easy it is to implement. You can find the indicator connection file here.

To be able to use socket connection you need the client-side and the server-side to allow the communication.

The python code, that is used in this example, is the server-side that waits for the client-side to send the indicator result asked for.

The python code that is used in this example is the server-side that waits for the client-side to send the indicator result asked for. In order to use the client-side, it is possible to code it in MQL-language or to use the ones that I already created:

  • here - Free - 5 Indicators
  • here - Not Free - 38 Indicators (5 from free indicators plus 33 new ones). The iCustom is not implemented.

To use the indicator in the expert advisor, you can call it providing the symbol name, all the other variables have pre-configured values. It always uses a time_frame for 1 minute.

example_sockets_connection.py

from include.indicator_connector import Indicator

indicator = Indicator()

moving_average = indicator.moving_average(symbol='PETR4')  # Brazilian Stock 

You can check this file to find some tips when calling an indicator, for example, on how to change the method or the applied price.

 def moving_average(self,
                       symbol,
                       time_frame=1,
                       period=20,
                       start_position=0,  # Change it if you want past values, zero is the most recent.
                       # method:
                       # 0 - MODE_SMA
                       # 1 - MODE_EMA
                       # 2 - MODE_SMMA
                       # 3 - MODE_LWMA
                       method=0,
                       # applied_price:
                       # 0 - PRICE_CLOSE
                       # 1 - PRICE_OPEN
                       # 2 - PRICE_HIGH
                       # 3 - PRICE_LOW
                       # 4 - PRICE_MEDIAN
                       # 5 - PRICE_TYPICAL
                       # 6 - PRICE_WEIGHTED
                       applied_price=0):

When using the indicators, please use try and except; sometimes the result can return "None."

example_sockets_connection.py

from include.indicator_connector import Indicator

indicator = Indicator()

while True:
    try:
        moving_average = indicator.moving_average(symbol='PETR4')  # Brazilian Stock 
    except TypeError:
        pass

The indicator result is a dictionary.

print(moving_average)
{'symbol': 'PETR4', 'time_frame': 1, 'period': 50, 'start_position': 0, 'method': 0, 'applied_price': 0, 'moving_average_result': 23.103}

print(moving_average['moving_average_result'])
23.103

mql5-python-integration's People

Contributors

joaopeuko avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.