Discussing the article: "Neural Networks in Trading: Probabilistic Time Series Forecasting (Conclusion)"
I’ve been having a few issues with VAE.mqh and have found that the following works quite well as a workaround.
bool CVAE::calcInputGradients(CNeuronBaseOCL *NeuronOCL) { if(!OpenCL || !NeuronOCL) return false; //--- if(!OpenCL.SetArgumentBuffer(def_k_VAECalcHiddenGradient, def_k_vaehg_input, NeuronOCL.getOutput().GetIndex())) return false; if(!OpenCL.SetArgumentBuffer(def_k_VAECalcHiddenGradient, def_k_vaehg_inp_grad, NeuronOCL.getGradient().GetIndex())) return false; if(!OpenCL.SetArgumentBuffer(def_k_VAECalcHiddenGradient, def_k_vaehg_random, m_cRandom.GetIndex())) return false; if(!OpenCL.SetArgumentBuffer(def_k_VAECalcHiddenGradient, def_k_vaehg_gradient, Gradient.GetIndex())) return false; if(!OpenCL.SetArgument(def_k_VAECalcHiddenGradient, def_k_vaehg_kld_mult, m_fKLD_Mult)) return false; // Calculate appropriate work sizes uint neurons_count = (uint)Neurons(); uint local_size = 64; // or 32, 128, 256, depending on your GPU // Round up the global size so that it is divisible by the local size uint global_size = ((neurons_count + local_size - 1) / local_size) * local_size; uint work_offset[] = {0}; uint work_size[] = {global_size}; uint local_work_size[] = {local_size}; if(!OpenCL.Execute(def_k_VAECalcHiddenGradient, 1, work_offset, work_size, local_work_size)) return false; //--- return true; }
I also followed the same testing procedure: first, I used Study to train the model on historical data 1,000,000 times and generated the relevant nnw files. I then used StudyOnline to train the model on one year’s worth of data (at this stage, there was no profit; the $10,000 account ran out of funds very quickly, and I updated some of the nnw files once the run had finished).Finally, the results from Test were broadly consistent with those from StudyOnline (no profit at all).
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Check out the new article: Neural Networks in Trading: Probabilistic Time Series Forecasting (Conclusion).
As previously mentioned, the model is trained in two consecutive stages. First, we conducted offline training using 15 years of EURUSD price history on the H1 timeframe. This dataset covers all types of market conditions: from prolonged sideways markets to sharp trends, and from calm periods to spikes in volatility. As a result, the model was able to learn from the diversity of market behavior. The Encoder learned to identify key patterns and transform the market state into a compact yet informative representation, which served as the basis for the Agent’s decision-making. The Actor, meanwhile, used feedback from the Critic and the Director to develop a robust strategy capable of performing effectively under various conditions.
This was followed by the second stage — online training using 2024 data, performed in the MetaTrader 5 Strategy Tester. Here, the model operated in near real time, analyzing the market candlestick by candlestick. It encountered noise, random fluctuations, and distortions typical of a live market. This approach made it possible not only to fine-tune the model but also to adapt its behavior to real-world dynamics, improve its strategy, and enhance its robustness in the face of uncertainty.
After training was complete, we tested the model on new data — quotes for January–March 2025 — while keeping all the parameters used during training unchanged. The test results are shown below.

The test results show that the model returned a profit over the selected historical period. Total net profit amounted to $821.90 on an initial deposit of $100.0, indicating capital growth. It should be noted, however, that the profitability ratio (Profit Factor) stands at 1.06, which indicates that profits only slightly exceed losses.Author: Dmitriy Gizlyk