Neural Networks in Trading: Mesh Approximation of Event Streams as a Tool for Analyzing Price Patterns (MDC Module)
Introduction
Building on the ideas presented in the previous article, we move on to the next stage — an analysis of the architecture and practical implementation of the EEMFlow framework using MQL5. In the previous step, we discussed the nature of event data. We demonstrated how regular price series are less informative than microstructural flows, and explained why the shift toward event-driven approaches is a logical step for modern trading systems. Now we need to build on this foundation and delve deeper into the technical aspects of the model, translating abstract principles into specific algorithms.
Viewed without romanticism, the market is a dynamic system characterized by the continuous redistribution of liquidity. Every event — whether it's a tick change, the appearance of a new order, a surge in buyer aggression, or a narrowing of the spread — is a signal indicating the internal state of this system. And the faster the market moves and the more closely participants interact, the harder it is to identify cause-and-effect relationships using simple analytical methods. This is exactly where the practical value of EEMFlow comes into play. It allows us not only to record the sequence of events, but also to transform it into a compact and stable representation in which movement is revealed as a structural rather than a random process.
The framework's architecture is built around several key components that operate sequentially. The model receives a sequence of events as input — ordered segments of market activity that reflect local dynamics. In the first stage, the data passes through the Adaptive Density Module (ADM), which adjusts the event density based on local conditions. In market data, event density often fluctuates: there may be few events during quiet periods, and many during periods of sharp price movements. ADM accounts for these variations, ensuring that the model receives appropriate input regardless of how dense or sparse the data is.
The adapted data is then fed into a pyramidal encoder, which is responsible for converting events into compact embeddings. These embeddings capture information about the spatiotemporal relationships between events and present them in a format that is easy to analyze. This approach helps avoid redundancy and allows us to focus on the essential features of motion.
The adapted embeddings are fed into the Multiscale Feature Correlation (MSFC) module. This module is responsible for matching features across different spatial scales and temporal horizons, establishing robust correlations between local and global motion patterns. MSFC allows the model to account for how small local changes interact with large-scale movements, which is particularly important for dynamic, non-stationary event streams.
Next, Meshflow Estimation is performed based on the correlated features. This is where a directional motion field (MeshFlow) is generated, reflecting large-scale displacement and global motion patterns. MeshFlow serves as the foundation for subsequent forecasts, transforming a stream of disparate events into a structured representation of motion suitable for analysis and trading decisions.
The process is completed by the Confidence-Induced Detail Completion (CDC) block, which restores local motion details while preserving sharp boundaries and accurately capturing minute changes.

A particularly important part of the architecture is the Adaptive Density Module (ADM). In real-world market data, events do not always occur at a steady rate — periods of high activity are followed by periods of calm. While event density is often high in high-frequency data, the data becomes sparse during periods of low activity. This poses challenges for any models that process such streams, because without proper adaptation, they either miss important details or start reacting to random noise.
ADM solves this problem by automatically adapting the data being analyzed based on its density. For example, when event density is low, the module increases the significance of individual events to compensate for the sparsity. Conversely, during sharp movements, it reduces the impact of each individual event to avoid distortion. This helps maintain the model's stability by preventing it from missing important patterns during periods of low activity and from becoming overloaded during sudden spikes.
Such adaptation is critical for financial markets. Volatility and periods of low liquidity are an inevitable reality. Without such adaptation, the model will either be too noisy during quiet periods or lose sensitivity to important signals in a rising market.

