How to make a dll from TensorFlow or Keras?

 

title

I've worked with python and used those, would like to make them dll to work with them in mql5. How can I do this?

 

Please don't post randomly in any section. Topic has been moved to the section: Expert Advisors and Automated Trading

 

You can use the chdir command to set the working directory and load files from there in python .

That's how i do it for pytorch but these are one ofs . Meaning i export the data in mql5 ,then move the files manually then let pytorch hog my machine for hours.

How do you plan to use it ? I suspect your biggest concern is with utilizing the configuration you trained live ? The python library here might be of use in that case.

import os
os.system('cls')
os.chdir("E:\Python\Projects\\fdcouk_90synth_NN01_C7")

You could also export the model to ONNX and use it with the ONNX library 

https://learn.microsoft.com/en-us/windows/ai/windows-ml/tutorials/tensorflow-convert-model

Convert your TensorFlow model into ONNX format
Convert your TensorFlow model into ONNX format
  • 2021.12.30
  • QuinnRadich
  • learn.microsoft.com
Learn how to convert your TensorFlow model into ONNX format, for use with Windows Machine Learning APIs.
 
Fernando Carreiro #:

Please don't post randomly in any section. Topic has been moved to the section: Expert Advisors and Automated Trading

sorry ... I had never scrolled down. I will not repeat this error. Thanks.

 
Lorentzos Roussos #:

You can use the chdir command to set the working directory and load files from there in python .

That's how i do it for pytorch but these are one ofs . Meaning i export the data in mql5 ,then move the files manually then let pytorch hog my machine for hours.

How do you plan to use it ? I suspect your biggest concern is with utilizing the configuration you trained live ? The python library here might be of use in that case.

You could also export the model to ONNX and use it with the ONNX library 

https://learn.microsoft.com/en-us/windows/ai/windows-ml/tutorials/tensorflow-convert-model

Thanks my fried!) I would like to keep in touch with you ... we share same thoughts.

What more can you tell me about this? Please explain more ... this is incredibly usefull !!!)

 
Javier Santiago Gaston De Iriarte Cabrera #:

Thanks my fried!) I would like to keep in touch with you ... we share same thoughts.

What more can you tell me about this? Please explain more ... this is incredibly usefull !!!)

You are welcome . 

I'am not familiar with onnx or keras or tensorflow unfortunately . I literally started python 1 week ago because i was not sure if my custom neural net (mql5 code) had errors or there was an issue with features or there was a fundamental error , etc , so i wanted to see what pytorch would do . The built in CUDA support was also very appealing . 

There was a thread with tutorials on Onnx by meqatuotes i think  

Sidenote : Also do not look for the complete solution right away . First test make sure something is what you need then dive in , and test test test test test ... In this field if you are to assume something assume you are wrong first . But also be careful with the documentation here , it appears the person that deploys a function is not the person that writes the instructions for it.
 
Lorentzos Roussos #:

You are welcome . 

I'am not familiar with onnx or keras or tensorflow unfortunately . I literally started python 1 week ago because i was not sure if my custom neural net (mql5 code) had errors or there was an issue with features or there was a fundamental error , etc , so i wanted to see what pytorch would do . The built in CUDA support was also very appealing . 

There was a thread with tutorials on Onnx by meqatuotes i think  

Sidenote : Also do not look for the complete solution right away . First test make sure something is what you need then dive in , and test test test test test ... In this field if you are to assume something assume you are wrong first . But also be careful with the documentation here , it appears the person that deploys a function is not the person that writes the instructions for it.

Thanks ... I will have to study more this, to ask more ... but for now, I think this can help you extract data from mt5 without moving the files manually


import MetaTrader5 as mt5
import pandas as pd

uname=
pword=
trading_server=
filepath=



mt5.initialize(login=uname, password=pword, server=trading_server, path=filepath)  # connect to MetaTrader 5

symbols = ['AUDCAD', 'AUDCHF', 'AUDJPY', 'AUDNZD', 'AUDUSD', 'CADCHF', 'CADJPY', 'CHFJPY', 'GBPAUD', 'GBPCAD',
           'GBPCHF', 'GBPJPY', 'GBPNZD', 'GBPUSD', 'EURAUD', 'EURCAD', 'EURCHF', 'EURGBP', 'EURJPY', 'EURNZD',
           'EURUSD', 'NZDCAD', 'NZDCHF', 'NZDJPY', 'NZDUSD', 'USDCAD', 'USDCHF', 'USDJPY']

prices = {}

for symbol in symbols:
    data = mt5.copy_rates_from_pos(symbol, mt5.TIMEFRAME_D1, 0, 100)
    prices[symbol] = pd.DataFrame(data)[["time", "open", "high", "low", "close"]]
    print(prices[symbol])
 
