Spezifikation
SECTION 1: OVERVIEW AND COMPONENT ARCHITECTURE
The objective of this project is to build a fully automated Trading System in native MQL5 that integrates a pre-trained Open Neural Network Exchange (ONNX) machine learning model into MetaTrader 5. The EA must be engineered using strict Object-Oriented Programming (OOP) paradigms, featuring clean decoupling between signal inference, execution handlers, and risk management modules. The system must maintain zero memory leaks through deterministic pointer lifecycle management and operate reliably on both Netting and Hedging account structures without dependency on third-party libraries outside native MQL5 bindings.
SECTION 2: MACHINE LEARNING & TENSOR PIPELINE
Inference must be handled directly through MetaTrader 5 native ONNX functions (OnnxCreate , OnnxRun ). The input pipeline must implement strict parity with the feature engineering transformations developed in Python (CatBoost / PyTorch / Scikit-Learn).
The EA is responsible for maintaining rolling historical data buffers in memory to generate real-time feature vectors on a bar-close or tick-by-tick basis. Input float/double arrays must match the exact shape and layout expected by the model tensor [1, N] . Execution guardrails must be implemented to reject any trade signals if model evaluation outputs NaN , invalid probabilities, or if inference evaluation time exceeds 5 milliseconds. On inference exception, the EA must safely abort signal propagation and log a system warning to the terminal journal without opening default or unchecked positions.
SECTION 3: ORDER EXECUTION AND RISK CONTROL
Trade execution must utilize the native CTrade class or a custom robust execution wrapper with explicit slippage parameters, retry limits, and return code handling (TRADE_RETCODE_DONE ). Every market order must submit a hard Stop Loss and Take Profit attached directly within the initial trade request matrix; orders placed without mandatory protective stops are strictly forbidden.
Risk management must operate independently of the machine learning signal generator. The system must feature dynamic position sizing calculated as a fixed fractional risk percentage of account equity, optionally adjusted for volatility using historical ATR. Martingale, grid expansion, or unhedged position-averaging logic are strictly prohibited.
Hard account protection controls must enforce:
-
Daily Max Equity Drawdown Limit: Immediate position liquidation and dynamic trading pause until the next daily reset.
-
Absolute Account Trailing/Static Drawdown Limit: Permanent trading lockout with forced closure of all open positions upon breach.
-
Spread and Liquidity Filter: Automatic block on trade placement during news events or periods where market spread exceeds predefined point limits.
SECTION 4: DIAGNOSTICS, LOGGING, AND CHART DISPLAY
The EA must output continuous operational telemetry to both the MetaTrader 5 Experts Journal and a structured CSV log file located in the MQL5 Files directory. Log entries must detail timestamps, raw feature vector values, raw model outputs, trade decision logic, slippage in points, and execution latency measured in milliseconds.
An optional, lightweight on-chart panel must render essential runtime metrics, including current model prediction probabilities, system operation status, daily net PnL, current floating drawdown, and account equity tracking.
SECTION 5: DELIVERABLES AND ACCEPTANCE TEST PROTOCOL
The developer must deliver the complete .mq5 source code, all custom .mqh header dependencies, and a sample .onnx model file for system verification. Acceptance requires successful backtesting on MetaTrader 5 Strategy Tester over multi-year tick data (Every Tick Based on Real Ticks) with zero uncaught execution errors, no unhandled trade context errors, zero memory leak warnings upon deinitialization (OnDeinit ), and full compliance with specified daily drawdown safety limits.