Upload 11 files
Browse files- .gitignore +32 -0
- LICENSE +21 -0
- ML-3m-trader_savelog.txt +70 -0
- README.md +158 -0
- STACKS.md +132 -0
- STRUCTURE.md +0 -0
- TECHSTACK.md +70 -0
- feature_process.png +0 -0
- metrics.png +0 -0
- requirements.txt +6 -0
- sractch.md +230 -0
.gitignore
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# __pycache__/
|
| 2 |
+
*.pyc
|
| 3 |
+
*.pyo
|
| 4 |
+
__pycache__/
|
| 5 |
+
|
| 6 |
+
# Data and model artifacts
|
| 7 |
+
data/
|
| 8 |
+
models/
|
| 9 |
+
results/
|
| 10 |
+
|
| 11 |
+
# Virtual environment
|
| 12 |
+
.venv/
|
| 13 |
+
venv/
|
| 14 |
+
env/
|
| 15 |
+
|
| 16 |
+
# IDE
|
| 17 |
+
.vscode/
|
| 18 |
+
.idea/
|
| 19 |
+
*.swp
|
| 20 |
+
*.swo
|
| 21 |
+
|
| 22 |
+
# OS
|
| 23 |
+
Thumbs.db
|
| 24 |
+
.DS_Store
|
| 25 |
+
desktop.ini
|
| 26 |
+
|
| 27 |
+
# Logs
|
| 28 |
+
*.log
|
| 29 |
+
*_savelog.txt
|
| 30 |
+
|
| 31 |
+
# Jupyter
|
| 32 |
+
.ipynb_checkpoints/
|
LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2026 Rembrant Oyangoren Albeos
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
ML-3m-trader_savelog.txt
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
REPOSITORY TECH-STACK AUDIT: ML-3m-trader
|
| 2 |
+
Path: c:\Users\User\Desktop\debugrem\ML-3m-trader
|
| 3 |
+
|
| 4 |
+
FILE TYPE COUNT LINES SYNTAX SIZE (KB)
|
| 5 |
+
------------------------------------------------------------------------------
|
| 6 |
+
(no extension) 878 6854 775 239.2
|
| 7 |
+
PNG Image (.png) 2 817 141 103.0
|
| 8 |
+
Plain Text (.txt) 50 8577 129 467.0
|
| 9 |
+
Markdown (.md) 7 5610 37 369.2
|
| 10 |
+
Python (.py) 17 2788 915 90.5
|
| 11 |
+
Lock File (.lock) 4 5903 2780 145.7
|
| 12 |
+
TOML (.toml) 2 40 35 0.8
|
| 13 |
+
CSV (.csv) 5 31000 0 7,164.4
|
| 14 |
+
Binary File (.bin) 7 92337 19040 8,852.6
|
| 15 |
+
Rust (.rs) 22 3018 676 101.5
|
| 16 |
+
JSON (.json) 357 371 20 238.5
|
| 17 |
+
TAG (.tag) 1 4 0 0.2
|
| 18 |
+
TIMESTAMP (.timestamp) 356 356 0 16.7
|
| 19 |
+
Windows Executable (.exe) 92 182892 10388 40,423.0
|
| 20 |
+
D (.d) 311 5923 19 1,550.1
|
| 21 |
+
PDB (.pdb) 106 755976 74785 184,504.0
|
| 22 |
+
DLL Library (.dll) 16 213628 4299 28,980.5
|
| 23 |
+
EXP (.exp) 14 33 1 17.5
|
| 24 |
+
Library (.lib) 14 180 1 33.0
|
| 25 |
+
RMETA (.rmeta) 250 1241287 38355 249,115.4
|
| 26 |
+
RLIB (.rlib) 158 770933 21359 256,066.0
|
| 27 |
+
CMake (.cmake) 57 8261 111 269.8
|
| 28 |
+
IN (.in) 13 375 169 11.2
|
| 29 |
+
C++ Header (.hpp) 350 54615 9065 1,746.7
|
| 30 |
+
APACHE (.apache) 1 203 1 11.1
|
| 31 |
+
BSD (.bsd) 1 27 0 1.5
|
| 32 |
+
GPL (.gpl) 1 675 1 34.3
|
| 33 |
+
LGPL (.lgpl) 1 503 6 25.9
|
| 34 |
+
MINPACK (.minpack) 1 52 0 2.1
|
| 35 |
+
MPL2 (.mpl2) 1 374 0 16.3
|
| 36 |
+
README (.readme) 1 19 0 0.8
|
| 37 |
+
C++ (.cpp) 254 59704 11785 2,152.7
|
| 38 |
+
CXXLIST (.cxxlist) 1 29 8 1.4
|
| 39 |
+
C Header (.h) 545 236942 54202 9,192.8
|
| 40 |
+
Shell Script (.sh) 12 756 191 18.6
|
| 41 |
+
C++ Header (.hh) 58 7563 972 199.7
|
| 42 |
+
C++ (.cxx) 3 514 95 13.5
|
| 43 |
+
MAIN (.main) 1 13 9 0.1
|
| 44 |
+
HTML (.html) 5 153 20 19.5
|
| 45 |
+
JavaScript (.js) 2 3 8965 383.8
|
| 46 |
+
Document Type Definition (.dtd) 1 31 0 1.8
|
| 47 |
+
C++ (.cc) 7 1337 149 44.9
|
| 48 |
+
CU (.cu) 15 4980 742 179.3
|
| 49 |
+
C (.c) 20 6619 2257 177.4
|
| 50 |
+
Fortran (.f) 51 37932 7492 1,295.2
|
| 51 |
+
DAT (.dat) 8 232 0 9.6
|
| 52 |
+
DOX (.dox) 2 42 3 1.2
|
| 53 |
+
YAML (.yml) 3 192 11 3.8
|
| 54 |
+
BSL (.bsl) 1 26 0 1.3
|
| 55 |
+
reStructuredText (.rst) 4 4188 130 159.8
|
| 56 |
+
MK (.mk) 1 16 1 0.3
|
| 57 |
+
XML (.xml) 1 2 1 0.0
|
| 58 |
+
Gradle (.gradle) 1 108 5 3.1
|
| 59 |
+
SUBLIME-SYNTAX (.sublime-syntax) 1 2062 15 70.6
|
| 60 |
+
Config (.conf) 1 3 1 0.0
|
| 61 |
+
HU (.hu) 1 162 37 5.3
|
| 62 |
+
Common Lisp (.cl) 3 2302 553 107.0
|
| 63 |
+
I (.i) 4 604 50 22.2
|
| 64 |
+
Visual Studio Solution (.sln) 1 34 15 1.6
|
| 65 |
+
VCXPROJ (.vcxproj) 1 344 153 18.2
|
| 66 |
+
FILTERS (.filters) 1 330 111 12.4
|
| 67 |
+
MQL5 Source (.mq5) 1 451 119 18.1
|
| 68 |
+
MQL Header (.mqh) 1 145 22 3.9
|
| 69 |
+
------------------------------------------------------------------------------
|
| 70 |
+
TOTAL 4107 3761450 271222 794,717.6
|
README.md
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
library_name: ml-trader
|
| 4 |
+
tags:
|
| 5 |
+
- trading
|
| 6 |
+
- machine-learning
|
| 7 |
+
- xauusd
|
| 8 |
+
- gold
|
| 9 |
+
- mt5
|
| 10 |
+
- metatrader5
|
| 11 |
+
- python
|
| 12 |
+
- rust
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# ML-3m-trader: XAUUSDc 3-Minute Timeframe ML Trading System
|
| 16 |
+
|
| 17 |
+
An end-to-end proprietary machine learning pipeline for trading XAUUSDc (Gold) on the 3-minute timeframe. This system utilizes a high-performance architecture bridging Python for data processing and model orchestration with Rust for high-frequency execution components.
|
| 18 |
+
|
| 19 |
+
[](https://opensource.org/licenses/MIT)
|
| 20 |
+
[](https://www.python.org/)
|
| 21 |
+
[](https://www.rust-lang.org/)
|
| 22 |
+
[](#techstack)
|
| 23 |
+
[](https://huggingface.co/algorembrant)
|
| 24 |
+
|
| 25 |
+
## Project Overview
|
| 26 |
+
|
| 27 |
+
The ML-3m-trader repository provides a robust framework for automated trading, featuring a hybrid implementation designed for speed and reliability. The core logic involves sophisticated feature engineering and a classification-based approach to market decision-making. Read paper at [SSRN](https://ssrn.com/abstract=6143486) for brigde system framework.
|
| 28 |
+
|
| 29 |
+
> [!NOTE]
|
| 30 |
+
> **Confidentiality Notice**: The specific machine learning algorithms and proprietary trading strategies utilized in this system are currently private. The documentation focuses on infrastructure and architectural workflows.
|
| 31 |
+
|
| 32 |
+
## Key Features
|
| 33 |
+
|
| 34 |
+
- **Multi-Language Architecture**: Seamless integration between Python processing and Rust execution.
|
| 35 |
+
- **Data Acquisition**: Automated 3-minute OHLCV data fetching.
|
| 36 |
+
- **Proprietary Labeling**: Advanced market state labeling engine with built-in risk-reward and spread filtering.
|
| 37 |
+
- **Vectorized Backtesting**: High-speed, realistic execution modeling accounting for slippage and spread.
|
| 38 |
+
- **Comprehensive Metrics**: Detailed performance analysis including Sharpe, Sortino, and Profit Factor.
|
| 39 |
+
|
| 40 |
+
## Output Preview
|
| 41 |
+
|
| 42 |
+
The following visualizations illustrate the system's internal processing and performance evaluation.
|
| 43 |
+
|
| 44 |
+
### Feature Processing Workflow
|
| 45 |
+

|
| 46 |
+
The diagram above details the data transformation pipeline from raw market indicators to model-ready features.
|
| 47 |
+
|
| 48 |
+
### Performance Metrics
|
| 49 |
+

|
| 50 |
+
The image above showcases the standardized backtesting report generated after a full simulation run.
|
| 51 |
+
|
| 52 |
+
## System Architecture
|
| 53 |
+
|
| 54 |
+
```mermaid
|
| 55 |
+
graph TD
|
| 56 |
+
A[MetaTrader 5] -->|OHLCV Data| B(Data Fetcher)
|
| 57 |
+
B --> C(Feature Engineering)
|
| 58 |
+
C --> D(Labeling Engine)
|
| 59 |
+
D --> E(ML Pipeline)
|
| 60 |
+
E --> F{Backtesting}
|
| 61 |
+
F -->|Performance| G(Metrics Report)
|
| 62 |
+
F -->|Execution| H[Live Trading Interface]
|
| 63 |
+
|
| 64 |
+
subgraph "Hybrid Processing"
|
| 65 |
+
C
|
| 66 |
+
D
|
| 67 |
+
E
|
| 68 |
+
end
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
## Project Structure
|
| 72 |
+
Detailed overview of all project components:
|
| 73 |
+
|
| 74 |
+
```text
|
| 75 |
+
ML-3m-trader/
|
| 76 |
+
βββ python_version/
|
| 77 |
+
β βββ main.py
|
| 78 |
+
β βββ config.py
|
| 79 |
+
β βββ data_fetcher.py
|
| 80 |
+
β βββ diag_mt5.py
|
| 81 |
+
β βββ features.py
|
| 82 |
+
β βββ labeler.py
|
| 83 |
+
β βββ model.py
|
| 84 |
+
β βββ backtester.py
|
| 85 |
+
β βββ metrics.py
|
| 86 |
+
β βββ README.md
|
| 87 |
+
βββ rust_ml_trader/
|
| 88 |
+
β βββ src/
|
| 89 |
+
β β βββ main.rs
|
| 90 |
+
β β βββ backtester.rs
|
| 91 |
+
β β βββ config.rs
|
| 92 |
+
β β βββ data_fetcher.rs
|
| 93 |
+
β β βββ features.rs
|
| 94 |
+
β β βββ labeler.rs
|
| 95 |
+
β β βββ metrics.rs
|
| 96 |
+
β β βββ model.rs
|
| 97 |
+
β β βββ types.rs
|
| 98 |
+
β βββ .gitignore
|
| 99 |
+
β βββ Cargo.toml
|
| 100 |
+
β βββ GUIDE.md
|
| 101 |
+
β βββ LICENSE
|
| 102 |
+
β βββ README.md
|
| 103 |
+
βββ SUM3API (local)/
|
| 104 |
+
β βββ MQL5/
|
| 105 |
+
β β βββ Experts/
|
| 106 |
+
β β β βββ ZmqPublisher.mq5
|
| 107 |
+
β β βββ Include/
|
| 108 |
+
β β βββ Libraries/
|
| 109 |
+
β βββ Rustmt5-chart/
|
| 110 |
+
βββ feature_process.png
|
| 111 |
+
βββ LICENSE
|
| 112 |
+
βββ metrics.png
|
| 113 |
+
βββ requirements.txt
|
| 114 |
+
βββ STACKS.md
|
| 115 |
+
βββ sractch.md
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
## Usage
|
| 119 |
+
|
| 120 |
+
For detailed technical documentation, please refer to [STACKS.md](STACKS.md).
|
| 121 |
+
|
| 122 |
+
### Quick Start (Python)
|
| 123 |
+
|
| 124 |
+
1. Install dependencies:
|
| 125 |
+
```bash
|
| 126 |
+
pip install -r requirements.txt
|
| 127 |
+
```
|
| 128 |
+
2. Run the full pipeline:
|
| 129 |
+
```bash
|
| 130 |
+
python python_version/main.py run
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
### Quick Start (Rust)
|
| 134 |
+
|
| 135 |
+
1. Build the project:
|
| 136 |
+
```bash
|
| 137 |
+
cd rust_ml_trader
|
| 138 |
+
cargo build --release
|
| 139 |
+
```
|
| 140 |
+
2. Execute backtest:
|
| 141 |
+
```bash
|
| 142 |
+
cargo run --release
|
| 143 |
+
```
|
| 144 |
+
|
| 145 |
+
## Citation
|
| 146 |
+
|
| 147 |
+
If you use this repository in your research or project, please cite it as follows:
|
| 148 |
+
|
| 149 |
+
```bibtex
|
| 150 |
+
@misc{albeos2026ml3mtrader,
|
| 151 |
+
author = {Rembrant Oyangoren Albeos},
|
| 152 |
+
title = {ML-3m-trader: XAUUSDc 3-Minute Timeframe ML Trading System},
|
| 153 |
+
year = {2026},
|
| 154 |
+
publisher = {Hugging Face},
|
| 155 |
+
journal = {Hugging Face Repository},
|
| 156 |
+
howpublished = {\url{https://huggingface.co/algorembrant/ML-3m-trader}}
|
| 157 |
+
}
|
| 158 |
+
```
|
STACKS.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# STACKS.md
|
| 2 |
+
|
| 3 |
+
## Description
|
| 4 |
+
ML-3m-trader is a high-performance, multi-language trading framework designed for the XAUUSDc 3rd minute timeframe. It bridges the data processing and machine learning capabilities of Python with the safety and speed of Rust for execution components. The system integrates directly with MetaTrader 5 for real-time market data and historical auditing.
|
| 5 |
+
|
| 6 |
+
## System Overview
|
| 7 |
+
```mermaid
|
| 8 |
+
graph TD
|
| 9 |
+
A[MetaTrader 5] -->|OHLCV Data| B(Data Fetcher)
|
| 10 |
+
B --> C(Feature Engineering)
|
| 11 |
+
C --> D(Labeling Engine)
|
| 12 |
+
D --> E(ML Pipeline)
|
| 13 |
+
E --> F{Backtesting}
|
| 14 |
+
F -->|Performance| G(Metrics Report)
|
| 15 |
+
F -->|Execution| H[Live Trading Interface]
|
| 16 |
+
|
| 17 |
+
subgraph "Hybrid Processing"
|
| 18 |
+
C
|
| 19 |
+
D
|
| 20 |
+
E
|
| 21 |
+
end
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
## Project Structure
|
| 25 |
+
```text
|
| 26 |
+
ML-3m-trader/
|
| 27 |
+
βββ python_version/
|
| 28 |
+
β βββ backtester.py
|
| 29 |
+
β βββ config.py
|
| 30 |
+
β βββ data_fetcher.py
|
| 31 |
+
β βββ diag_mt5.py
|
| 32 |
+
β βββ features.py
|
| 33 |
+
β βββ GUIDE.md
|
| 34 |
+
β βββ labeler.py
|
| 35 |
+
β βββ main.py
|
| 36 |
+
β βββ metrics.py
|
| 37 |
+
β βββ model.py
|
| 38 |
+
β βββ README.md
|
| 39 |
+
βββ rust_ml_trader/
|
| 40 |
+
β βββ data/
|
| 41 |
+
β β βββ raw_xauusdc_m3.csv
|
| 42 |
+
β βββ models/
|
| 43 |
+
β β βββ rf_model.bin
|
| 44 |
+
β βββ results/
|
| 45 |
+
β β βββ report.txt
|
| 46 |
+
β β βββ trades.csv
|
| 47 |
+
β βββ src/
|
| 48 |
+
β β βββ backtester.rs
|
| 49 |
+
β β βββ config.rs
|
| 50 |
+
β β βββ data_fetcher.rs
|
| 51 |
+
β β βββ features.rs
|
| 52 |
+
β β βββ labeler.rs
|
| 53 |
+
β β βββ main.rs
|
| 54 |
+
β β βββ metrics.rs
|
| 55 |
+
β β βββ model.rs
|
| 56 |
+
β β βββ types.rs
|
| 57 |
+
β βββ .gitignore
|
| 58 |
+
β βββ Cargo.lock
|
| 59 |
+
β βββ Cargo.toml
|
| 60 |
+
β βββ GUIDE.md
|
| 61 |
+
β βββ LICENSE
|
| 62 |
+
β βββ README.md
|
| 63 |
+
βββ SUM3API (local)/
|
| 64 |
+
β βββ MQL5/
|
| 65 |
+
β β βββ Experts/
|
| 66 |
+
β β β βββ ZmqPublisher.mq5
|
| 67 |
+
β β βββ Include/
|
| 68 |
+
β β β βββ Zmq/
|
| 69 |
+
β β β βββ Zmq.mqh
|
| 70 |
+
β β βββ Libraries/
|
| 71 |
+
β β βββ libsodium.dll
|
| 72 |
+
β β βββ libzmq.dll
|
| 73 |
+
β βββ Rustmt5-chart/
|
| 74 |
+
β β βββ src/
|
| 75 |
+
β β β βββ main.rs
|
| 76 |
+
β β βββ Cargo.lock
|
| 77 |
+
β β βββ Cargo.toml
|
| 78 |
+
β βββ .gitignore
|
| 79 |
+
βββ .gitignore
|
| 80 |
+
βββ feature_process.png
|
| 81 |
+
βββ LICENSE
|
| 82 |
+
βββ metrics.png
|
| 83 |
+
βββ README.md
|
| 84 |
+
βββ requirements.txt
|
| 85 |
+
βββ sractch.md
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
## Techstack
|
| 89 |
+
Audit of **ML-3m-trader** project files:
|
| 90 |
+
|
| 91 |
+
| File Type | Count | Lines | Syntax Hits | Size (KB) |
|
| 92 |
+
| :--- | :--- | :--- | :--- | :--- |
|
| 93 |
+
| Rust (.rs) | 10 | 2283 | 570 | 76.1 |
|
| 94 |
+
| Python (.py) | 9 | 1459 | 438 | 46.9 |
|
| 95 |
+
| Markdown (.md) | 7 | 5610 | 37 | 369.2 |
|
| 96 |
+
| (no extension) | 5 | 95 | 0 | 2.5 |
|
| 97 |
+
| CSV (.csv) | 5 | 31000 | 0 | 7,164.4 |
|
| 98 |
+
| Plain Text (.txt) | 3 | 4872 | 0 | 341.7 |
|
| 99 |
+
| DLL Library (.dll) | 2 | 3351 | 267 | 736.0 |
|
| 100 |
+
| Lock File (.lock) | 2 | 5901 | 2780 | 145.7 |
|
| 101 |
+
| PNG Image (.png) | 2 | 817 | 141 | 103.0 |
|
| 102 |
+
| TOML (.toml) | 2 | 40 | 35 | 0.8 |
|
| 103 |
+
| Binary File (.bin) | 1 | 1844 | 132 | 453.8 |
|
| 104 |
+
| MQL Header (.mqh) | 1 | 145 | 22 | 3.9 |
|
| 105 |
+
| MQL5 Source (.mq5) | 1 | 451 | 119 | 18.1 |
|
| 106 |
+
| **Total** | **50** | **57868** | **4541** | **9,462.0** |
|
| 107 |
+
|
| 108 |
+
## Dependencies
|
| 109 |
+
|
| 110 |
+
### Python Dependencies
|
| 111 |
+
- **MetaTrader5**: Terminal communication and data acquisition.
|
| 112 |
+
- **lightgbm**: Gradient boosting framework for machine learning.
|
| 113 |
+
- **pandas**: Data manipulation and analysis.
|
| 114 |
+
- **numpy**: Scientific computing and vectorized operations.
|
| 115 |
+
- **scikit-learn**: Machine learning utilities and preprocessing.
|
| 116 |
+
- **joblib**: Model persistence and parallel processing.
|
| 117 |
+
|
| 118 |
+
### Rust Dependencies
|
| 119 |
+
- **zeromq**: Asynchronous messaging for MQL5 integration.
|
| 120 |
+
- **tokio**: Asynchronous runtime for high-performance networking.
|
| 121 |
+
- **chrono**: Date and time handling.
|
| 122 |
+
- **serde / serde_json**: Serialization and deserialization.
|
| 123 |
+
- **csv**: High-performance CSV parsing and writing.
|
| 124 |
+
- **clap**: Command-line argument parsing.
|
| 125 |
+
- **bincode**: Binary serialization for model weights.
|
| 126 |
+
- **ndarray**: N-dimensional arrays for vectorized math.
|
| 127 |
+
- **rand**: Random number generation for execution modeling.
|
| 128 |
+
|
| 129 |
+
## Applications
|
| 130 |
+
- High-frequency algorithmic trading of Gold (XAUUSDc).
|
| 131 |
+
- Quantitative backtesting and performance auditing.
|
| 132 |
+
- Machine learning model development and deployment in financial markets.
|
STRUCTURE.md
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
TECHSTACK.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## Techstack
|
| 2 |
+
|
| 3 |
+
Audit of **ML-3m-trader** project files (excluding environment and cache):
|
| 4 |
+
|
| 5 |
+
| File Type | Count | Lines | Syntax Hits | Size (KB) |
|
| 6 |
+
| :--- | :--- | :--- | :--- | :--- |
|
| 7 |
+
| (no extension) | 878 | 6854 | 775 | 239.2 |
|
| 8 |
+
| C Header (.h) | 545 | 236942 | 54202 | 9,192.8 |
|
| 9 |
+
| JSON (.json) | 357 | 371 | 20 | 238.5 |
|
| 10 |
+
| TIMESTAMP (.timestamp) | 356 | 356 | 0 | 16.7 |
|
| 11 |
+
| C++ Header (.hpp) | 350 | 54615 | 9065 | 1,746.7 |
|
| 12 |
+
| D (.d) | 311 | 5923 | 19 | 1,550.1 |
|
| 13 |
+
| C++ (.cpp) | 254 | 59704 | 11785 | 2,152.7 |
|
| 14 |
+
| RMETA (.rmeta) | 250 | 1241287 | 38355 | 249,115.4 |
|
| 15 |
+
| RLIB (.rlib) | 158 | 770933 | 21359 | 256,066.0 |
|
| 16 |
+
| PDB (.pdb) | 106 | 755976 | 74785 | 184,504.0 |
|
| 17 |
+
| Windows Executable (.exe) | 92 | 182892 | 10388 | 40,423.0 |
|
| 18 |
+
| C++ Header (.hh) | 58 | 7563 | 972 | 199.7 |
|
| 19 |
+
| CMake (.cmake) | 57 | 8261 | 111 | 269.8 |
|
| 20 |
+
| Fortran (.f) | 51 | 37932 | 7492 | 1,295.2 |
|
| 21 |
+
| Plain Text (.txt) | 50 | 8577 | 129 | 467.0 |
|
| 22 |
+
| Rust (.rs) | 22 | 3018 | 676 | 101.5 |
|
| 23 |
+
| C (.c) | 20 | 6619 | 2257 | 177.4 |
|
| 24 |
+
| Python (.py) | 17 | 2788 | 915 | 90.5 |
|
| 25 |
+
| DLL Library (.dll) | 16 | 213628 | 4299 | 28,980.5 |
|
| 26 |
+
| CU (.cu) | 15 | 4980 | 742 | 179.3 |
|
| 27 |
+
| EXP (.exp) | 14 | 33 | 1 | 17.5 |
|
| 28 |
+
| Library (.lib) | 14 | 180 | 1 | 33.0 |
|
| 29 |
+
| IN (.in) | 13 | 375 | 169 | 11.2 |
|
| 30 |
+
| Shell Script (.sh) | 12 | 756 | 191 | 18.6 |
|
| 31 |
+
| DAT (.dat) | 8 | 232 | 0 | 9.6 |
|
| 32 |
+
| Binary File (.bin) | 7 | 92337 | 19040 | 8,852.6 |
|
| 33 |
+
| C++ (.cc) | 7 | 1337 | 149 | 44.9 |
|
| 34 |
+
| Markdown (.md) | 7 | 5610 | 37 | 369.2 |
|
| 35 |
+
| CSV (.csv) | 5 | 31000 | 0 | 7,164.4 |
|
| 36 |
+
| HTML (.html) | 5 | 153 | 20 | 19.5 |
|
| 37 |
+
| I (.i) | 4 | 604 | 50 | 22.2 |
|
| 38 |
+
| Lock File (.lock) | 4 | 5903 | 2780 | 145.7 |
|
| 39 |
+
| reStructuredText (.rst) | 4 | 4188 | 130 | 159.8 |
|
| 40 |
+
| C++ (.cxx) | 3 | 514 | 95 | 13.5 |
|
| 41 |
+
| Common Lisp (.cl) | 3 | 2302 | 553 | 107.0 |
|
| 42 |
+
| YAML (.yml) | 3 | 192 | 11 | 3.8 |
|
| 43 |
+
| DOX (.dox) | 2 | 42 | 3 | 1.2 |
|
| 44 |
+
| JavaScript (.js) | 2 | 3 | 8965 | 383.8 |
|
| 45 |
+
| PNG Image (.png) | 2 | 817 | 141 | 103.0 |
|
| 46 |
+
| TOML (.toml) | 2 | 40 | 35 | 0.8 |
|
| 47 |
+
| APACHE (.apache) | 1 | 203 | 1 | 11.1 |
|
| 48 |
+
| BSD (.bsd) | 1 | 27 | 0 | 1.5 |
|
| 49 |
+
| BSL (.bsl) | 1 | 26 | 0 | 1.3 |
|
| 50 |
+
| Config (.conf) | 1 | 3 | 1 | 0.0 |
|
| 51 |
+
| CXXLIST (.cxxlist) | 1 | 29 | 8 | 1.4 |
|
| 52 |
+
| Document Type Definition (.dtd) | 1 | 31 | 0 | 1.8 |
|
| 53 |
+
| FILTERS (.filters) | 1 | 330 | 111 | 12.4 |
|
| 54 |
+
| GPL (.gpl) | 1 | 675 | 1 | 34.3 |
|
| 55 |
+
| Gradle (.gradle) | 1 | 108 | 5 | 3.1 |
|
| 56 |
+
| HU (.hu) | 1 | 162 | 37 | 5.3 |
|
| 57 |
+
| LGPL (.lgpl) | 1 | 503 | 6 | 25.9 |
|
| 58 |
+
| MAIN (.main) | 1 | 13 | 9 | 0.1 |
|
| 59 |
+
| MINPACK (.minpack) | 1 | 52 | 0 | 2.1 |
|
| 60 |
+
| MK (.mk) | 1 | 16 | 1 | 0.3 |
|
| 61 |
+
| MPL2 (.mpl2) | 1 | 374 | 0 | 16.3 |
|
| 62 |
+
| MQL Header (.mqh) | 1 | 145 | 22 | 3.9 |
|
| 63 |
+
| MQL5 Source (.mq5) | 1 | 451 | 119 | 18.1 |
|
| 64 |
+
| README (.readme) | 1 | 19 | 0 | 0.8 |
|
| 65 |
+
| SUBLIME-SYNTAX (.sublime-syntax) | 1 | 2062 | 15 | 70.6 |
|
| 66 |
+
| TAG (.tag) | 1 | 4 | 0 | 0.2 |
|
| 67 |
+
| VCXPROJ (.vcxproj) | 1 | 344 | 153 | 18.2 |
|
| 68 |
+
| Visual Studio Solution (.sln) | 1 | 34 | 15 | 1.6 |
|
| 69 |
+
| XML (.xml) | 1 | 2 | 1 | 0.0 |
|
| 70 |
+
| **Total** | **4107** | **3761450** | **271222** | **794,717.6** |
|
feature_process.png
ADDED
|
metrics.png
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MetaTrader5>=5.0.45
|
| 2 |
+
lightgbm>=4.0.0
|
| 3 |
+
pandas>=2.0.0
|
| 4 |
+
numpy>=1.24.0
|
| 5 |
+
scikit-learn>=1.3.0
|
| 6 |
+
joblib>=1.3.0
|
sractch.md
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ML-3m-trader: XAUUSDc 3-Minute Timeframe ML Trading System
|
| 2 |
+
|
| 3 |
+
End-to-end machine learning pipeline for trading XAUUSDc (Gold) on the 3-minute timeframe. Uses MetaTrader 5 for data acquisition, LightGBM for classification, and a vectorized backtesting engine with realistic execution modeling.
|
| 4 |
+
|
| 5 |
+
## User Review Required
|
| 6 |
+
|
| 7 |
+
> [!IMPORTANT]
|
| 8 |
+
> **ML Framework Choice: LightGBM** β LightGBM is the best-suited framework for this task because:
|
| 9 |
+
> - Tabular classification (Buy/Sell/Hold/DoNothing) is LightGBM's strongest domain
|
| 10 |
+
> - Extremely fast training, even on CPU (i5-7200U will handle it fine)
|
| 11 |
+
> - Low memory footprint (well within 12 GB RAM)
|
| 12 |
+
> - No GPU required (your MX110 is not needed)
|
| 13 |
+
> - Outperforms deep learning on structured/tabular data in virtually all benchmarks
|
| 14 |
+
>
|
| 15 |
+
> **This will run entirely on your local machine. No Google Colab needed.**
|
| 16 |
+
|
| 17 |
+
> [!WARNING]
|
| 18 |
+
> **MetaTrader 5 Python API** only works on Windows (which you have). MT5 must be open and logged in when running the data fetch script. The `MetaTrader5` pip package handles communication.
|
| 19 |
+
|
| 20 |
+
> [!NOTE]
|
| 21 |
+
> **VIX Feature**: Since the CBOE VIX index is not directly available from MT5, the system will compute a **synthetic VIX proxy** using a rolling standard deviation of returns (realized volatility), which is the standard approach in non-US-equity trading systems. If you want the actual VIX, we would need a separate data source.
|
| 22 |
+
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
## Proposed Changes
|
| 26 |
+
|
| 27 |
+
### Project Structure
|
| 28 |
+
|
| 29 |
+
```
|
| 30 |
+
ML-3m-trader/
|
| 31 |
+
βββ config.py # All configuration constants
|
| 32 |
+
βββ data_fetcher.py # MT5 data acquisition
|
| 33 |
+
βββ features.py # Technical indicator computation
|
| 34 |
+
βββ labeler.py # Trade label generation (Buy/Sell/Hold/DoNothing)
|
| 35 |
+
βββ model.py # LightGBM training, prediction, persistence
|
| 36 |
+
βββ backtester.py # Vectorized backtesting engine
|
| 37 |
+
βββ metrics.py # Performance evaluation
|
| 38 |
+
βββ main.py # CLI entry point
|
| 39 |
+
βββ requirements.txt
|
| 40 |
+
βββ LICENSE
|
| 41 |
+
βββ README.md
|
| 42 |
+
βββ GUIDE.md # Step-by-step usage guide with tables
|
| 43 |
+
βββ .gitignore
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
---
|
| 47 |
+
|
| 48 |
+
### Configuration
|
| 49 |
+
|
| 50 |
+
#### [NEW] [config.py](file:///c:/Users/User/Desktop/debugrem/ML-3m-trader/config.py)
|
| 51 |
+
|
| 52 |
+
Central configuration file containing all tunable parameters:
|
| 53 |
+
- `SYMBOL = "XAUUSDc"`, `TIMEFRAME = mt5.TIMEFRAME_M3`
|
| 54 |
+
- Feature list, lookback periods for SMA (14, 50), VROC (14), ADX (14), Momentum SI (10)
|
| 55 |
+
- Risk/reward ratio = 1.0, default bet percentage logic
|
| 56 |
+
- Slippage range (0β2 units), spread filter (`stoploss_size >= spread * 10`)
|
| 57 |
+
- Train/test split ratio, model hyperparameters
|
| 58 |
+
- Starting equity/balance
|
| 59 |
+
|
| 60 |
+
---
|
| 61 |
+
|
| 62 |
+
### Data Acquisition
|
| 63 |
+
|
| 64 |
+
#### [NEW] [data_fetcher.py](file:///c:/Users/User/Desktop/debugrem/ML-3m-trader/data_fetcher.py)
|
| 65 |
+
|
| 66 |
+
- Connects to MT5 terminal via `MetaTrader5` Python package
|
| 67 |
+
- Fetches 1-year of 3-minute OHLCV bars for XAUUSDc
|
| 68 |
+
- Returns a `pandas.DataFrame` with columns: `time, open, high, low, close, volume, spread`
|
| 69 |
+
- Saves raw data to `data/raw_xauusdc_3m.csv` for reproducibility
|
| 70 |
+
- Handles MT5 connection errors gracefully
|
| 71 |
+
|
| 72 |
+
---
|
| 73 |
+
|
| 74 |
+
### Feature Engineering
|
| 75 |
+
|
| 76 |
+
#### [NEW] [features.py](file:///c:/Users/User/Desktop/debugrem/ML-3m-trader/features.py)
|
| 77 |
+
|
| 78 |
+
Computes all required technical indicators using pure NumPy/Pandas (no TA-Lib dependency):
|
| 79 |
+
|
| 80 |
+
| Feature | Method |
|
| 81 |
+
|---------|--------|
|
| 82 |
+
| SMA | Simple Moving Average (14-period) |
|
| 83 |
+
| Double Moving Average | SMA(14) and SMA(50), plus crossover signal |
|
| 84 |
+
| VROC | Volume Rate of Change (14-period) |
|
| 85 |
+
| Synthetic VIX | Rolling std of log-returns (20-period) as volatility proxy |
|
| 86 |
+
| Momentum Strength Index | Custom momentum oscillator (10-period, 0β100 scale) |
|
| 87 |
+
| ADX | Average Directional Index (14-period) via Wilder's smoothing |
|
| 88 |
+
| Time features | Hour-of-day, minute-of-hour, day-of-week (cyclical encoded) |
|
| 89 |
+
|
| 90 |
+
All computations are vectorized with NumPy for maximum speed. NaN rows from lookback periods are dropped.
|
| 91 |
+
|
| 92 |
+
---
|
| 93 |
+
|
| 94 |
+
### Labeling Engine
|
| 95 |
+
|
| 96 |
+
#### [NEW] [labeler.py](file:///c:/Users/User/Desktop/debugrem/ML-3m-trader/labeler.py)
|
| 97 |
+
|
| 98 |
+
Generates ground-truth labels for supervised learning:
|
| 99 |
+
|
| 100 |
+
1. For each bar, compute a potential **Buy** and **Sell** trade:
|
| 101 |
+
- **Buy**: entry at `close`, SL below recent swing low (ATR-based), TP = entry + (entry - SL) (1:1 RR)
|
| 102 |
+
- **Sell**: entry at `close`, SL above recent swing high (ATR-based), TP = entry - (SL - entry) (1:1 RR)
|
| 103 |
+
2. Walk forward through subsequent bars to determine outcome (TP hit, SL hit, or neither within N bars)
|
| 104 |
+
3. Apply **spread filter**: if `SL_distance < spread * 10`, label = `DO_NOTHING`
|
| 105 |
+
4. Final labels: `BUY_WIN`, `BUY_LOSS`, `SELL_WIN`, `SELL_LOSS`, `HOLD`, `DO_NOTHING` β simplified to 4-class: `BUY (1)`, `SELL (2)`, `HOLD (3)`, `DO_NOTHING (0)`
|
| 106 |
+
5. Only winning setups are labeled as BUY/SELL; losing setups become HOLD
|
| 107 |
+
|
| 108 |
+
---
|
| 109 |
+
|
| 110 |
+
### ML Model
|
| 111 |
+
|
| 112 |
+
#### [NEW] [model.py](file:///c:/Users/User/Desktop/debugrem/ML-3m-trader/model.py)
|
| 113 |
+
|
| 114 |
+
- **LightGBM** multi-class classifier (4 classes)
|
| 115 |
+
- Hyperparameters tuned for tabular financial data:
|
| 116 |
+
- `num_leaves=63`, `max_depth=8`, `learning_rate=0.05`, `n_estimators=500`
|
| 117 |
+
- `subsample=0.8`, `colsample_bytree=0.8`, `min_child_samples=20`
|
| 118 |
+
- `class_weight='balanced'` to handle label imbalance
|
| 119 |
+
- Train/validation split: 80/20 chronological (no shuffle β time series)
|
| 120 |
+
- Feature importance output
|
| 121 |
+
- Model persistence via `joblib` (save/load `.pkl`)
|
| 122 |
+
- Early stopping on validation set
|
| 123 |
+
|
| 124 |
+
---
|
| 125 |
+
|
| 126 |
+
### Backtesting Engine
|
| 127 |
+
|
| 128 |
+
#### [NEW] [backtester.py](file:///c:/Users/User/Desktop/debugrem/ML-3m-trader/backtester.py)
|
| 129 |
+
|
| 130 |
+
Vectorized backtesting with realistic execution:
|
| 131 |
+
|
| 132 |
+
- Takes model predictions and raw price data
|
| 133 |
+
- **Position sizing**: bet % of current balance, accounting for full SL distance
|
| 134 |
+
- `lot_value = balance * bet_pct / sl_distance`
|
| 135 |
+
- **Random slippage**: uniform 0β2 XAUUSDc units applied to entry price
|
| 136 |
+
- **Spread filter**: skip trade if `sl_distance < spread * 10`
|
| 137 |
+
- **1:1 Risk-Reward**: TP distance = SL distance
|
| 138 |
+
- Walk forward bar-by-bar on test set, track equity curve
|
| 139 |
+
- No trade limit β takes every valid signal
|
| 140 |
+
- Records all trades with entry/exit prices, PnL, timestamps
|
| 141 |
+
|
| 142 |
+
---
|
| 143 |
+
|
| 144 |
+
### Metrics & Evaluation
|
| 145 |
+
|
| 146 |
+
#### [NEW] [metrics.py](file:///c:/Users/User/Desktop/debugrem/ML-3m-trader/metrics.py)
|
| 147 |
+
|
| 148 |
+
| Metric | Description |
|
| 149 |
+
|--------|-------------|
|
| 150 |
+
| Win Rate | % of trades closed at TP |
|
| 151 |
+
| Average Win % | Mean profit per winning trade as % of balance |
|
| 152 |
+
| Average Loss % | Mean loss per losing trade as % of balance |
|
| 153 |
+
| Sharpe Ratio | Annualized risk-adjusted return |
|
| 154 |
+
| Sortino Ratio | Downside-risk-adjusted return |
|
| 155 |
+
| Max Drawdown | Largest peak-to-trough equity decline |
|
| 156 |
+
| Profit Factor | Gross profit / Gross loss |
|
| 157 |
+
| Start Equity | Initial balance |
|
| 158 |
+
| End Equity | Final balance after all trades |
|
| 159 |
+
| Total Trades | Number of executed trades |
|
| 160 |
+
| Avg Trade Duration | Mean holding time in bars/minutes |
|
| 161 |
+
| Daily PnL Stats | Intraday mean, std, min, max PnL |
|
| 162 |
+
| Calmar Ratio | Annualized return / Max Drawdown |
|
| 163 |
+
| Expectancy | Average PnL per trade |
|
| 164 |
+
|
| 165 |
+
Outputs a formatted console report and saves to `results/report.txt`.
|
| 166 |
+
|
| 167 |
+
---
|
| 168 |
+
|
| 169 |
+
### CLI Entry Point
|
| 170 |
+
|
| 171 |
+
#### [NEW] [main.py](file:///c:/Users/User/Desktop/debugrem/ML-3m-trader/main.py)
|
| 172 |
+
|
| 173 |
+
Unified CLI with subcommands:
|
| 174 |
+
|
| 175 |
+
```
|
| 176 |
+
python main.py fetch # Fetch 1-year data from MT5
|
| 177 |
+
python main.py train # Engineer features, label, train model
|
| 178 |
+
python main.py backtest # Run backtest on test set
|
| 179 |
+
python main.py evaluate # Print metrics report
|
| 180 |
+
python main.py run # Full pipeline: fetch β train β backtest β evaluate
|
| 181 |
+
```
|
| 182 |
+
|
| 183 |
+
Uses `argparse` with clear help text.
|
| 184 |
+
|
| 185 |
+
---
|
| 186 |
+
|
| 187 |
+
### Project Files
|
| 188 |
+
|
| 189 |
+
#### [NEW] [requirements.txt](file:///c:/Users/User/Desktop/debugrem/ML-3m-trader/requirements.txt)
|
| 190 |
+
|
| 191 |
+
```
|
| 192 |
+
MetaTrader5>=5.0.45
|
| 193 |
+
lightgbm>=4.0.0
|
| 194 |
+
pandas>=2.0.0
|
| 195 |
+
numpy>=1.24.0
|
| 196 |
+
scikit-learn>=1.3.0
|
| 197 |
+
joblib>=1.3.0
|
| 198 |
+
```
|
| 199 |
+
|
| 200 |
+
#### [NEW] [LICENSE](file:///c:/Users/User/Desktop/debugrem/ML-3m-trader/LICENSE)
|
| 201 |
+
|
| 202 |
+
MIT License, author: Rembrant Oyangoren Albeos, year: 2026.
|
| 203 |
+
|
| 204 |
+
#### [NEW] [README.md](file:///c:/Users/User/Desktop/debugrem/ML-3m-trader/README.md)
|
| 205 |
+
|
| 206 |
+
Professional README with badges (Python, License, LightGBM), project description, features list, quick start, architecture overview, and configuration reference. No emojis.
|
| 207 |
+
|
| 208 |
+
#### [NEW] [GUIDE.md](file:///c:/Users/User/Desktop/debugrem/ML-3m-trader/GUIDE.md)
|
| 209 |
+
|
| 210 |
+
Step-by-step usage guide with tables for all commands, parameters, and expected outputs.
|
| 211 |
+
|
| 212 |
+
#### [NEW] [.gitignore](file:///c:/Users/User/Desktop/debugrem/ML-3m-trader/.gitignore)
|
| 213 |
+
|
| 214 |
+
Standard Python gitignore plus `data/`, `results/`, `models/`, `*.pkl`.
|
| 215 |
+
|
| 216 |
+
---
|
| 217 |
+
|
| 218 |
+
## Verification Plan
|
| 219 |
+
|
| 220 |
+
### Automated Tests
|
| 221 |
+
|
| 222 |
+
1. **Syntax validation** β run `python -m py_compile <file>` on every `.py` file to confirm no syntax errors
|
| 223 |
+
2. **Import validation** β run `python -c "import config; import features; import labeler; import model; import backtester; import metrics"` to confirm all modules load correctly
|
| 224 |
+
3. **Dry-run test** β run `python main.py --help` to confirm CLI is functional
|
| 225 |
+
|
| 226 |
+
### Manual Verification
|
| 227 |
+
|
| 228 |
+
1. **User runs `python main.py fetch`** with MT5 open and logged in, confirms data CSV is created in `data/`
|
| 229 |
+
2. **User runs `python main.py run`** for the full pipeline, reviews the metrics report output
|
| 230 |
+
3. **User inspects `results/report.txt`** for the performance metrics
|