Javier Santiago Gaston De Iriarte Cabrera #:

Thanks ... I will have to study more this, to ask more ... but for now, I think this can help you extract data from mt5 without moving the files manually


Nice . You trust that mt5 will return the full history without gaps ? You must consider that it may need more than one attempts or some time to load older data .

I don't know how the integration works however .

How will you normalize the input features ? You can opt for a local normalization if you also send in the atr of each previous bar to the one you get the ohlc for . It will make your inputs look more similar across symbols and it will make "memorization" harder

 
Lorentzos Roussos #:

Nice . You trust that mt5 will return the full history without gaps ? You must consider that it may need more than one attempts or some time to load older data .

I don't know how the integration works however .

How will you normalize the input features ? You can opt for a local normalization if you also send in the atr of each previous bar to the one you get the ohlc for . It will make your inputs look more similar across symbols and it will make "memorization" harder

mt5 gives good data, I've tried it and has not given errors ... but I also use ta library with fillna=true


I use ta library ... check it ... that uses this parameters that I use as inputs for the ml .... :


 'volume_adi', 'volume_obv', 'volume_cmf', 'volume_fi', 'volume_em', 'volume_sma_em', 'volume_vpt', 'volume_vwap', 'volatility_bbm', 'volatility_bbh', 'volatility_bbl', 'volatility_bbw', 'volatility_bbp', 'volatility_bbhi', 'volatility_bbli', 'volatility_kcc', 'volatility_kch', 'volatility_kcl', 'volatility_kcw', 'volatility_kcp', 'volatility_kchi', 'volatility_kcli', 'volatility_dcl', 'volatility_dch', 'volatility_dcm', 'volatility_dcw', 'volatility_dcp', 'trend_macd', 'trend_macd_signal', 'trend_macd_diff', 'trend_sma_fast', 'trend_sma_slow', 'trend_ema_fast', 'trend_ema_slow', 'trend_vortex_ind_pos', 'trend_vortex_ind_neg', 'trend_vortex_ind_diff', 'trend_trix', 'trend_mass_index', 'trend_dpo', 'trend_kst', 'trend_kst_sig', 'trend_kst_diff', 'trend_ichimoku_conv', 'trend_ichimoku_base', 'trend_ichimoku_a', 'trend_ichimoku_b', 'trend_stc', 'momentum_rsi', 'momentum_stoch_rsi', 'momentum_stoch_rsi_k', 'momentum_stoch_rsi_d', 'momentum_tsi', 'momentum_uo', 'momentum_stoch', 'momentum_stoch_signal', 'momentum_wr', 'momentum_ao', 'momentum_roc', 'momentum_ppo', 'momentum_ppo_signal', 'momentum_ppo_hist', 'momentum_pvo', 'momentum_pvo_signal', 'momentum_pvo_hist', 'others_dr', 'others_dlr', 'others_cr'

after this, I pass it through fastai.tabular ... shift a period of time, and get results as prediction (this was my old python ml ... now I will use deep learning).


I hope I can make it possible to do the same in mql5 ... just need to make the libraries.

 
Javier Santiago Gaston De Iriarte Cabrera #:

mt5 gives good data, I've tried it and has not given errors ... but I also use ta library with fillna=true


I use ta library ... check it ... that uses this parameters that I use as inputs for the ml .... :


after this, I pass it through fastai.tabular ... shift a period of time, and get results as prediction (this was my old python ml ... now I will use deep learning).


I hope I can make it possible to do the same in mql5 ... just need to make the libraries.

So you are getting a sequence of bars and try to guess the next bar 

 
Lorentzos Roussos #:

So you are getting a sequence of bars and try to guess the next bar 

yep.... more exactly the close or high or low.... thats whats already done... but I hope it will get better results using  deep learning .... 


NormalizeDouble (in mql5)


from keras.layers import BatchNormalization (but this is for images)

to normalize price data:

def sigmoid(x): return 1 (1 + math.exp(-x))

( Deep Reinforcement Learning for Trading with TensorFlow 2.0 (mlq.ai) )

What I'm now traying, is to make an executable from a .py (autopytoexe) and from there with visual a dll. Lets see if this works... If I can use all ta features as inputs for dl it might give better results (at least I need to check it).

Deep Reinforcement Learning for Trading with TensorFlow 2.0
Deep Reinforcement Learning for Trading with TensorFlow 2.0
  • www.mlq.ai
In this guide we'll discuss the application of using deep reinforcement learning for trading with TensorFlow 2.0. In this article, we'll assume that you're familiar with deep reinforcement learning, although if you need a refresher you can find our full list of RL guides here. Building a Deep Q-Learning Trading Network Stock Market Data...