This repository is an article-derived reference project based on the original MQL5 article. It does not claim to reproduce the full original source code unless files are explicitly attached.
This repository is derived from the MQL5 article *Working with ONNX Models in MQL5 (Part 3): Drawing the Neurons and the Weights Between Them)*. The article extends an ONNX model viewer for MetaTrader 5 by moving from layer-level graph visualization to neuron-level rendering of dense layers and their weight matrices.
The main focus is on interpreting stored ONNX weight tensors as connection maps between neuron rows, handling matrix orientation correctly, drawing weighted links with sign- and magnitude-based styling, and allowing the user to switch between graph view and neuron view. As an article-derived project, this repository serves as a reference for studying the described architecture and, where attached files are available, reusing the provided implementation.
## Original Article
- **Article ID:** 24337
- **Title:** Working with ONNX Models in MQL5 (Part 3): Drawing the Neurons and the Weights Between Them
- If a dense layer obtains weights dynamically rather than from a stored tensor, the article's logic declines neuron rendering.
- Models composed of operators such as convolutions, recurrent structures, or attention are also not forced into an incorrect dense-connection visualization.
8.**Compute rank/depth of each row**
- The arrangement is refined by repeatedly pushing each target row one level deeper than the row feeding it.
- This produces a depth-based layout similar in spirit to the graph layout from the previous article.
9.**Measure and place rows**
- Each row width is calculated from its neuron count and spacing settings.
- Rows sharing the same rank are arranged side by side.
- The widest rank is used as the centering reference so the full arrangement stays visually balanced.
10.**Draw weighted connections**
- For each pair of source and target neurons, the corresponding weight is fetched from the tensor.
- The indexing rule depends on whether the matrix is stored transposed.
- Line color reflects sign:
- positive weights use one color,
- negative weights use another.
- Line opacity is scaled relative to the largest absolute weight in the tensor.
11.**Apply practical visualization limits**
- The article notes that tensors are capped when read, with the strongest structure preserved first.
- This means the visualization may show a reduced but meaningful subset of connections for very large matrices rather than every single weight.
12.**Draw neuron rows and labels**
- Each neuron is rendered as a circle.
- Labels are centered above their own row and include the operation label and neuron count.
13.**Provide explicit failure messages**
- If the neuron arrangement cannot be built, the panel displays a reason instead of leaving the canvas blank.
14.**Support graph/neuron view switching**
- A footer control toggles between the existing graph view and the new neuron view.
- Sizing, fitting, scrolling, hover text, and tooltips all depend on the active view.
- If neuron view is unavailable, the control remains dimmed and explains why.
## Mentioned or Attached Files
### Explicitly attached files
The processed article input explicitly lists these attachments:
1.**make_model.py** — Python script
Builds the sample classification network and saves it as `model.onnx` under `MQL5\Files\ONNX Model Viewer Part 3\`
2.**OMV Protobuf.mqh** — Include file
Defines protobuf wire-type constants and byte-decoding logic for ONNX parsing
3.**OMV Model.mqh** — Include file
Defines node, tensor, and port structures and implements model parsing logic
4.**OMV Canvas.mqh** — Include file
Provides the drawing surface and rendering helpers
5.**OMV Panel.mqh** — Include file
Arranges graph and neuron views, draws both, and handles mouse/UI interaction
6.**ONNX Model Viewer Part 3.mq5** — Expert Advisor
Main program entry point that initializes the panel and forwards chart events
7.**MQL5.zip** — Archive
Ready-to-extract archive containing the MQL5 folder structure and project files
### ZIP attachment
- An attached ZIP archive is available: https://www.mql5.com/en/articles/download/24337_270086.zip?s=d0028f3bb4f47dfde7f5dfc917902de7c95a5fd0d6ed782b6f7af0bed76d2f6d&t=1791568242
### Files mentioned in text
-`model.onnx` is mentioned as the generated ONNX model file produced by the Python script.
## Statistics
- **Word count:** Not available
- **Reading time:** Not available
- **Image count:** Not available
- **Code block count:** Not available
- **File count:** Not available
## Tags
- mql5
- metatrader-5
- expert-advisors
- statistics
- onnx
- neural-networks
- model-visualization
- difficulty-advanced
## Difficulty
**Advanced**
Reason: the article combines ONNX model interpretation, tensor-orientation handling, custom layout construction, chart-based rendering, UI interaction, and careful support/rejection logic for multiple operator types.
## Limitations
- This repository is based on an article and should be treated as a reference or reconstruction unless the attached files are actually included here.
- Full functionality depends on the source files and archives actually attached or provided by the article author.
- The neuron view described in the article is intentionally limited to cases that can be represented honestly as dense neuron-to-neuron connections.
- The article explicitly notes that convolutions, recurrent layers, attention layers, and dynamically supplied dense weights are not suitable for this visualization approach.
- The visualization may not render every stored weight in very large tensors, because the article describes capped tensor retention and prioritization of stronger connections.
- The project should not be assumed production-ready unless validated independently in your own MetaTrader 5 environment.
## Reference
- Original article: https://www.mql5.com/en/articles/24337