In the practical section of the previous article, we began working on building individual ADM components. And today we're continuing the work we've started.
Feature Alignment Module
The Adaptive Density Module (ADM) adapts the density of an event stream to changing data conditions. ADM consists of two submodules:
- Multi-Density Changer (MDC),
- Multi-Density Selector (MDS).
MDC is responsible for globally adjusting the density of the event representations being analyzed across multiple scales, while MDS selects the optimal pixel density for subsequent optical flow calculation.
MDC uses a three-level Encoder-Decoder architecture. Combined event representations are supplied as input and then pass through three encoding blocks to extract features at different scales. After that, three decoding blocks reconstruct the information, and two feature fusion blocks ensure the integration of multiscale information. As a result, MDC generates a set of multiscale representations.
The Feature Alignment Module (FAM) is built into MDC and is responsible for feature alignment across different scales. It ensures that local micro-impulses and large-scale movement trends are correctly integrated into multiscale representations, forming a stable foundation for subsequent blocks.
In our implementation, the new CNeuronSpikeFAM class implements a spiking version of the Feature Alignment Module (FAM) and plays a key role in preparing data for subsequent motion analysis blocks. Its primary task is to align and harmonize features obtained at different scales, forming a coherent and structured representation of event motion information. The module's spiking nature allows the model to process event streams in the same way that neurons in the brain respond to a sequence of impulses, detecting sudden changes and instantaneous bursts of activity. In practice, this means that the model takes into account both micro-changes and major trends simultaneously, which is critical for the financial market. After all, every fluctuation in volume or sharp price spike can be significant for forecasting.
To implement this functionality, the object combines several components. The cProduct base block is used for the initial processing of the features being analyzed and prepares them for subsequent transformation. cActivation provides nonlinear activation, allowing the module to respond flexibly to event impulses. The core of FAM's operation lies in the multiscale convolutional block cConv, which extracts features at different scales and aligns them within a unified structure, creating a spiking representation. This is where a coherent picture of motion is formed. Local micro-impulses and global trends come together to form a comprehensive representation, which ensures accuracy in building MeshFlow.
The Init method handles the initial setup of the module's internal components. This method prepares all FAM elements to handle event streams and lays the foundation for correct feature alignment.
bool CNeuronSpikeFAM::Init(uint numOutputs, uint myIndex, COpenCLMy *open_cl, uint window, uint units_count, uint variables, ENUM_OPTIMIZATION optimization_type, uint batch) { if(!CNeuronBatchNormOCL::Init(numOutputs, myIndex, open_cl, window * units_count * variables, batch, optimization_type)) return false; activation = None;
First, base initialization is performed using the parent class. This step ensures that the module's basic structure is ready for operation and capable of processing input data with the required accuracy.
Next, the internal components are initialized sequentially. The base cProduct feature processing block is configured to run without activation at this stage in order to preserve the raw form of the input data.
if(!cProduct.Init(0, 0, OpenCL, Neurons(), optimization, iBatch)) return false; cProduct.SetActivationFunction(None);
Next, the cActivation activation block is initialized; it will perform a spiking transformation of the features in response to instantaneous pulses in the event stream.
if(!cActivation.Init(0, 1, OpenCL, Neurons(), optimization, iBatch)) return false;
Special attention is given to the cConv convolution block, which receives the window parameters and the number of variables required for feature alignment. This block combines local micro-impulses and global motion trends into a single structure.
uint windows[] = {3 * window}; if(!cConv.Init(0, 2, OpenCL, windows, window, window, units_count, variables, optimization, iBatch)) return false; cConv.SetActivationFunction(None); //--- return true; }
It is worth noting that although a multi-window convolution object is used to process features, only one window is actually passed in the array. Its size is three times the corresponding dimension of the input data. This setting is necessary for convolution with zero padding: it allows the influence of neighboring elements on the signal being analyzed to be taken into account without changing the sequence length. In other words, each data point is evaluated in the context of its surroundings, which is particularly important for financial data streams, where the accuracy of local change analysis directly affects price movement forecasts.
As a result, the initialization call fully prepares the module for operation, ensuring that all internal components are properly configured and ready to process real-time market event streams. This is the foundation for the operation of the entire spiking FAM.
The next step in our work is to set up a forward pass for data through FAM, which is implemented using the feedForward method. At this stage, the events under analysis undergo a series of sequential transformations, resulting in an aligned feature representation.
bool CNeuronSpikeFAM::feedForward(CNeuronBaseOCL *NeuronOCL, CBufferFloat *SecondInput) { if(!NeuronOCL || !SecondInput) return false;
First, the method checks that the pointers to the input stream objects are valid to ensure that the source data is ready for processing.
Next, the two feature streams — the main and the supplementary — are multiplied element-by-element. This allows the model to simultaneously take into account different sources of information and correctly correlate local impulses with global trends.
if(!ElementMult(NeuronOCL.getOutput(), SecondInput, cProduct.getOutput())) return false;
The data then passes through an activation block, which generates a spiking representation in response to instantaneous changes in the event stream.
if(!cActivation.FeedForward(cProduct.AsObject())) return false;
Next, the convolution object is invoked to combine the features, aligning them and taking neighboring elements into account. This is especially important for financial data streams, where every tick impulse can contain significant information about price movements.
if(!cConv.FeedForward(cActivation.AsObject())) return false;
After convolution, the data undergoes normalization, which ensures the stability of the values and prepares the features for further analysis.
if(!CNeuronBatchNormOCL::feedForward(cConv.AsObject())) return false;
Finally, residual connections are added to produce the final aligned feature representation, ready to be passed to subsequent blocks of the model.
if(!SumAndNormilize(NeuronOCL.getOutput(), Output, Output, GetWindow(), true, 0, 0, 0, 1)) return false; //--- return true; }
Thus, the feedForward method transforms disparate events from two sources into a structured, spiking representation that accounts for both local and global movement patterns. This ensures the accuracy and reliability of financial market forecasts.
In the context of ADM and MDC, the spiking version of FAM plays a central role. It forms an aligned multiscale spiking feature representation. This approach allows traders to analyze market events in real time, adapt to varying event densities, take into account local and global price movement patterns, and obtain accurate predictions even under conditions of high volatility or low liquidity. The module's spiking nature makes processing more natural and responsive to instantaneous market changes, transforming the stream of events into a structured and informative representation for making trading decisions.
Multi-Density Changer Module
Once the construction of the spiking FAM is complete and we have obtained an aligned multiscale feature representation, we move up one level in the ADM hierarchy and proceed to construct the Multi-Density Changer (MDC). While FAM ensured the accuracy and alignment of local and global features, MDC is responsible for global adaptation of event density. This module adjusts the analyzed representations at multiple scales, adapting them to fluctuating market activity.
Using MDC, the model can account for periods of high activity, when events occur almost simultaneously, and quiet periods, when the data stream is sparse and infrequent. This is especially important for traders. MDC allows the model to retain key signals while avoiding false positives when processing noisy or sparse data.
The MDC architecture is based on a three-level Encoder-Decoder framework, in which three encoding blocks extract features at different scales, and three decoding blocks, together with feature fusion blocks, form a multiscale, coherent representation. All operations are performed efficiently, with minimal impact on computing resources, which enables real-time processing of event streams.
To implement the Multi-Density Changer (MDC) functionality as part of this project, we are creating a new class called CNeuronSpikeMDC. This object takes data processing to the next level after the spiking FAM, enabling the model to respond effectively to market dynamics.
class CNeuronSpikeMDC : public CNeuronBatchNormOCL { protected: CLayer cSCMs; CLayer cFAMs; CLayer cAFFs; CLayer cProjects; CLayer cProjectsOut; CLayer cFeatExtracts; CNeuronBaseOCL cConcatOut; //--- virtual bool feedForward(CNeuronBaseOCL *NeuronOCL) override; virtual bool updateInputWeights(CNeuronBaseOCL *NeuronOCL) override; virtual bool calcInputGradients(CNeuronBaseOCL *NeuronOCL) override; public: CNeuronSpikeMDC(void) {}; ~CNeuronSpikeMDC(void) {}; //--- virtual bool Init(uint numOutputs, uint myIndex, COpenCLMy *open_cl, uint window, uint window_out, uint units_count, uint variables, ENUM_OPTIMIZATION optimization_type, uint batch); //--- virtual int Type(void) override const { return defNeuronSpikeMDC; } //--- methods for working with files virtual bool Save(int const file_handle) override; virtual bool Load(int const file_handle) override; //--- virtual void SetOpenCL(COpenCLMy *obj) override; //--- virtual bool WeightsUpdate(CNeuronBaseOCL *source, float tau) override; //--- virtual void SetActivationFunction(ENUM_ACTIVATION value) override { }; virtual void TrainMode(bool flag) override; virtual bool Clear(void) override; };
Within the class, a sequence of layers and components has been implemented that collectively enable the module to function.
The cSCMs channel scaling blocks perform initial feature scaling by setting the relative importance of each channel in the data stream. Essentially, this block determines which elements of the input stream are most valuable for analysis and which can be slightly attenuated without losing key information. This is similar to the work of an experienced trader who selects the most important signals from a multitude of market signals, ignoring the noise. The result is a balanced representation that is tailored to the event density.
The cFAMs array is responsible for integrating the Feature Alignment Module (FAM), the spiking version of the feature alignment module. Its purpose is to ensure the alignment of features obtained at different scales, creating a structured, multiscale representation. This allows for the creation of a representation tailored to the event density, where every detail has its own significance and contributes to the accuracy of price movement forecasts.
The cAFFs modules are responsible for adaptive feature fusion, carefully combining data from different scales to create a coherent representation. As a result, the model sees a comprehensive picture of the market: local impulses and global trends are integrated without losing their significance.
The cProjects and cProjectsOut blocks project features into a suitable space, preparing them for subsequent fusion. They organize the information into a compatible form for final aggregation.
Finally, the cFeatExtracts block plays a key role in feature extraction: it transforms the raw event stream into structured, multiscale signals that can be used to accurately predict price movements.
The initialization method coordinates the assembly and configuration of the entire module, transforming disparate components into a ready-to-use tool for analyzing a multiscale event stream. Its task is not simply to create objects, but to arrange them into a logical sequence in which each layer, each block, and each element plays its own role, creating a unified, adapted feature representation for further analysis of price movements.bool CNeuronSpikeMDC::Init(uint numOutputs, uint myIndex, COpenCLMy *open_cl, uint window, uint window_out, uint units_count, uint variables, ENUM_OPTIMIZATION optimization_type, uint batch) { if(!CNeuronBatchNormOCL::Init(numOutputs, myIndex, open_cl, 3 * window_out * units_count * variables, batch, optimization_type)) return false;
First, basic initialization is performed using the parent class, where the object's key parameters are set. This lays the foundation for all subsequent components, ensuring a uniform data format and consistency at all levels of MDC.
Next, the dynamic arrays are cleared and configured one by one. Each array is passed a pointer to the OpenCL context object, enabling efficient real-time processing of event streams — a critical requirement for financial data. After all, delays can result in the loss of valuable information.
cSCMs.Clear(); cFAMs.Clear(); cAFFs.Clear(); cProjects.Clear(); cProjectsOut.Clear(); cFeatExtracts.Clear(); cSCMs.SetOpenCL(OpenCL); cFAMs.SetOpenCL(OpenCL); cAFFs.SetOpenCL(OpenCL); cProjects.SetOpenCL(OpenCL); cProjectsOut.SetOpenCL(OpenCL); cFeatExtracts.SetOpenCL(OpenCL);
Special attention is given to the cFeatExtracts block, which contains convolution objects with different window sizes and numbers of elements in the sequence. These blocks capture information at various levels: from local micro-impulses to global market trends.
CNeuronSpikeConvBlock* conv = NULL; CNeuronMultiWindowsConvWPadOCL* pad_conv = NULL; CNeuronSpikeSCM* scm = NULL; CNeuronSpikeFAM* fam = NULL; CNeuronBaseOCL* neuron = NULL; uint index = 0; uint windows[1]; //--- if(!cConcatOut.Init(numOutputs, myIndex, open_cl, Neurons(), optimization, iBatch)) return false; //--- index++; windows[0] = 3 * window; pad_conv = new CNeuronMultiWindowsConvWPadOCL(); if(!pad_conv || !pad_conv.Init(0, index, OpenCL, windows, window, window_out, units_count, variables, optimization, iBatch) || !cFeatExtracts.Add(pad_conv)) { DeleteObj(pad_conv) return false; } pad_conv.SetActivationFunction(SoftPlus);
The SoftPlus activation function is specified for each block, ensuring smooth and predictable signal transformation. This approach allows the model to account for the influence of neighboring elements without changing the dimensionality of the sequence — a key factor in correctly analyzing tick data.
Please note that a two-step data transformation process takes place here. First, the model expands the feature space by increasing the number of channels to capture as much information as possible about each micro-impulse and the global trend. At the same time, the data sequence is shortened — the model focuses on the most significant elements, leaving out less important details.
index++; windows[0] = 3 * window_out; pad_conv = new CNeuronMultiWindowsConvWPadOCL(); if(!pad_conv || !pad_conv.Init(0, index, OpenCL, windows, 2 * window_out, 2 * window_out, (units_count + 1) / 2, variables, optimization, iBatch) || !cFeatExtracts.Add(pad_conv)) { DeleteObj(pad_conv) return false; } pad_conv.SetActivationFunction(SoftPlus); uint u = pad_conv.GetUnits(); index++; windows[0] = 6 * window_out; pad_conv = new CNeuronMultiWindowsConvWPadOCL(); if(!pad_conv || !pad_conv.Init(0, index, OpenCL, windows, 4 * window_out, 4 * window_out, (u + 1) / 2, variables, optimization, iBatch) || !cFeatExtracts.Add(pad_conv)) { DeleteObj(pad_conv) return false; } pad_conv.SetActivationFunction(SoftPlus);
Once the features have passed through the expansion phase and been processed at various scales, the reverse procedure is performed: the sequence length is restored, and the features are carefully aggregated and fused. This results in a balanced event representation adapted to event density, in which each signal has the appropriate weight and influence on the final forecast of price movement.
u = pad_conv.GetUnits(); index++; windows[0] = 16 * window_out; pad_conv = new CNeuronMultiWindowsConvWPadOCL(); if(!pad_conv || !pad_conv.Init(0, index, OpenCL, windows, 8 * window_out, 16 * window_out, u, variables, optimization, iBatch) || !cFeatExtracts.Add(pad_conv)) { DeleteObj(pad_conv) return false; } pad_conv.SetActivationFunction(SoftPlus); u *= 2; index++; windows[0] = 8 * window_out; pad_conv = new CNeuronMultiWindowsConvWPadOCL(); if(!pad_conv || !pad_conv.Init(0, index, OpenCL, windows, 4 * window_out, 8 * window_out, u, variables, optimization, iBatch) || !cFeatExtracts.Add(pad_conv)) { DeleteObj(pad_conv) return false; } pad_conv.SetActivationFunction(SoftPlus); u *= 2; index++; windows[0] = 3 * window_out; pad_conv = new CNeuronMultiWindowsConvWPadOCL(); if(!pad_conv || !pad_conv.Init(0, index, OpenCL, windows, window_out, window_out, units_count, variables, optimization, iBatch) || !cFeatExtracts.Add(pad_conv)) { DeleteObj(pad_conv) return false; } pad_conv.SetActivationFunction(None);
For a trader, this means that MDC organizes the flow of information, highlighting significant events and presenting a market picture ready for analysis, taking into account local spikes and global trends.
The cProjects and cProjectsOut data projection blocks prepare the features by organizing them and converting them to a uniform format for subsequent fusion. The Adaptive Feature Fusion (cAFFs) block then carefully fuses these data, ensuring a balance between different scales and sources of information. As a result, the model takes into account both local micro-impulses and global trends, forming a coherent and adapted representation of the market.
index++; neuron = new CNeuronBaseOCL(); if(!neuron || !neuron.Init(0, index, OpenCL, 4 * window_out * units_count * variables, optimization, iBatch) || !cProjects.Add(neuron)) { DeleteObj(neuron) return false; } neuron.SetActivationFunction(None); index++; conv = new CNeuronSpikeConvBlock(); if(!conv || !conv.Init(0, index, OpenCL, 4 * window_out, 4 * window_out, 2 * window_out, units_count, variables, optimization, iBatch) || !cProjects.Add(conv)) { DeleteObj(conv) return false; } index++; neuron = new CNeuronBaseOCL(); if(!neuron || !neuron.Init(0, index, OpenCL, 2 * window_out * units_count * variables, optimization, iBatch) || !cProjects.Add(neuron)) { DeleteObj(neuron) return false; } neuron.SetActivationFunction(None); index++; conv = new CNeuronSpikeConvBlock(); if(!conv || !conv.Init(0, index, OpenCL, 2 * window_out, 2 * window_out, window_out, units_count, variables, optimization, iBatch) || !cProjects.Add(conv)) { DeleteObj(conv) return false; }
Here, the features undergo a process of weighting and harmonization, creating a coherent representation in which each element makes an appropriate contribution to the final signal.
index++; windows[0] = 12 * window_out; pad_conv = new CNeuronMultiWindowsConvWPadOCL(); if(!pad_conv || !pad_conv.Init(0, index, OpenCL, windows, 4 * window_out, window_out, units_count, variables, optimization, iBatch) || !cProjectsOut.Add(pad_conv)) { DeleteObj(pad_conv) return false; } pad_conv.SetActivationFunction(None); index++; windows[0] = 6 * window_out; pad_conv = new CNeuronMultiWindowsConvWPadOCL(); if(!pad_conv || !pad_conv.Init(0, index, OpenCL, windows, 2 * window_out, window_out, units_count, variables, optimization, iBatch) || !cProjectsOut.Add(pad_conv)) { DeleteObj(pad_conv) return false; } pad_conv.SetActivationFunction(None); //--- index++; neuron = new CNeuronBaseOCL(); if(!neuron || !neuron.Init(0, index, OpenCL, 7 * window_out * units_count * variables, optimization, iBatch) || !cAFFs.Add(neuron)) { DeleteObj(neuron) return false; } neuron.SetActivationFunction(None); index++; conv = new CNeuronSpikeConvBlock(); if(!conv || !conv.Init(0, index, OpenCL, 7 * window_out, 7 * window_out, window_out, units_count, variables, optimization, iBatch) || !cAFFs.Add(conv)) { DeleteObj(conv) return false; } index++; windows[0] = 3 * window_out; pad_conv = new CNeuronMultiWindowsConvWPadOCL(); if(!pad_conv || !pad_conv.Init(0, index, OpenCL, windows, window_out, window_out, units_count, variables, optimization, iBatch) || !cAFFs.Add(pad_conv)) { DeleteObj(pad_conv) return false; } pad_conv.SetActivationFunction(None); index++; conv = new CNeuronSpikeConvBlock(); if(!conv || !conv.Init(0, index, OpenCL, 14 * window_out, 14 * window_out, 2 * window_out, (units_count + 1) / 2, variables, optimization, iBatch) || !cAFFs.Add(conv)) { DeleteObj(conv) return false; } index++; windows[0] = 6 * window_out; pad_conv = new CNeuronMultiWindowsConvWPadOCL(); if(!pad_conv || !pad_conv.Init(0, index, OpenCL, windows, 2 * window_out, 2 * window_out, (units_count + 1) / 2, variables, optimization, iBatch) || !cAFFs.Add(pad_conv)) { DeleteObj(pad_conv) return false; } pad_conv.SetActivationFunction(None);
The cFAMs block combines two spiking FAM modules, which capture the precise local micro-impulses detected at the previous processing level. These spiking signals allow MDC to detect instantaneous market events, such as sharp price fluctuations or spikes in volume, which can have a decisive impact on forecasts and trading decisions.
index++; fam = new CNeuronSpikeFAM(); if(!fam || !fam.Init(0, index, OpenCL, 4 * window_out, units_count, variables, optimization, iBatch) || !cFAMs.Add(fam)) { DeleteObj(fam) return false; } index++; fam = new CNeuronSpikeFAM(); if(!fam || !fam.Init(0, index, OpenCL, 2 * window_out, units_count, variables, optimization, iBatch) || !cFAMs.Add(fam)) { DeleteObj(fam) return false; }
The cSCMs block performs scaling of the feature channels, adjusting their relative influence on subsequent processing. In practice, this means that the model determines which market signals to amplify and which to temporarily dampen. This scaling allows MDC to adapt to changing event density. For a trader, this ensures that the system will respond only to signals that actually affect the price, thereby increasing the accuracy of forecasts and reducing the likelihood of false entries.
index++; scm = new CNeuronSpikeSCM(); if(!scm || !scm.Init(0, index, OpenCL, 2 * window, 2 * window_out, (units_count + 1) / 2, variables, optimization, iBatch) || !cSCMs.Add(scm)) { DeleteObj(scm) return false; } u = scm.GetUnits(); index++; scm = new CNeuronSpikeSCM(); if(!scm || !scm.Init(0, index, OpenCL, 4 * window, 4 * window_out, (u + 1) / 2, variables, optimization, iBatch) || !cSCMs.Add(scm)) { DeleteObj(scm) return false; } //--- return true; }
Each time a new component is added, a check is performed to verify that it initialized successfully. If an object cannot be created or fails validation, the method terminates, preventing potential errors later on. This ensures the reliability of the entire architecture and guarantees that MDC is ready to process real-world data streams.
As a result, the initialization method produces a fully configured Multi-Density Changer, in which all components are set up, interconnected, and ready for a forward pass.
The feedForward method implements the main data processing path in the Multi-Density Changer module. Its task is to transform the stream of events being analyzed into a structured, multiscale representation through a sequence of steps. Each operation here has a distinct functional role, ensuring a balance between local micro-impulses and global trends.
bool CNeuronSpikeMDC::feedForward(CNeuronBaseOCL *NeuronOCL) { CNeuronBaseOCL* prev = NeuronOCL; CNeuronBaseOCL* curr = NULL; for(int i = 0; i < cSCMs.Total(); i++) { curr = cSCMs[i]; if(!curr || !curr.FeedForward(prev)) return false; prev = curr; }
The process begins with the cSCMs channel scaling blocks. Each SCM receives the features to be analyzed and performs adaptive scaling on them. Some channels are amplified to draw attention to key events, while others are slightly attenuated to reduce the impact of noise. For a trader, this is similar to filtering market signals: it is important not just to see everything, but to identify the truly significant changes in price and volume.
In the next step, the data is fed into the first feature extraction block, cFeatExtracts. Here, the feature space expands while the sequence length decreases in parallel.
if(!cFeatExtracts[0] || !cFeatExtracts[0].FeedForward(NeuronOCL)) return false; if(!cFeatExtracts[1] || !cFeatExtracts[1].FeedForward(cFeatExtracts[0])) return false;
Expanding the feature space captures as much detail as possible about micro-impulses, while shortening the sequence focuses attention on the most significant events. This operation performs an initial adjustment of feature density and prepares the features for precise processing by the spiking FAM modules.
After initial feature extraction, the data passes through the Feature Alignment Module (FAM). The spiking FAM aligns features across different scales by combining local impulses and global trends.
if(!cFAMs[1] || !cFAMs[1].FeedForward(cFeatExtracts[1], cSCMs[0].getOutput())) return false;
Each FAM block receives two streams: extracted features and scaled SCM channels. This allows local events to be synchronized with the overall market structure so that no critical signal is missed.
if(!cFeatExtracts[2] || !cFeatExtracts[2].FeedForward(cFAMs[1])) return false; if(!cFAMs[0] || !cFAMs[0].FeedForward(cFeatExtracts[2], cSCMs[1].getOutput())) return false;
The data is then fed into the Adaptive Feature Fusion (AFF) module, where features from different levels are carefully combined. Several important operations occur simultaneously here: information from different scales is adaptively summed, significant signals are amplified, and noise and minor fluctuations are suppressed. For a trader, this means that the model provides a clear and coherent picture of the market, where local micro-impulses, sharp changes in volume, and global trends are integrated into a single representation.
//--- AAFF CNeuronSpikeConvBlock* conv = cAFFs[1]; if(!conv) return false; uint units = conv.GetUnits() * conv.GetVariables(); uint window1 = cFeatExtracts[0].Neurons() / units; uint window2 = cFAMs[1].Neurons() / units; uint window3 = cFAMs[0].Neurons() / units; prev = cAFFs[0]; if(!prev || !Concat(cFeatExtracts[0].getOutput(), cFAMs[1].getOutput(), cFAMs[0].getOutput(), prev.getOutput(), window1, window2, window3, units)) return false; for(int i = 1; i < cAFFs.Total(); i += 2) { conv = cAFFs[i]; curr = cAFFs[i + 1]; if(!conv || !conv.FeedForward(prev)) return false; if(!curr || !curr.FeedForward(conv)) return false; }
After processing in AFF, the data is sent to the cProjects and cProjectsOut projection layers, where the features are converted into a format suitable for the model. These layers carefully organize and scale the information, preparing it for final aggregation so that all significant market signals — from local spikes to global trends — are taken into account and correctly integrated into the final representation.
//--- prev = cProjectsOut[0]; curr = cFeatExtracts[3]; if(!prev || !prev.FeedForward(cFAMs[0])) return false; if(!curr || !curr.FeedForward(cFAMs[0])) return false; //--- window1 = curr.Neurons() / units; window2 = cAFFs[4].Neurons() / units; prev = cProjects[0]; if(!prev || !Concat(curr.getOutput(), cAFFs[4].getOutput(), prev.getOutput(), window1, window2, units)) return false; if(!cProjects[1] || !cProjects[1].FeedForward(prev)) return false; if(!cProjectsOut[1] || !cProjectsOut[1].FeedForward(cProjects[1])) return false;
These layers perform several key tasks: additional scaling, dimensional alignment, and concatenation of intermediate outputs, ensuring a consistent and coherent multiscale representation.
if(!cFeatExtracts[4] || !cFeatExtracts[4].FeedForward(cProjects[1])) return false; //--- window1 = cFeatExtracts[4].Neurons() / units; window2 = cAFFs[2].Neurons() / units; prev = cProjects[2]; if(!prev || !Concat(cFeatExtracts[4].getOutput(), cAFFs[2].getOutput(), prev.getOutput(), window1, window2, units)) return false; if(!cProjects[3] || !cProjects[3].FeedForward(prev)) return false; if(!cFeatExtracts[5] || !cFeatExtracts[5].FeedForward(cProjects[3])) return false;
In the final stage, all intermediate outputs are carefully combined in cConcatOut and undergo normalization implemented using the parent class's functionality. This ensures consistency and stability in the final representation, allowing the model to correctly interpret all significant market signals and generate an accurate forecast of price movements.
window1 = cProjectsOut[0].Neurons() / units; window2 = cProjectsOut[1].Neurons() / units; window3 = cFeatExtracts[5].Neurons() / units; //--- if(!Concat(cProjectsOut[0].getOutput(), cProjectsOut[1].getOutput(), cFeatExtracts[5].getOutput(), cConcatOut.getOutput(), window1, window2, window3, units)) return false; window1 = NeuronOCL.Neurons() / units; if(!SumVecMatrix(NeuronOCL.getOutput(), cConcatOut.getOutput(), cConcatOut.getOutput(), window1, units, 0, 0, 0, 1)) return false; if(!CNeuronBatchNormOCL::feedForward(cConcatOut.AsObject())) return false; //--- return true; }
Ultimately, the feedForward method transforms the stream of market events into a structured, multiscale representation that is adapted to the current event density in the market. Every signal — whether it is a sharp price spike, a sudden change in volume, or a gradual trend — is given the appropriate weight and significance, allowing the model to identify precisely the data points that actually influence market dynamics.
Thanks to the sequential operation of the SCM, FAM, FeatExtracts, and AFF modules, along with the projection layers, the system does more than simply record events; it creates a comprehensive picture of the market, revealing both short-term spikes in activity and long-term trends. This approach improves the accuracy of forecasts, reduces the risk of false signals, and allows the strategy to respond quickly to any market changes. As a result, MDC becomes a tool that helps traders view the market holistically, evaluate current signals, and make more confident and informed trading decisions.
We have put in a lot of work and deserve a little break. Let's give ourselves a break and let the information settle in our minds. And in the next article, we will be able to resume our analysis of the framework with renewed energy, taking the implementation all the way through to full integration and testing, in order to demonstrate its practical value for traders.
Conclusion
In this article, we took a detailed look at the implementation of the EEMFlow framework's key components using MQL5, demonstrating how its architecture enables the efficient processing of a stream of market events. Each element — from channel scaling in SCM and local feature alignment in FAM, to adaptive feature fusion in AFF and final aggregation in the projection layers — contributes to the creation of a structured, multiscale representation of the market.
The framework's main advantage is that it adapts to changing market event density, identifies significant signals, and filters out noise, allowing the strategy to detect both instantaneous micro-impulses and broader trends. This ensures the accuracy of forecasts, the reliability of trading decisions, and the flexibility to respond to market dynamics.
Thus, EEMFlow creates a picture of the market ready for use in forecasting, providing traders with a tool for gaining a comprehensive understanding of the market environment and improving the effectiveness of their strategies. The use of spiking modules and multiscale processing enables the model to operate at a level close to that of human analysis, but with a speed and accuracy unattainable by traditional methods.
Links
Software used in this article
| # | Name | Type | Description |
|---|---|---|---|
| 1 | Study.mq5 | Expert Advisor | Expert Advisor for offline model training |
| 2 | StudyOnline.mq5 | Expert Advisor | Expert Advisor for online model training |
| 3 | Test.mq5 | Expert Advisor | Model testing Expert Advisor |
| 4 | Trajectory.mqh | Class Library | Structure describing the system state and model architectures |
| 5 | NeuroNet.mqh | Class Library | Class library for building a neural network |
| 6 | NeuroNet.cl | Library | Code library for an OpenCL program |
Translated from Russian by MetaQuotes Ltd.
Original article: https://www.mql5.com/ru/articles/20606
Warning: All rights to these materials are reserved by MetaQuotes Ltd. Copying or reprinting of these materials in whole or in part is prohibited.
This article was written by a user of the site and reflects their personal views. MetaQuotes Ltd is not responsible for the accuracy of the information presented, nor for any consequences resulting from the use of the solutions, strategies or recommendations described.