MetaTrader 5 Python User Group - how to use Python in Metatrader - page 31

 

Compiling for python scripts in the editor means running them for execution inside the editor.

Look at the output in the error windows and the log. The log shows the main output, and the error windows show the stderr output.

 
Renat Fatkhullin:

Compiling for python scripts in the editor means running them for execution inside the editor.

Look at the output in the error windows and the log. The log shows the main output and the error window shows stderr output.

I see. There are no errors in the Error window,

no errors

but in the log window, the script is probably waiting for my action.

the script is waiting for my action

As I understand it, there is just no feedback (probably not yet).


Then I try to run the example from post #1 (https://www.mql5.com/ru/forum/306688 )- installed the matplotlib package and MetaTrader5.

Trying to run example from first post

In errors

test.py started test.py 1       1
Traceback (most recent call last):      test.py 1       1
    MT5Initialize()     test.py 1       1
NameError: name 'MT5Initialize' is not defined  test.py 1       1
test.py finished in 389 ms              1       1

In log

2020.01.27 10:08:12.899 Python  "E:\Programs\Python37\python.exe" "C:\Users\barab\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Scripts\Python\test.py"

and nothing happens (terminal is running at the same time).

 
Renat Fatkhullin:

Compiling for python scripts in the editor means running them for execution inside the editor.

Look at the output in the error windows and the log. The log shows the main output, and the error windows show the stderr output.

So the .py script will not compile to .ex5 ?
And run it from the navigator.

 
Vladimir Karputov:

I see. There are no errors in the "Errors" window,


but in the "Log" window, the script is probably waiting for my action.

As I understand it, there's just no feedback (probably not yet).


Then I try to run the example from post #1 (https://www.mql5.com/ru/forum/306688 )- installed the matplotlib package and MetaTrader5.

Trying to run example from first post

In errors

In log

and nothing happens (terminal is running).

MetaTrader5 library is not installed, do it:

pip install --upgrade metatrader5

everything works:


 
Roman:

So, the .py script will not be compiled to .ex5 ?
And run it from the navigator.

Of course, it won't compile, but will be visible in the navigator as a *.py program and run hidden in a separate terminal thread.

Communication with the terminal via the MetaTrader 5 Python library.

 
Renat Fatkhullin:

Not supplied with MetaTrader5 library, do it:

everything works:


The library is installed:


(was put in immediately withmatplotlib)


Added: and does not run in python:


 
Renat Fatkhullin:

Of course, it won't be compiled, but will be visible in navigator as *.py program and run hidden in a separate thread of the terminal.

Communication with the terminal via the built-in MetaTrader 5 library for Python.

Now I get it, it will be like a Python visual notebook, only the whole code is run.
I've been working my butt off about the compilation, and the compilation would have been awesome.
The thing is, with standard .py to .exe compilation, there is very little protection against reverse-engineering. You could say it's useless.
If .py compiled to .ex5, it would really boost mql5 in terms of wow mql5 compiles to an executable well protected by .ex5.
Python has this as a global problem, think about it. Especially since python compiles to .exe, uses C or C++ like compiler.
And mql5 uses LLVM.

 

Uninstalled python. Installed 3.8.1 x64.

When running in Python now has these errors:


Python 3.8.1 (tags/v3.8.1:1 b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
= RESTART: C:\Users\barab\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Scripts\Python\metatrader5-test.py
Traceback (most recent call last):
  File "C:\Users\barab\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Scripts\Python\metatrader5-test.py", line 2, in <module>
    from MetaTrader5 import *
  File "E:\Programs\Python\Python38\lib\site-packages\MetaTrader5\__init__.py", line 35, in <module>
    from .C import *
ImportError: DLL load failed while importing C: Не найден указанный модуль.
>>> 
 
Vladimir Karputov:

The library stands:


(was supplied immediately along withmatplotlib)


Added: and does not run in python:


You have Python 3.8, put better 3.7.6 as many libraries are not yet ready for 3.8 anyway

1) From the command line, check the script.

2) Check that python path is in PATH.

3) Make sure there is only one copy of Python, and no conflicts with other versions.

4) Make sure the path to the single copy of Python in the editor is correct.


It's quite possible that you have a zoo of indirectly installed Pythons from different environments like Visual Studio.

 
Vladimir Karputov:

Then I try to run the example from post #1 (https://www.mql5.com/ru/forum/306688 )- installed the matplotlib package and MetaTrader5.

Trying to run the example from the first post

In errors

In log

and nothing happens (terminal is running at the same time).

We need to wait a bit - the script requests data from 28.01.2019 - it takes time.

Second possible reason - limited value of " Max bars in window" is specified in the terminal.

ticks1 = MT5CopyTicksFrom("EURAUD", datetime(2019,1,28,13), 10000, MT5_COPY_TICKS_ALL)
ticks2 = MT5CopyTicksRange("AUDUSD", datetime(2019,1,27,13), datetime(2019,1,28,13,1), MT5_COPY_TICKS_ALL)

rates1 = MT5CopyRatesFrom("EURUSD", MT5_TIMEFRAME_M1, datetime(2019,1,28,13), 1000)
rates2 = MT5CopyRatesFromPos("EURGBP", MT5_TIMEFRAME_M1, 0, 1000)
rates3 = MT5CopyRatesRange("EURCAD", MT5_TIMEFRAME_M1, datetime(2019,1,27,13), datetime(2019,1,28,13))

The help explicitly states https://www.mql5.com/ru/docs/integration/python_metatrader5/mt5copyratesfrom_py

The MetaTrader 5 terminal gives bars only within the history available to the user on the charts. The number of bars that are available to the user is set in the settings by the "Max bars in window " parameter.


If this is really about the number of bars, you can either change the limit or fix the script to take the nearest minutes, e.g. for 2020 - this should work

Настройки платформы - Начало работы - Справка по MetaTrader 5
Настройки платформы - Начало работы - Справка по MetaTrader 5
  • www.metatrader5.com
Торговая платформа обладает множеством настроек, что позволяет организовать работу в ней так, как это удобно именно вам. Выполните команду " Настройки" меню "Сервис" или нажмите "Ctrl+O". Графики — общая настройка отображения ценовых графиков, а также настройка параметров управления объектами: выделение объектов после их создания, немедленная...