MetaTrader 5 Python User Group - the summary - page 21

 
fxke62:

I am an experienced database developer but a Python rookie.
System W10 on 64 bit.

It's looking for a compiler and isn't finding it. You'll need to install:


Microsoft Visual C++ 14.2 standalone: Build Tools for Visual Studio 2019 (x86, x64, ARM, ARM64)

This is a standalone version of Visual C++ 14.2 compiler, you don't need to install Visual Studio 2019.

  • Install Microsoft Build Tools for Visual Studio 2019.

  • In Build tools, install C++ build tools and ensure the latest versions of MSVCv142 - VS 2019 C++ x64/x86 build tools and Windows 10 SDK are checked.

  • The setuptools Python package version must be at least 34.4.0.

Download Visual Studio 2019 for Windows & Mac
Download Visual Studio 2019 for Windows & Mac
  • 2020.10.08
  • visualstudio.microsoft.com
Download Visual Studio Community, Professional, and Enterprise. Try Visual Studio IDE, Code or Mac for free today.
 

How to use this function Tick()?

I am getting error:

>>> mt5.Tick()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: structseq() missing required argument 'sequence' (pos 1)

Please let me know.

Where I can find the documentation for this function?
 

Is there no reply for my query here? I should have asked this query in Russian Forum, I guess.

 
jaffer wilson:

Is there no reply for my query here? I should have asked this query in Russian Forum, I guess.

jaffer wilson:

How to use this function Tick()?

I am getting error:

Please let me know.

Where I can find the documentation for this function?

Tick is not a function. It is the object that's returned from the symbol_info_tick function. The capital T in the name is the giveaway as it is the python convention for classes. You could have also used your python IDE to peek the declaration to see that it is a subclass of tuple it's not intended to be called directly from the API. 


https://www.mql5.com/en/docs/integration/python_metatrader5

Documentation on MQL5: Integration / MetaTrader for Python
Documentation on MQL5: Integration / MetaTrader for Python
  • www.mql5.com
Python is a modern high-level programming language for developing scripts and applications. It contains multiple libraries for machine learning, process automation, as well as data analysis and visualization. MetaTrader package for Python is designed...
 

Gradient Boosting (CatBoost) in the development of trading systems. A naive approach

Gradient Boosting (CatBoost) in the development of trading systems. A naive approach

Gradient boosting is a powerful machine learning algorithm. The method produces an ensemble of weak models (for example, decision trees), in which (in contrast to bagging) models are built sequentially, rather than independently (in parallel). This means that the next tree learns from the mistakes of the previous one, then this process is repeated, increasing the number of weak models. This builds a strong model which can generalize using heterogeneous data. In this experiment, I used the CatBoost library developed by Yandex. It is one of the most popular libraries, along with XGboost and LightGBM. 

The purpose of the article is to demonstrate the creation of a model based on machine learning. The creation process consists of the following steps:

  • receive and preprocess data
  • train the model using the prepared data
  • test the model in a custom strategy tester
  • port the model to MetaTrader 5

The Python language and the MetaTrader 5 library are used for preparing the data and for training the model.


Gradient Boosting (CatBoost) in the development of trading systems. A naive approach
Gradient Boosting (CatBoost) in the development of trading systems. A naive approach
  • www.mql5.com
Gradient boosting is a powerful machine learning algorithm. The method produces an ensemble of weak models (for example, decision trees), in which (in contrast to bagging) models are built sequentially, rather than independently (in parallel). This means that the next tree learns from the mistakes of the previous one, then this process is...
 
nicholish en:

You can set the tp/sl when you send the order as well as modifying it. Here is a quick example. 

I am struggling with it in python 3. It seems there is a bug or something. Whenever I set action to TRADE_ACTION_SLTP, regardless what other parameters are, the order_send() functions always returns a None. This is while other trade actions work perfectly.
 
Hello Community,

I am a new user of this wonderful python integration package and have come to make it working for me. I am able to get ticks/rates and send orders or close them. One thing that I have not managed yet is to modify SL/TP of an already open position. I will post below the code I am using which is based on code snippets in this forum and others in the web that people declared is working okey. But it always returns None no matter what parameters I pass or how they are valued. It seems to me that
order_send()


doesn't even react to action type TRADE_ACTION_SLTP. Here is my code example:

import pandas as pd
import MetaTrader5 as mt5
 
# connect to MetaTrader 5
if not mt5.initialize():
    print("initialize() failed")
    mt5.shutdown()

# login credentials
user  = ******* # server login integer
passw = ******* # password string

if not mt5.login(user, password=passw):
    print("login() failed")
    mt5.shutdown()

ticket = **********   # ticket to the position I want to change its SL

position = mt5.positions_get(ticket=ticket)
symbol   = position[0].symbol
SL       = 1900
TP       = 1800

request = {
            "action"      : mt5.TRADE_ACTION_SLTP,
            "position"    : ticket,
            "symbol"      : symbol,
            "deviation"   : 20,
            "sl"          : SL,
            "tp"          : TP,
            "type_time"   : mt5.ORDER_TIME_GTC,
            "type_filling": mt5.ORDER_FILLING_RETURN   }


result = mt5.order_send(request)

print(result)

It always returns None and nothing changes in the position. I tried several combinations of parameters but nothing also changed. I am using the package with python 3.8 and the package release is 5.0.33.

Please help me find a solution to this if possible.

 
p0o0uya:
Hello Community,

I am a new user of this wonderful python integration package and have come to make it working for me. I am able to get ticks/rates and send orders or close them. One thing that I have not managed yet is to modify SL/TP of an already open position. I will post below the code I am using which is based on code snippets in this forum and others in the web that people declared is working okey. But it always returns None no matter what parameters I pass or how they are valued. It seems to me that


doesn't even react to action type TRADE_ACTION_SLTP. Here is my code example:

It always returns None and nothing changes in the position. I tried several combinations of parameters but nothing also changed. I am using the package with python 3.8 and the package release is 5.0.33.

Please help me find a solution to this if possible.

Oh God! I found the problem. SL and TP should be float numbers not integers. 
 

Hello,

Have you managed to use the MetaTrader5 library for Python with Google Colab ?

 
Laurent Soudron:

Hello,

Have you managed to use the MetaTrader5 library for Python with Google Colab ?

In order for it to work, both Python and Metatrader need to be running in windows. I'm using a windows guest on linux host. You can download a 90 day eval of windows for free. Before booting the windows VM for the first time you need to create a snapshot so you can easily reset the VM. I then keep all my files in the cloud. Every 90 days I reset the VM, install MT5 and sync the cloud files. 


https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/

Virtual Machines
  • developer.microsoft.com
These virtual machines expire after 90 days . We recommend setting a snapshot when you first install the virtual machine which you can roll back to later. Mac users will need to use a tool that supports zip64, like The Unarchiver, to unzip the files. The password to your VM is "Passw0rd!" View installation...
Reason: