Discussing the article: "Neural Networks in Trading: A Spatio-Temporal State Model for Financial Data Analysis (Conclusion)"
The initial problem
I ran an E-STMFlow training run on one month’s worth of data (3 epochs). I encountered two critical issues:
1. STFS error >1,500 — the model was unable to predict future market states
2. The Actor did not open any positions (0 out of 441 iterations) — the outputs were stuck around 0.5
Stage 1: Diagnostics via logging
I added comprehensive logging to understand the training process:
- Tracking STFS, Actor and Critic errors by epoch
- Logging of Actor actions versus Oracul (reference strategy)
- Monitoring the outputs of each layer of the neural network
- Statistics on open positions, lots, TP/SL
- Detailed analysis of the Encoder’s latent representations
Result: It was found that the raw features had different scales (prices ~1.13, volumes ~1,000+, indicators -100 to +100), which caused the STFS to collapse.
Stage 2: Feature normalisation
Implemented normalisation of all input features:
- (Close-Open), (High-Open), (Low-Open), MACD, Signal → divided by ATR
- Volume → divided by 100, capped at 10
- RSI → converted to the range [-1, 1]
- CCI → divide by 100, clip to [-3, 3]
- ATR → normalised relative to the closing price
Result: STFS error fell from ~1600 to 0.42 ✅
Stage 3: Problem with the Actor
Despite the STFS fix, the Actor was still not opening positions. Deep logging revealed:
- The VAE layer (Layer 5) had collapsed: avg=0.5009, std=0.0022
- Actor outputs: [0.4986, 0.4987, 0.5010, 0.5013, 0.4973, 0.4997]
- The difference between buy_lot and sell_lot = 0.0002 (must be >0.01 to open a position)
Stage 4: Replacing VAE with SpikeConv
I checked that the code matched the original E-STMFlow paper. I found that the VAE layer is not part of the E-STMFlow concept (the paper describes spiking mechanisms). I replaced `defNeuronVAEOCL` with `defNeuronSpikeConv`.
Result after 3 epochs:
- SpikeConv: avg=0.5885, std=0.0582 (25 times better than VAE!)
- But the Actor still hadn’t opened any positions
Stage 5: Extended training (breakthrough!)
Ran training for 30 epochs instead of 3. Results for Epochs 23–28:
✅ The Actor is working!
- Positions: 3,012 out of 3,012 (100% activity)
- Lot sizes: 0.0152–0.0154 (stable sizes)
- SpikeConv3: avg=0.9583, std=0.1382 (excellent variability)
- Actor Error: decreased from 0.2487 to 0.2216 (-2.85%)
- Raw Actor: [0.4485, 0.4450, 0.4279, 0.4637, 0.4589, 0.4416] — sufficient spread to open positions
Current issues (requiring further training):
1. The Actor opens only SELL positions (0 BUY positions) — a systematic bias in exits
2. Overtrading: Actor is active on 100% of bars compared to Oracul’s 32% — has not learnt to ‘not trade’
Key conclusions
1. Normalisation is critical — without it, STFS collapses
2. SpikeConv >> VAE — std increased from 0.002 to 0.138
3. A minimum of 20–30 epochs is essential — the layers ‘thaw’ gradually
4. Logging saved the project — without detailed diagnostics, we would not have found the root cause of the problem
---
Question
Given that the problem was due to an insufficient number of epochs, rather than the SpikeConv architecture:
Will the original VAE layer work if trained for 30+ epochs?
Comparison after 3 epochs:
- VAE: std=0.0022 (almost complete collapse)
- SpikeConv: std=0.0582 (variability is already present)
Perhaps the VAE simply requires even more epochs to ‘thaw’? Or is its architecture fundamentally incompatible with the task of generating trading actions in E-STMFlow?
Should we revert to VAE and test it over 50–100 epochs for the sake of experimental purity?
Vladimir Sanin #:
Good evening, ---
Question
Given that the problem lay in the insufficient number of epochs, rather than in the SpikeConv architecture:
Will the original VAE layer work when trained for 30+ epochs?
Comparison after 3 epochs:
- VAE: std=0.0022 (almost complete collapse)
- SpikeConv: std=0.0582 (variability is already present)
Perhaps the VAE simply requires even more epochs to ‘unfreeze’? Or is its architecture fundamentally incompatible with the task of generating trading actions in E-STMFlow?
Should we bring the VAE back and test it over 50–100 epochs to ensure the experiment is rigorous?
Training for 3 or even 30 epochs is very little. In ‘...\Experts\NeuroNet_DNG\NeuroNet.mqh’, the learning rate is set to
#define lr 1.0 e-6 f ///<learning rateUsing a VAE, unlike other types of neural layers, allows you to learn the boundaries of the distribution of values, rather than just the mean.
And yes, E-STMFlow does not support either VAEs or the Actor-Critic model as such.
Dmitriy Gizlyk #:
Good evening,
Training for 3 or even 30 epochs is far too little. In ‘...\Experts\NeuroNet_DNG\NeuroNet.mqh’, the learning rate is set to
. Unlike other types of neural layers, using a VAE allows you to learn the boundaries of the distribution of values, rather than just the mean.
And yes, E-STMFlow does not support either VAEs or the Actor-Critic model as such.
I’m very pleased to receive your feedback. I suspect that even 100 epochs won’t yield high-quality training. But the funny thing is that even on a rented server with a good GPU, the training process is extremely slow. Neither the CPU nor the GPU is utilised to full capacity, averaging only about 10 per cent. To run 1,000+ epochs, I’ll have to keep the server running for at least two weeks... The problem is that the code runssequentially on the CPU, despite OpenCL being initialised.Good evening,
Training for 3 or even 30 epochs is far too little. In ‘...\Experts\NeuroNet_DNG\NeuroNet.mqh’, the learning rate is set to
. Unlike other types of neural layers, using a VAE allows you to learn the boundaries of the distribution of values, rather than just the mean.
And yes, E-STMFlow does not support either VAEs or the Actor-Critic model as such.
Main performance issues:
1.Sequential processing on the CPU instead of batching on the GPU
. The code processes each position in turn within a loop. For each bar, the following is executed:- feedForward for the Encoder, STFS, Actor and Critic
- backProp for each network
- This
- ~1,500 bars × 100 epochs = 150,000 sequential iterations
2. Multiple CPU-GPU synchronisations
EachfeedForward/backProp call requires data transfer between the CPU and GPU, creating a huge overhead.3. Inefficient use of BatchSize
. BatchSize is set to 1e4, but the code processes one example at a time instead of in batches.As a result, I’ve decided to try porting your idea to Python, using the source code from the original article as a basis and adapting it according to your approach. Let’s see how it turns out. Or perhaps you could suggest a performance solution for MQL5? Or at least point me in the right direction?
Vladimir Sanin #:
I’m really pleased to hear your feedback. I suppose that even 100 epochs wouldn’t be enough for high-quality training. But the funny thing is that even on a rented server with a good GPU, the training process is extremely slow. Neither the CPU nor the graphics card is utilised to full capacity, averaging only about 10 per cent. To run 1,000+ epochs, I’ll have to keep the server running for at least two weeks... The problem is that the code runssequentially on the CPU, despite OpenCL being initialised.
As a result, I’ve decided to try porting your idea to Python, using the source code from the original article as a basis and adapting it according to your approach. Let’s see how it turns out. Or perhaps you could suggest a performance solution for MQL5? Or at least point me in the right direction?
...Oh yes, if only it were in Python...
I’m really pleased to hear your feedback. I suppose that even 100 epochs wouldn’t be enough for high-quality training. But the funny thing is that even on a rented server with a good GPU, the training process is extremely slow. Neither the CPU nor the graphics card is utilised to full capacity, averaging only about 10 per cent. To run 1,000+ epochs, I’ll have to keep the server running for at least two weeks... The problem is that the code runssequentially on the CPU, despite OpenCL being initialised.
Main performance issues:
1.Sequential processing on the CPU instead of batching on
the GPU. The code processes each position one by one in a loop. For each bar, the following is executed:- feedForward for the Encoder, STFS, Actor and Critic
- backProp for each network
- This
- ~1,500 bars × 100 epochs = 150,000 sequential iterations
2. Multiple
CPU–GPUsynchronisations:
EachfeedForward/backPropcall requires data transfer between the CPU and GPU, creating a huge overhead.3. Inefficient use
of BatchSize: BatchSize is set to 1e4, but the code processes one example at a time instead of in batches.As a result, I’ve decided to try porting your idea to Python, using the source code from the original article as a basis and adapting it according to your approach. Let’s see how it turns out. Or perhaps you could suggest a performance solution for MQL5? Or at least point me in the right direction?
Check out the new article: Neural Networks in Trading: A Spatio-Temporal State Model for Financial Data Analysis (Conclusion).
The first stage of training is based on historical data and is similar to a beginner trader's practice session on a major exchange. Imagine the EURUSD chart from January 2024 to June 2025 as a canvas full of hidden patterns. Like an attentive student, the model scrutinizes every candlestick, tracks volume, analyzes market reactions to indicators, and identifies patterns. Our implementation of the E-STMFlow framework's encoder makes it possible to detect the slightest price fluctuations while also identifying broader trends. It generates an informative state for the Actor and the Critic, combines features of different scales, and learns alongside the model. With each new step, the model gradually becomes a confident trader capable of making independent decisions.
The next stage — online training in the MetaTrader 5 Strategy Tester—is no longer just a rehearsal, but intensive skills practice. There is no convenient historical data here; each candlestick represents a live pulse of the real market. The model reacts instantly, evaluates noise fluctuations, adapts to sudden spikes, and adjusts its actions during periods of low liquidity. CNeuronESTMEncoder synchronizes the operation of all blocks, integrates features across different scales, and continues learning alongside the model, resulting in flexible and stable behavior.
The final skills assessment uses data from July through October 2025. There are no clues here, and no way to rely on the past — only the market and the model's decisions. Every move hones the ability to combine features of different scales, anticipate market reactions, and act with precision. The test results demonstrate how the implemented solution transforms a complex architecture into a cohesive, adaptive, and efficient trading system.
Author: Dmitriy Gizlyk