Introduction to Embedding AI into EA (Gemini API, Claude, ONNX): Design and Pitfalls [MT5 only]
When you hear “AI-equipped EA,” what image comes to mind?
AI reads the market, finds good opportunities on its own, and makes money. It might sound like a dream come true.
But when you actually try incorporating AI into your EA, the reality is quite different from that image. AI isn’t a magic wand; it’s closer to a consultant who, when given data, offers their opinions.
My EA includes a mechanism to consult with AI like Gemini and Claude. In this article, based on that experience, I’ll explain as clearly and in as much detail as possible the following points.
What you’ll understand in this article
- Why integrate AI into an EA in the first place
- What kinds of judgments AI makes (and what it isn’t trusted to do)
- What’s the difference between AI run inside MT5 and external AI (Gemini and Claude)
- Overall design when incorporating AI and common pitfalls
- Actual working sample code to call Gemini and Claude (you can copy and use it)
To give you the conclusion first: here it is.
Don’t make AI the “final decision-maker.” Instead, use it as a consultant that organizes the decision material. And let the final decision be dictated by the EA’s own rules.
This mindset becomes the foundation for the rest of the discussion.
【For those who haven’t built an EA yet】
The method for building the EA itself is explained in my paid article“From Programming Beginners to EA Development”There, it’s recommended for anyone who hasn’t yet built an EA to start with that. This article is about adding AI judgment to an EA built in that way.
【Paid part includes a trial code】
The paid part includes a trial code that you can copy and paste to compile and run (Chapter 18. It comes with a dashboard). It won’t trade, so you can safely test on a demo account.
1. Why put AI into an EA
First, the most important discussion. The purpose of adding AI to an EA isn’t “to win.”
There’s no guarantee that adding AI will make you win. What matters is to clearly define in advance “what you expect from AI.”
A rules-based EA excels at conditions expressed in numbers like “RSI above X” or “price above EMA.”
On the other hand, judgments such as “how confident are we when looking at several situations together” are hard to codify into rules. Adding more conditions makes things more complex, and it becomes unclear what is working where.
Therefore, I expect AI to help with the following:
What I expect from AI
- Have AI summarize multiple materials to give a direction and how confident it is
- If materials are not ready, say “defer for now”
- Provide the reasoning for judgments in short sentences (so you can review logs later)
- While a position is open, alert when the situation reverses
Of course, whether these actually improve the EA’s performance is another matter. You need to compare AI-enabled and non-AI versions under the same conditions to verify. Honestly, I haven’t yet performed a controlled comparison under identical conditions. That’s why it’s important to be clear about the purpose of using AI and to record and verify as you go.
If you don’t narrow the purpose and just add AI because it’s trendy, you’ll end up with a mediocre EA. Before you add it, write down what you expect AI to do on paper.