MetaTrader 5 Python User Group - the summary - page 25

 

Hello all,


I'm new to MetaTrader and try to understand some basics in combination with Python and MT5.

I'm quite sure my questions have been answered multiple times in this forum, but would like to give a short introduction of my understanding and would love to get pointed to the right direction by you.

As far as I understood, the python support is given 'scripts' only. 

Scripts are using an API to e.g. get historical data, additiopnal info ... and also place orders,

but they cannot be attached to an open chart as indicators and advisors can, right?

Indicators and advisors have to be written in mql5 an C++ like programming language, where the compiler is comming with the MetaEditor installation.

The MQL5 languange itself might provide whatever is needed to enable one creating 'indicators', 'advisors' and 'scripts', but I guess there is no big open source projects providing things like the C++ STL or streams, right?

I have read, that there is also a R support which I guess it will be limited to 'scripts' as it is for python, which is caused by the fact these languages are interpreted and cannot provide entry point like OnInti(), ...


In the past years I was buying end of day data using them in R and Python scripting, preprocessing them and creating models providing me predictions.

I understand now, that historical data I get get for free by using MT4/5, which is great, but I don not miss the time I did all the processing of data as I learned a lot ;)

What I would like to do now is, connect my python processing to MT5, use my models to predict the movement of symbols, and finaly trade binary options.

I have a broker enabling me trading binary options via MT5, also in a demo mode on a subset of the sysmbols.

Before starting trading using a python script, I would like to test the model by performing backtesting making use of the 'strategy tester'. 

Unfortunately I'm not sure how to achieve this. 

As far as I understood, the 'strategy tester' can be used only in combination with 'expert advisors', right?

This means, that

- an 'exp. advisor' needs to be bound to the same symbol as my python model

- the python script running in an endless loop publishes (based on a timer as OnTick() does not exists in its environment) predictions

- publishing needs to be doen through a communication channel like a socket

- the 'exp. advisor' decides based on the prediction received to trade (call or put) on a defined time scale

This brings up some things to consider

- the symbol of the prediction has to be checked by the advisor and compared with the chart it is running on

- the time scale of the prediction has to be the same as the one used in the chart

- a trade is just a trigger on call or put making use of a defined time span e.g. 15min, 2hour, 1day, ... It does not support stop loss or similar attributes which are normal on stock trading.

- it seems I need to start an Binary.ex5 tool to enable doing binary option trading in MT5, don't know what this is good for as when running it I get an error that my account is not supporting this, but this I need to clarify with the broker 


It would be very helpfull if you can give me a hint if my thoughts are going to the right direction and point me to some information e.g. books covering the MT5 algo trading etc. 

Is someone here making use of MT5 & python and trading binary options?


Regards

laiki



have an 'expert advisor' which will do the tr

 

Forum on trading, automated trading systems and testing trading strategies

Order Python, R, C++, C#, and Java programs in Freelance

MetaQuotes, 2021.08.30 15:36

The MQL5 language is constantly evolving: in the last few years, we have added native work with databases and DirectX, OpenCL and Python support, network functions for operations on the web, and other syntax improvements aimed at bringing the language closer to C++. That is why MQL5 is considered the best and the fastest language for algorithmic traders, while Freelance is the largest service for ordering trading robots and applications.

Modern algorithmic trading is no longer limited to one platform or market: advanced trading strategies often involve a whole set of different tasks implemented in different programming languages. In line with this trend, we have extended the list of programming languages in Freelance orders, enabling you to select Python, R, C++, C#, Java, or others for your order.

Selecting a programming language for a Freelance order


With the new options, you can easily select specific language developers. Use them to set explicit requirements for the Freelance developer you are looking for, rather than desired additional skills. You can still specify other skills which might be additionally required, to make your order description even more precise.

In addition, we have implemented the ability to select completed works by customer or developer, at the request of Freelance users. The total number of completed projects is approaching 100,000, so this new filter will be extremely helpful.

Originally, the new feature was requested by developers who have already completed hundreds of orders. However, this option is equally useful for customers who wish to create a personal order for a specific developer but cannot find projects in which they have previously cooperated.

Search by username in your projects


