The Battle of the AIs: ONNX Models vs. LLMs (via WebRequest) in MetaTrader 5
The Battle of the AIs: ONNX Models vs. LLMs (via WebRequest) in MetaTrader 5
The era of "simple" algorithmic trading is fading. The days when a basic Moving Average crossover could guarantee consistent profits are largely behind us. Today, the edge lies in Artificial Intelligence.
However, for MQL5 developers and traders, "AI" is not a monolith. It currently exists in two very distinct ecosystems within the MetaTrader 5 platform:
-
Local Machine Learning (ONNX): Fast, numerical models running directly inside the terminal.
-
Cloud-Based LLMs (via WebRequest): Reasoning models (like GPT-4 or DeepSeek) accessed via API calls.
Understanding the difference between these two technologies—and knowing when to use which—is the defining skill of modern algorithmic trading.
In this article, we will break down the pros, cons, and best practices of each approach, and explain why the "Holy Grail" might actually be combining them.
1. The Speed Demon: ONNX Models in MT5
What is it?
ONNX (Open Neural Network Exchange) is an open format for machine learning models. You train a model in Python (using libraries like TensorFlow, PyTorch, or Scikit-learn) on historical price data, export it as an .onnx file, and embed it directly into your MQL5 Expert Advisor.
How it works:
The MT5 terminal has a native OnnxRun() function. This means the calculations happen on your computer's CPU/GPU.
✅ The Pros
-
Zero Latency: Inference happens in microseconds. This is critical for scalping or tick-based strategies.
-
No Internet Dependency: Your EA works even if the API server goes down.
-
No Ongoing Costs: You don't pay per token or per API call.
-
Privacy: Your trading data never leaves your terminal.
❌ The Cons
-
"Blind" to Context: An ONNX model trained on OHLC data only knows math. It doesn't know that the Federal Reserve just announced a rate hike. It only sees the resulting candle.
-
Static Nature: To update the "brain" of the model, you must retrain it in Python and recompile the EA. It doesn't learn in real-time.
Best Use Case: Pattern recognition, tick scalping, and identifying statistical anomalies in price action (e.g., Ratio X Gold ML).
2. The Analyst: Large Language Models (LLMs) via WebRequest
What is it?
This involves connecting your EA to external AI brains like OpenAI's GPT-4o or DeepSeek via the MQL5 WebRequest() function. You send a "prompt" containing market data, news, or indicators, and the AI sends back a text or JSON analysis.
How it works:
Your EA acts as a client, sending a query to a remote server and waiting for a reasoned response.
✅ The Pros
-
Contextual Awareness: LLMs can process unstructured data. They can analyze sentiment from news headlines, correlate geopolitical events with price, and "reason" about market structure.
-
Adaptability: The model updates its internal knowledge base constantly (on the provider's side).
-
Explainability: An LLM can tell you why it wants to take a trade (e.g., "Bearish bias due to hawkish Fed comments"), whereas an ONNX model is often a "black box."
❌ The Cons
-
Latency: An API call can take 1 to 5 seconds. In high-frequency trading, this is an eternity.
-
Cost: API calls cost money (tokens). Frequent querying on every tick is financially unsustainable.
-
Hallucinations: LLMs can sometimes confidently invent facts or misinterpret data if the prompt isn't strictly engineered.
Best Use Case: Trend bias filtering, news impact analysis, and sentiment confirmation (e.g., Ratio X AI Quantum).
The Comparison: Speed vs. Intelligence
| Feature | ONNX (Local ML) | LLM (WebRequest) |
| Execution Speed | Microseconds (Instant) | Seconds (Laggy) |
| Data Input | Strictly Numerical (Price, Vol) | Textual & Contextual |
| Running Cost | Free | Per-Token Cost |
| Primary Strength | Precision & Execution | Logic & Sentiment |
| Primary Weakness | Lack of "World Knowledge" | Latency |
Best Practices for 2026: The Hybrid Architecture
If you have to choose between Speed (ONNX) and Intelligence (LLM), the answer is: Choose Both.
The most sophisticated systems on the market today—including our own Ratio X Trading Systems—utilize a Hybrid Architecture.
Here is how a professional Hybrid EA works:
-
The "General" (LLM): Every 15 minutes or 1 hour, the EA sends a WebRequest to an LLM (like GPT-4 or DeepSeek). It feeds the AI current news, daily volatility metrics, and trend structure. The LLM returns a broad bias (e.g., "Bullish Context: Buy Only").
-
The "Sniper" (ONNX/Algo): The local EA receives this bias. It then uses ONNX models or strict algorithms to execute the actual entry and exit at the micro-level, ensuring perfect timing without latency.
This way, you get the "brain" of a fundamental analyst and the "speed" of a high-frequency robot.
Experience the Power of Hybrid AI with Ratio X
Building a hybrid system from scratch requires mastering Python, MQL5, ONNX, and API engineering. Or, you can access a toolbox where this work is already done for you.
The Ratio X Trader's Toolbox features EAs that leverage the best of both worlds:
-
Ratio X AI Gold Fury: Uses DeepSeek (LLM) integration to analyze non-linear market patterns in Gold.
-
Ratio X AI Quantum: Uses sophisticated logic to filter entries based on market regime detection.
-
Ratio X Gold ML: Uses compiled machine learning for precision execution.
We don't just sell a robot; we provide an evolving ecosystem of AI technology.
🎄 A Christmas Gift for Your Trading Future
To help you upgrade your trading desk with professional-grade AI, we are offering an exclusive holiday promotion.
From now until December 25th, you can secure Lifetime Access to the complete Ratio X Trader's Toolbox (10+ EAs and Indicators) with a special discount.
-
The Offer: 15% OFF the entire toolbox.
-
Coupon Code: SANTACLAUS15
-
Deadline: Strictly December 25th.
Stop choosing between speed and intelligence. Get the arsenal that uses both.
The future of trading is hybrid. Are you ready?
Happy Holidays,
Mauricio (Ratio X Lead Developer)


