Trading Bot in MQL5 w/ ML written in Python

Renz Carillo  

Is my idea feasible? If so what gotchas do I need to lookout for? Is this even the best idea or should i just completely write everything in Python?

A quick background check about me: I already know how to write bots in MQL5. I have used python before but for a completely different scenario (e.g. web scraping, data engineering, etc.) and not trading. 

Fernando Carreiro  
Renz Carillo: Is my idea feasible? If so what gotchas do I need to lookout for? Is this even the best idea or should i just completely write everything in Python? A quick background check about me: I already know how to write bots in MQL5. I have used python before but for a completely different scenario (e.g. web scraping, data engineering, etc.) and not trading. 

It's possible but not necessarily the best approach. Given that most Machine Learning libraries for Python are actually written in C/C++ with a Python wrapper, you might as well directly access the pure libraries via a DLL calls for a much more direct and efficient solution. Going through Python would be slow, inefficient and just be a kludge.

Lorentzos Roussos  

Seems like you'll need to create both ends . Trading simulation in python and ML in mql5 (at least the feed forward part if NN), because you will need testing accuracy during training and you will need the "brain" functions of whatever you trained in mql5.

There is a saying in Greece 

"We ate the whole cow but we are debating eating the tail" 

Renz Carillo  
Fernando Carreiro #:

It's possible but not necessarily the best approach. Given that most Machine Learning libraries for Python are actually written in C/C++ with a Python wrapper, you might as well directly access the pure libraries via a DLL calls for a much more direct and efficient solution. Going through Python would be slow, inefficient and just be a kludge.

Interesting. Has anyone actually tried this before? I've been googling but to no avail. Perhaps you could point me to an article how to implement this. Thanks a lot!
Fernando Carreiro  
Renz Carillo #: Interesting. Has anyone actually tried this before? I've been googling but to no avail. Perhaps you could point me to an article how to implement this. Thanks a lot!

There are several Articles about Machine Learning and Neural Networks here on the website.

There are also several related forum topics too, and a few related CodeBase publications.

So, run a Search here on the website and do some reading.

Renz Carillo  
Lorentzos Roussos #:

Seems like you'll need to create both ends . Trading simulation in python and ML in mql5 (at least the feed forward part if NN), because you will need testing accuracy during training and you will need the "brain" functions of whatever you trained in mql5.

There is a saying in Greece 

"We ate the whole cow but we are debating eating the tail" 

Im sorry for my ignorance but I'm quite confused with your reasoning as to why I would need " Trading simulation in python and ML in mql5".
Fernando Carreiro  
Renz Carillo #: Im sorry for my ignorance but I'm quite confused with your reasoning as to why I would need " Trading simulation in python and ML in mql5".

Because MetaTrader only offers back-testing for MQL5 EAs and not for Python code.

So if your Python code is stand-alone or needs to train on its own without the MQL5 front-end, you would then need to create your own trading simulation functionality for the python components.

This is probably what @Lorentzos Roussos meant by his comments.

Lorentzos Roussos  
Fernando Carreiro #:

Because MetaTrader only offers back-testing for MQL5 EAs and not for Python code.

So if your Python code is stand-alone or needs to train on its own without the MQL5 front-end, you would then need to create your own trading simulation functionality for the python components.

This is probably what @Lorentzos Roussos meant by his comments.

Always on point ++

Renz Carillo #:
Im sorry for my ignorance but I'm quite confused with your reasoning as to why I would need " Trading simulation in python and ML in mql5".

Its not ignorance , i'm just saying your "model" will need to evaluate itself somehow . So you will either export all the signals from mt5 and then optimize with the field of signals on python (or anything else . You can do this now for instance with excel's built in genetic algorithm) , or , you will export the price feed and do calculations (including indicators) internally (in python).

*The advantage to exporting all the signals is you are not limited to trading rules as you would be in the MT5 tester , you can evaluate all the signals but then , when you move from concept to ea you need to take the "trading rules" into account.  

Then , assuming your trained model is ready ,if its a neural net it will have nodes .These nodes will have a configuration , activation functions , weights biases ,dropouts etc. 

So you either feed data to python , the model predicts , returns data to mt5 or you "transfer" the "brains" to the ea directly .