The enhanced features will assist users in finding the best developers for their orders. Furthermore, we expect that the new featured programming languages will expand the range of Freelance tasks and will attract even more algorithmic traders.



Order a project in Freelance


 

hi to All

how  can i iterate over this?

rates = mt5.copy_rates_range(index, mt5.TIMEFRAME_M5, utc_from, utc_to)

thanks

 
Rez Golestani #:

Hi to All

I'm newbie in mql5 and python.

The question is that how can i SOTRE  time series information from metatrader5 to python as csv file? 

Thanks in advance

from IPython.core.display import display, HTML
import numpy as np
import pandas as pd
from datetime import datetime
import MetaTrader5 as mt5

symbol = 'GBPUSD'
mt5.initialize()
start = datetime(2001, 1, 1)
end = datetime(2030, 1, 1)
df_M1 = pd.DataFrame(mt5.copy_rates_range(symbol, mt5.TIMEFRAME_M1, start, end)).drop(columns=['real_volume'])
df_M1['time']=pd.to_datetime(df_M1['time'], unit='s')
mt5.shutdown()
df_M1.to_csv('{}_M1.csv'.format(symbol), index=False)
display(df_M1.head(2))
display(df_M1.tail(2))
 
Manuel Sanchon #:

Hi Manuel

Thanks for kindness. the time-span covered using Start and End was new for me and practical.

 

Forum on trading, automated trading systems and testing trading strategies

MetaTrader 5 Python Integration for Beginners

Renat Fatkhullin , 2021.10.23 15:42

MetaTrader 5 for Python 3.0.36 was released with Python 3.10 support

 

Hi there,

This is my first post in this group and I'm not sure it's the right place. If not please tell me where I can post.

I use MetaTrader5 python package dl from Pypi. 

I downloaded ticks with copy_ticks_range() and in the result I have a field "flags" uint32. 

On the 260 000 ticks I got I have 3 different values for this field: 4, 130 and 134.

In accordance to https://www.mql5.com/en/docs/integration/python_metatrader5/mt5copyticksfrom_py#tick_flag I have:

print(mt5.TICK_FLAG_BID) #Bid price changed

2

print(mt5.TICK_FLAG_ASK) # Ask price changed

4

print(mt5.TICK_FLAG_LAST) #Last price changed

8

print(mt5.TICK_FLAG_VOLUME) # Volume changed

16

print(mt5.TICK_FLAG_BUY) # last Buy price changed

32

print(mt5.TICK_FLAG_SELL) # last Sell price changed

64

For 4, it seems ok with the few ticks I checked, but I can't find any reason for 130 and 134 (because the sum of all flags is inferior to 130) !

Also 130 + 4 is 134 ! But what could I do with this clue (if it's one)

Any info or idea ? 

Thanks 

Alex 


EDIT: 

Also in the documentation https://www.mql5.com/en/docs/integration/python_metatrader5/mt5copyticksfrom_py

At the end of the page, tick results are showing 134 for the flag value, so I think this is a MetaTrader 5 situation and not related my broker/account

Documentation on MQL5: Integration / MetaTrader for Python / copy_ticks_from
Documentation on MQL5: Integration / MetaTrader for Python / copy_ticks_from
  • www.mql5.com
copy_ticks_from - MetaTrader for Python - Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Is there a way to view variables that are declared within an EA that is running in mql5 from the Python interface? 
 
Thomas Culbertson #: Is there a way to view variables that are declared within an EA that is running in mql5 from the Python interface? 

No! Not even other EAs, Scripts, Indicators or Services or even MetaTrader itself can do that (unless you running in source Debug mode via MetaEditor).

Unlike Python, MQL is a compiled language. Only the external inputs are visible. All other variables have been compiled and reduced to executable code.

 

Forum on trading, automated trading systems and testing trading strategies

MetaTrader 5 Python User Group - the summary

Sergey Golubev, 2019.03.14 08:18

The Main Study

----------------

The Article

----------------

Metatrader 5 Help

----------------

The CodeBase

----------------

The Forum

----------------

The Blogs

Something to Read - Python for Finance: Analyze Big Financial Data - the blog post (the book)

----------------

more to follow ..


Reason: