Python Proxy Backtest
- Bibliotecas
- Cheung Ka Ho
- Versão: 1.40
- Atualizado: 18 agosto 2023
[Introduction] . [Installation]
Introduction
Python is a high level programing language with a nice package management giving user different libraries in the range from TA to ML/AI. Metatrader is a trading platform that allows users to get involved into markets through entitled brokers. Combining python with MT4 would give user an unprecedented convienance over the connection of brokers and the freedom of library utilization. The potential of your EA now becomes unlimited as you can create different AI strategies on top of those famous ML python libraries freely.
You will need to have your customized proxy EA running on the MT4 side. TCP socket will be used for messaging between the python EA and proxy EA. There are 3 main components in the MT4 system:
- Py3_Proxy_Interface.ex4 --- It holds the core communication implementation. You can get a free version from the MQL5 for backtesting your strategy.
- WinSocketWrapper.mqh --- It contains the windows socket utilization.
- Py_Proxy_Ea.mq4 --- The last component in MT4 side. By combining all 3 of them, you will have your own customized proxy EA running as a server on the MT4 side and waiting for the connection from the python EA. In addition, you can control the input parameters as what you did as a normal MT4 EA.
The idea of the proxy EA is not only providing python interfaces but also keeping the life cycle of EAs so that the callback sequences are remained in the python side which means that you can backtest your python EA on the MT4 platform.
As one may notice that the communication between the processes is TPC socket, speed is a bit slower to the share memory method. To keep the speed of the EA operation while does not sacrifice much of the data converage. The OnTick function on the python side will be triggered for each bar instead of each tick. In other words, whenever there is a bar update, the function OnTick will be triggered.
Limitation & Notice
There are limitations of this solution.
- This is not a bug free library. Users are encouraged to test out their EAs through the free version provided on the marketplace amid the backtesting phases. There is no support guarantee but you can put down the bugs or suggestions you have in the comments.
- Not all of the functions in MQL4 are supported. You can find the list of supported functions within the file --- function_list.txt
- The callback frequence is not tick by tick, that is based on bar, for example 1M, 5M, etc...
If you like this library and would you like to use it for live trading, feel free to subscribe it through the marketplace. Please only do this after you tested and confirm it works for your use case.
There is no guarantee of profits by this tool. It is just a bridge tool between MT4 and python.