Taking Neural Networks to the next level - page 40

 
Lorentzos Roussos #:

Hi you could import the onnx model on mql5 after you are done.

Why are you using 3 sets ? 

Hi,

Regarding importing the ONNX model into MQL5, from my understanding (and correct me if I'm wrong), transferring a model to MQL5 can be quite challenging and may lead to inefficiencies. This process might result in a loss of complexity and functionality that more advanced frameworks like Python can handle more gracefully.

As for using three datasets, I separate them into training, validation (including hyperparameter optimization), and final testing sets. This approach ensures that the model is trained on one dataset, validated and fine-tuned on another to prevent overfitting, and then tested on an entirely separate dataset to evaluate its performance objectively. Using three distinct sets helps maintain the integrity of the model evaluation and optimizes its generalization capabilities.

I chose Python because integrating with the MetaTrader API is straightforward, and Python also allows for easy interaction with external APIs, such as those for news data. Additionally, Python simplifies working with databases—I’m currently using an Oracle cloud database, but any database would work similarly. This flexibility and ease of integration make Python a more efficient choice for developing and deploying complex models. But that's only my opinion.

Have you been able to achieve any positive results with the models you’ve developed? I’d love to hear about your experiences and any insights you might have.

Best regards!

 
Rafael Grecco #:

Hi,

Regarding importing the ONNX model into MQL5, from my understanding (and correct me if I'm wrong), transferring a model to MQL5 can be quite challenging and may lead to inefficiencies. This process might result in a loss of complexity and functionality that more advanced frameworks like Python can handle more gracefully.

As for using three datasets, I separate them into training, validation (including hyperparameter optimization), and final testing sets. This approach ensures that the model is trained on one dataset, validated and fine-tuned on another to prevent overfitting, and then tested on an entirely separate dataset to evaluate its performance objectively. Using three distinct sets helps maintain the integrity of the model evaluation and optimizes its generalization capabilities.

I chose Python because integrating with the MetaTrader API is straightforward, and Python also allows for easy interaction with external APIs, such as those for news data. Additionally, Python simplifies working with databases—I’m currently using an Oracle cloud database, but any database would work similarly. This flexibility and ease of integration make Python a more efficient choice for developing and deploying complex models. But that's only my opinion.

Have you been able to achieve any positive results with the models you’ve developed? I’d love to hear about your experiences and any insights you might have.

Best regards!

You could validate similarity by comparing the outputs [of the model] on the training set on python and mql5. If you find inconsistency it means the Onnx on this side is not up to speed yet.

Interesting , so you backprop with the training set and manage the learning rate with the 2nd set ?

You avoid accidental overfits this way i guess 

 
Lorentzos Roussos #:

You could validate similarity by comparing the outputs [of the model] on the training set on python and mql5. If you find inconsistency it means the Onnx on this side is not up to speed yet.

Interesting , so you backprop with the training set and manage the learning rate with the 2nd set ?

You avoid accidental overfits this way i guess 

I could migrate my model to MQL5 and compare whether its behavior is the same or similar to my Python model. However, honestly, since I already have the model in Python, I don't see an advantage in migrating to MQL5. The main reason I found it easier to create the model using Python is because it has a more extensive library, but it might be possible to do everything directly in MQL5, although my research suggests otherwise.

Regarding the datasets, yes, the idea is to use different sets for training, validation, and final testing precisely to avoid overfitting. I use the training set to perform backpropagation and update the model's weights, while the second set (validation set) is used to monitor performance and adjust the learning rate as needed. This approach helps prevent overfitting and ensures that the learning rate is optimized based on the model's performance on unseen data.

Since I already trade the Dow Jones index manually, I'm training the model on three years of data (2019-2021). Validation and optimization will occur on two years of data (2022-2023), and the final test will be on one year (2024). The final test serves to confirm that the results after training and optimization remain consistent. Additionally, it's important to use the datasets in chronological order so that the final test takes place in the most recent period (2024), which is more current and more likely to represent the current state of the market.

The most challenging part (after having the entire structure ready) is deciding which agent, environment, model, actions, states, rewards, etc., to use in training the model. There are so many variables and parameters that it's difficult to find a combination that results in stable learning and consistently profitable outcomes. But I'm making progress.

Do you have any combinations that are working well for you?

 
Rafael Grecco #:

I could migrate my model to MQL5 and compare whether its behavior is the same or similar to my Python model. However, honestly, since I already have the model in Python, I don't see an advantage in migrating to MQL5. The main reason I found it easier to create the model using Python is because it has a more extensive library, but it might be possible to do everything directly in MQL5, although my research suggests otherwise.

Regarding the datasets, yes, the idea is to use different sets for training, validation, and final testing precisely to avoid overfitting. I use the training set to perform backpropagation and update the model's weights, while the second set (validation set) is used to monitor performance and adjust the learning rate as needed. This approach helps prevent overfitting and ensures that the learning rate is optimized based on the model's performance on unseen data.

Since I already trade the Dow Jones index manually, I'm training the model on three years of data (2019-2021). Validation and optimization will occur on two years of data (2022-2023), and the final test will be on one year (2024). The final test serves to confirm that the results after training and optimization remain consistent. Additionally, it's important to use the datasets in chronological order so that the final test takes place in the most recent period (2024), which is more current and more likely to represent the current state of the market.

The most challenging part (after having the entire structure ready) is deciding which agent, environment, model, actions, states, rewards, etc., to use in training the model. There are so many variables and parameters that it's difficult to find a combination that results in stable learning and consistently profitable outcomes. But I'm making progress.

Do you have any combinations that are working well for you?

Yeah you could take 10 samples , run them in mql5 with the onnx and output the outputs of the network in a file.

then run the same 10 samples on python and output the outputs of the network in a file.

if the outputs match then mql's onnx is up to speed with what you have used in python.

Not with python's libraries for onnx but with what you have used in that model. 

 

Forum on trading, automated trading systems and testing trading strategies

Better NN EA

Sergey Golubev, 2025.02.28 17:59

Neural Network in Practice: Sketching a Neuron

Neural Network in Practice: Sketching a Neuron

In the previous article Neural Network in Practice: Pseudoinverse (II), I discussed the importance of dedicated computational systems and the reasons behind their development. In this new article related to neural networks, we will delve deeper into the subject. Creating material for this stage is no simple task. Despite appearing straightforward, explaining something that often causes significant confusion can be quite challenging.

What will we cover at this stage? In this series, I aim to demonstrate how a neural network learns. So far, we have explored how a neural network establishes correlations between different data points.


 

Forum on trading, automated trading systems and testing trading strategies

Better NN EA

Sergey Golubev, 2025.03.11 06:53

Neural Networks in Trading: State Space Models

Neural Networks in Trading: State Space Models

In recent times, the paradigm of adapting large models to new tasks has become increasingly widespread. These models are pre-trained on extensive datasets containing arbitrary raw data from a broad spectrum of domains, including text, images, audio, time series, and more.


 
Sergey Golubev #:
State Space Models

Thank you for sharing this information! I've been using MLP and CNN on my models, but SSM seems really interesting. It's a bit trickier to implement because it's very new, but I'll test it!

 

I started playing around with SSM, based on the shared article. At first I was going for the Mamba approach, but I ran into some technical stuff that made me fall back to classic S4 instead. Honestly though, using State Space Models made a huge difference — really appreciate the information shared here.

Also gave PPO with RNN a try, just to see what would happen. But in my case, the RNN didn’t seem to help much — kinda felt redundant with SSM. So I ended up sticking with plain PPO, and it’s been working fine.

Now here’s the weird part: I’ve been experimenting with reinforcement learning using a bit of intentional data leakage. I know, sounds wrong — data leakage is supposed to be a big problem. But the idea was to let the model peek a little into the future during training, in a controlled way. Turns out it actually helps the model understand and converge faster. What’s cool is that when I validate it (no leakage, unseen data, clean setup), it still performs better than models trained the "proper" way.

Just thought I’d share. Curious if anyone else has played with stuff like this.

 

Neural Networks in Trading: Optimizing the Transformer for Time Series Forecasting (LSEAttention)

Neural Networks in Trading: Optimizing the Transformer for Time Series Forecasting (LSEAttention)

Multivariate time series forecasting plays a critical role across a wide range of domains (finance, healthcare, and more) where the objective is to predict future values based on historical data. This task becomes particularly challenging in long-term forecasting, which demands models capable of effectively capturing feature correlations and long-range dependencies in multivariate time series data. Recent research has increasingly focused on leveraging the Transformer architecture for time series forecasting due to its powerful Self-Attention mechanism, which excels at modeling complex temporal interactions. However, despite its potential, many contemporary methods for multivariate time series forecasting still rely heavily on linear models, raising concerns about the true effectiveness of Transformers in this context.
Neural Networks in Trading: Optimizing the Transformer for Time Series Forecasting (LSEAttention)
Neural Networks in Trading: Optimizing the Transformer for Time Series Forecasting (LSEAttention)
  • 2025.07.14
  • www.mql5.com
The LSEAttention framework offers improvements to the Transformer architecture. It was designed specifically for long-term multivariate time series forecasting. The approaches proposed by the authors of the method can be applied to solve problems of entropy collapse and learning instability, which are often encountered with vanilla Transformer.
 

Neural Networks in Trading: Enhancing Transformer Efficiency by Reducing Sharpness (SAMformer)

Neural Networks in Trading: Enhancing Transformer Efficiency by Reducing Sharpness (SAMformer)

Multivariate time series forecasting is a classical machine learning task that involves analyzing time series data to predict future trends based on historical patterns. It is a particularly challenging problem due to feature correlations and long-term temporal dependencies. This learning problem is common in real-world applications where observations are collected sequentially (e.g., medical data, electricity consumption, stock prices).
Neural Networks in Trading: Enhancing Transformer Efficiency by Reducing Sharpness (SAMformer)
Neural Networks in Trading: Enhancing Transformer Efficiency by Reducing Sharpness (SAMformer)
  • 2025.07.21
  • www.mql5.com
Training Transformer models requires large amounts of data and is often difficult since the models are not good at generalizing to small datasets. The SAMformer framework helps solve this problem by avoiding poor local minima. This improves the efficiency of models even on limited training datasets.