🤖 Agentic AI Trading

Claude Code for Trading: How to Build an AI EA in 2026

By Dan Machado · 12 min read

Claude Code for trading exploded in 2026, as agentic coding tools let traders with no programming background build sophisticated Expert Advisors. In February 2026, quant researcher Saulius built the QuantaAlpha framework using Claude Code — an autonomous system that analyzed 53 commodity futures contracts across a decade of historical data. This tutorial shows how you can build an EA with Claude Code, on a smaller scale, today.

Claude Code for trading: what it is (vs. regular ChatGPT)

Claude Code is Anthropic’s agentic coding tool. Unlike ChatGPT or Claude in a browser, it:

  • Runs in your terminal/IDE: it has direct access to your files
  • Executes code: it doesn’t just suggest — it tests, debugs, refactors
  • Keeps long context: it works across projects with dozens of files
  • Learns from errors: when it sees an error output, it adjusts the code automatically
  • Is instructable: you set guardrails (‘never use a DLL’, ‘always validate with the Strategy Tester’)

For trading, that means: you describe the strategy in plain English, and Claude Code generates a working MQL5 EA, refines it based on backtests, and keeps the code consistent across sessions.

Real case: QuantaAlpha (Feb 2026)

QuantaAlpha is a factor mining framework (automatic discovery of predictive factors in financial time series) built by Saulius in February 2026, entirely with Claude Code:

  • Scope: 53 commodity futures contracts (oil, gas, gold, soft commodities)
  • Dataset: ~10 years of historical data (~2.5M bars)
  • Output: identified 200+ candidate quant factors with an in-sample Sharpe > 1.0
  • Total time: ~3 weeks of development (with Claude Code)
  • Cost: under $500 in API usage

Before Claude Code, a similar project would have required 6-12 months of work from a senior quant developer.

Prerequisites for using Claude Code in trading

  • Anthropic account: Claude Pro or API access (Pro includes Claude Code with a generous usage limit)
  • MetaTrader 5 installed: to test the EAs it generates
  • Python 3.10+: for analysis scripts and model training
  • An editor with a terminal: VS Code is the standard (Claude Code has an official extension)
  • Minimal trading knowledge: you need to be able to describe the strategy (entries, exits, risk)
  • You DON’T need to: know MQL5, Python, or any coding at all

Step-by-step workflow

Step 1: Define the strategy in plain English

Before opening Claude Code, write your strategy out in clear text. Example:

“I want an EA for Volatility 75 on Deriv MT5 that:
1. Calculates RSI 14 on the M15 timeframe
2. When RSI < 30, buys with SL 1% below and TP 2% above
3. When RSI > 70, sells with SL 1% above and TP 2% below
4. Maximum 3 simultaneous trades
5. Stops trading after 2 consecutive losing trades
6. Logs every decision to a file
7. Doesn’t trade in the first 5 minutes after the week opens”

Step 2: Start Claude Code with guardrails

# Start Claude Code with initial instructions
claude

# First message - set the project's guardrails
> Let's build an MQL5 EA for MT5. Important rules:
> 1. ALWAYS validate the code in the Strategy Tester before declaring it done
> 2. NEVER use external DLLs - only native MQL5 functions
> 3. Use the updated ENUM_ONNX_FLAGS from Build 5572 (ONNX_LOGLEVEL_*)
> 4. Stop loss and risk management are ALWAYS mandatory
> 5. Comments in English, code following standard MQL5 conventions
> 6. Create this structure: main EA file + separate include files for risk/logging

Step 3: Ask for the initial EA

> Create the EA per this description: [paste your spec from Step 1]
> Desired structure:
> - src/MyEA.mq5 (main file)
> - src/Include/RiskManager.mqh (risk management)
> - src/Include/SignalEngine.mqh (signal logic)
> - src/Include/Logger.mqh (logging)

Step 4: Iterate and refine

Claude Code will generate the full code. From there, you iterate:

  • “Add a volatility filter that avoids trading when ATR is in the top 10% of the last 100 periods”
  • “The backtest is losing a lot on the Sunday gap. Add an automatic exit on Friday at 21:00 GMT”
  • “I want to plug in an ONNX model I trained. How do I do that?”
  • “The EA is overtrading. Add a 30-minute cooldown between trades”

Claude Code keeps context across all these messages, edits the right files, and keeps everything consistent.

Step 5: Validate with the Strategy Tester

Here Claude Code can help, but you decide the criteria:

  1. Compile the EA in MetaEditor (Claude Code helps you fix compile errors)
  2. Run a backtest for 2024-2026 on V75 M15
  3. Note: profit factor, max drawdown, number of trades, win rate
  4. Paste the results back into Claude Code: “Results: PF 1.3, DD 18%, 450 trades, WR 52%. What should I optimize next?”
  5. Claude Code suggests changes based on the numbers

Advanced prompt example: integrating ONNX

> I have an ONNX model trained in Python (2-layer LSTM, hidden size 32,
> input: 30 normalized OHLC candles, output: 2 classes: BUY/SELL).
> File: lstm_v75.onnx (3.2 MB)
>
> Modify the current EA to:
> 1. Embed the model as a #resource
> 2. Initialize with OnnxCreateFromBuffer + CUDA flag if available
> 3. Replace the RSI logic with the model's prediction
> 4. Keep a confidence threshold: only trade if prob > 0.7
> 5. Update OnnxRelease in OnDeinit
> 6. Add a fallback to RSI if the model fails

Pros and cons vs. learning to code

Aspect Claude Code Learning MQL5
Time to first working EA 1-2 hours 2-4 months
Cost ~$20/month (Pro) Time + courses
Code quality Good (varies) Good (with practice)
Maintainability You need to be able to read it You can modify it yourself
Advanced debugging Claude helps but it’s limited You’re self-sufficient
Real innovation Limited to known patterns You innovate

Recommendation: use Claude Code to move faster — but learn the basic fundamentals of MQL5 in parallel (1-2 hours/week). You don’t need to become a programmer, but you need to understand what Claude Code is generating.

Important limitations

  • It’s not magic: if your strategy has no edge, Claude Code won’t discover one — it’ll just implement well whatever you asked for
  • Realistic backtesting is ON YOU: Claude Code can generate an EA that looks good on a limited sample. You need to test it on real out-of-sample data
  • Prompt overfitting: iterating too many times can end up “forcing” parameters that only worked in those specific tests
  • Costs can add up: complex projects (50+ files) consume more tokens — keep an eye on usage
  • Subtle bugs happen: always test on demo for 30+ days before going live

Practical next steps

  1. Subscribe to Claude Pro ($20/month) — includes Claude Code with generous usage
  2. Install the Claude Code extension in VS Code
  3. Start with a simple EA (a strategy you already know well)
  4. Iterate until it passes a 2-year backtest with PF > 1.3 and DD < 20%
  5. Demo trade the EA on Deriv for at least 30 days
  6. Only then take it live with a minimum stake
  7. Once you’ve mastered this, move on to EAs with ONNX (AI models)

🚀 To test EAs with ONNX, get a free Deriv MT5 demo ($10,000 virtual):

Open Deriv MT5 Demo →

DM

Dan Machado

Founder IA Trader Pro · AI-for-trading specialist

⚠️ Disclaimer: Educational content, not investment advice. Trading involves substantial risk. AI tools do not guarantee profit and can make mistakes. Always test on demo before trading with real capital. This article contains a Deriv affiliate link.

Similar Posts