Files

3.3 KiB
Raw Permalink Blame History

Mad Turtle v2.0 — Improved ML EA for XAUUSD

Modern ML trading system: Python inference server + ONNX models + MQL5 EA with UI.

Architecture

madturtle/
├── python/
│   ├── ml_pipeline/
│   │   └── build_onnx_raw.py      # Build demo/train real ONNX models
│   ├── inference_server/
│   │   └── server.py              # FastAPI REST server
│   ├── run_server.py              # Server launcher
│   └── requirements.txt
├── models/
│   ├── xauusd_h1_ensemble.onnx    # ONNX model (demo included)
│   └── metadata.json              # Feature schema + model info
└── mql5/
    ├── scripts/
    │   └── MadTurtle.mq5          # Main EA
    └── include/
        ├── MadTurtle_API.mqh      # HTTP bridge to Python server
        ├── MadTurtle_MTF.mqh      # Multi-timeframe filters (H4/D1)
        └── MadTurtle_UI.mqh       # Status dashboard + oscillator + equity curve

Quick Start

1. Python inference server (macOS/Linux)

# Create venv (Python 3.11 or 3.12 recommended for sklearn+skl2onnx)
python3 -m venv .venv
source .venv/bin/activate

# Install dependencies
pip install numpy onnx onnxruntime fastapi uvicorn pydantic

# Run server
python python/run_server.py
# Server starts on http://0.0.0.0:8000

Test:

curl http://127.0.0.1:8000/health

2. Train a real ONNX model (optional)

# Requires Python 3.11/3.12 + scikit-learn + skl2onnx
pip install scikit-learn skl2onnx pandas

# With real XAUUSD H1 OHLCV CSV:
python python/ml_pipeline/train_onnx.py

# Or build the current demo model:
python python/ml_pipeline/build_onnx_raw.py

CSV format: datetime,open,high,low,close,volume

3. MQL5 EA setup

  1. Open MetaTrader 5
  2. Press F4 → Open MetaEditor
  3. Create new Expert Advisor MadTurtle
  4. Replace generated files with:
    • MadTurtle.mq5mql5/scripts/
    • MadTurtle_API.mqh, MadTurtle_MTF.mqh, MadTurtle_UI.mqhmql5/include/
  5. Compile (F7)

4. Run

  • Attach EA to XAUUSD H1 chart
  • Set server host/port in inputs (default 127.0.0.1:8000)
  • Ensure Python server is running before EA starts
  • Configure risk inputs manually (lot size, max positions, confidence threshold)

Features

  • Real ML inference via ONNX Runtime (no external API calls at runtime)
  • 14 engineered features: returns, SMAs, EMA/MACD, RSI, ATR, volume ratio, range, dist_sma20
  • Multi-class output: BUY / HOLD / SELL with confidence probabilities
  • Multi-timeframe confirmation (H4 + D1 SMA/RSI/MACD filters)
  • Dark-themed UI: status dashboard, P&L metrics, equity curve, signal oscillator, chart arrows
  • No grid, no martingale, no external dependencies at runtime

Risk Management

You define all risk parameters in EA inputs:

  • InpLotSize — fixed lot per trade
  • InpMaxPositions — max simultaneous positions
  • InpMinConfidence — minimum model confidence to trade
  • InpStopLossPts / InpTakeProfitPts — fallback SL/TP if model doesnt set them

Model Replacement

  1. Train a new model on real data
  2. Export to models/xauusd_h1_ensemble.onnx
  3. Restart Python server — EA picks it up automatically

License

MIT — improved upon Mad Turtle concept. Not affiliated with original author.