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

 
Maxim Dmitrievsky:

a command and a list of parameters can be passed as a string, separated by separators. When the Expert Advisor unpacks the message, it will understand what to do


The OrderSend command ?

What should the format of the string be ? string ? In the socket example, the string from mql5 socket is passedto result: socketreceive(int sock,int timeout)...result+=CharArrayToString(rsp,0,rsp_len);.return result;

 
slukin:

OrderSend command ?

What should the format of the string be ? string ? In the socket example, the string from mql5 socket client is passedto result: socketreceive(int sock,int timeout)...result+=CharArrayToString(rsp,0,rsp_len);.return result;

not OrderSend() but just a string containing the 1st 3 characters, e.g. "BUY", followed by a list of arguments: lot, take, sl. The Expert Advisor reads the string, sees the 1st 3 letters buy and forms a Trog Request

i.e., just design a simple exchange protocol between the applications, in a free form
 
Maxim Dmitrievsky:

not OrderSend() but just a string with the 1st 3 characters, for example "BUY", and then a list of arguments: lot, take, sl. The Expert Advisor reads the string, sees that the 1st 3 letters are buy and forms a trog request

i.e., just think of a simple exchange protocol between applications, in a free form


An example from an experienced developer would be very helpful.

 
Roffild:

I've already connected a full-fledged Python to the terminal, and you're still using slow-moving sockets and pipes to make the exchange.

If it's not too difficult, how long is a single test at any timeframe?

It means we are interested in question how long optimization time in the tester is and if incorrect calculations are possible?

In previous comments you wrote that I need some background knowledge in JAVA to understand it.

I also know some C# and Python, I can program in MQL4,5, can I master your libraries rather easily, how much harder can they be?

 
slukin:

An example from an experienced developer would be very helpful.

there is no time to explain, unless there is an article later, with examples

 
forexman77:

If it is not difficult to write how long a single test takes on any timeframe?

That is, I am interested in the question of how long the optimization in the tester and whether there are incorrect calculations?

In previous comments you wrote that I need some background knowledge in JAVA to understand it.

I do know some C# and Python, I can program in MQL4,5, can I master your libraries rather easily, how much harder can they be?

Optimization in the Strategy Tester is the same as the usual one. Incorrect calculations due to corrupted data during transfer to Python and back are excluded, because the transfer goes through RAM and not through unstable sockets or files.

Yes, I put into my library code in MQL, Java and Python. But you don't have to use Java if you don't need Apache Spark etc.

 

MetaTrader 5 build 2055 beta: Integration with Python, C++-like scope and massive improvements in strategy tester

Terminal: Добавлено API для запроса данных из терминала MetaTrader 5 через приложения, использующие язык Python

Python is a modern, high-level programming language for developing scripts and applications. Contains many libraries for machine learning, process automation, data analysis and visualisation.

MetaTrader package for Python is designed for easy and fast getting of exchange data via interprocess communication directly from MetaTrader 5 terminal. The data thus obtained can be further used for statistical calculations and machine learning.



Connecting

  1. Download the latest version of Python fromhttps://www.python.org/downloads/windows
  2. When installing Python check the "Add Python X.X to PATH%" box, so that you can run scripts in Python from the command line.
  3. Install MetaTrader 5 module from the command line
    pip install MetaTrader5
  4. Add packages matplotlib and pytz
    pip install matplotlib
    pip install pytz

Functions

  • MT5Initialize- establishes connection to MetaTrader 5 terminal
  • MT5Shutdown- closes the previously established connection to the MetaTrader 5 terminal
  • MT5TerminalInfo- receives the state and parameters of the connected MetaTrader 5 terminal
  • MT5Version- returns the terminal version MetaTrader 5
  • MT5WaitForTerminal- waits until the terminal MetaTrader 5 connects to the trade server
  • MT5CopyRatesFrom- receives bars from MetaTrader 5 terminal from the specified date
  • MT5CopyRatesFromPos- receives bars from MetaTrader 5 terminal starting from the specified index
  • MT5CopyRatesRange- receives bars in the specified date range from the MetaTrader 5 terminal
  • MT5CopyTicksFrom- receives ticks from MetaTrader 5 terminal starting from the specified date
  • MT5CopyTicksRange- receives ticks for specified date range from MetaTrader 5 terminal
Welcome to Python.org
Welcome to Python.org
  • 2019.05.15
  • www.python.org
The official home of the Python Programming Language
 

So? Is anyone working in that direction? Doesn't seem enthusiastic.

Good luck

 
Vladimir Perervenko:

So? Is anyone working in that direction? Doesn't seem enthusiastic.

Good luck

Not in this one. And I use python for NS tests.
 
Roffild:

Optimisation in the tester is as usual. Incorrect calculations due to data corruption during transfer to and from Python are excluded, because the transfer is via RAM, not via unstable sockets or files.

Yes, I put into my library code in MQL, Java and Python. But you don't have to use Java if you don't need Apache Spark etc.

I agree that it's faster via memory, but I don't agree that sockets or pips are not stable, and the crazy memory speed when organizing a connector is unnecessary because there is latency exchange <--- (intermediate server is possible) ---> terminal, for which even hundreds of consecutive sockets within one machine are excessively enough...