A new era of EA trading: create your own Expert Advisor using AI

7
min read

A new era of EA trading: create your own Expert Advisor using AI

7
min read
Red robotic hand interacting with a candlestick chart, symbolising AI-driven EA trading and automation in financial markets.
Lesson
This is some text inside of a div block.
This is some text inside of a div block.

Heading

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.

Duration
This is some text inside of a div block.
minutes

What is Expert Advisor trading

If you’re wondering what an Expert Advisor (EA) is, you’re not alone! An Expert Advisor is an automated trading programme that runs within platforms like MT5 and cTrader, opening, managing, and closing trades based on predetermined rules. Thanks to artificial intelligence, you can now create or refine your own expert advisor for trading with ease, even if you have limited coding experience.

Why use AI to create your Expert Advisor 

Creating an Expert Advisor can seem daunting—especially if you don’t have coding experience. The good news is that using AI now allows both beginners and seasoned traders to create expert advisor robots by simply explaining trading rules in plain language. AI models like Claude, ChatGPT, and Gemini transform your trading ideas into working code, making expert advisor trading more accessible and powerful.

1. Selecting the right AI model to create an Expert Advisor 

To start, choose an AI model to generate your EA code. The most popular options include:

  • Claude (by Anthropic) — excels at producing structured code.
  • ChatGPT (by OpenAI) — the paid version is especially renowned for coding tasks. Use GPT-4 (o1) to craft the initial logic and prompt, and GPT-4o (o3 mini) for refining output.
  • Gemini (by Google AI) — also suitable for algorithmic trading code.

Experiment with each model to find which best suits your approach and needs.


2. How to prompt AI to create an Expert Advisor

Before generating code, you may want to ask the AI to help define or refine your trading logic, especially for advanced strategies. While you can skip this, it can improve results significantly.

Once ready, use a clear, structured prompt. For example:

“You are an expert MQL5 coder. Create a fully functional expert advisor (EA) in MQL5 based on the following logic and rules. Add clear comments so the code is easy to follow. Provide the complete .mq5 source code within triple backticks at the end.”

Next, outline your strategy. For example:

  • Use a 50-period Simple Moving Average (SMA) and a 200-period SMA.
  • Enter a buy trade when the 50 SMA crosses above the 200 SMA on the H1 timeframe.
  • Close the trade when the SMA crosses back down.
  • Set stop-loss at the last swing low.
  • Risk 1% of account balance per trade.

The more specific your instructions, the more accurate and useful the AI’s output will be.

3. Copying and testing your AI-generated EA code

For Deriv MT5 (MQL5)

  1. From Deriv MT5’s toolbar, click IDE.
  2. In the top left corner, select New and choose Expert Advisor.
  3. Enter a name for your EA and follow the prompts.
  4. Paste your AI-generated code into the MetaEditor and check for errors.
  5. Backtest the EA to make sure it functions as expected.
  6. If all looks good, return to MT5, open Navigator → right-click Expert Advisors → Refresh.
  7. Drag your EA onto a chart and enable Algo Trading.

For Deriv cTrader (C#)

Ask the AI for a cBot in C#. Use a clear, detailed prompt, such as:

“Write a cTrader trading bot (cBot) in C# that enters a buy trade when the RSI (14) is below 30, and the price closes above the 20-period EMA on the H1 timeframe. Exit the trade when RSI reaches 70. Risk 2% of balance per trade.”

  • The more specific your prompt, the better the output.
  • If you encounter errors, paste the error messages back into the AI; it can usually help you resolve issues.

4. Common AI mistakes when creating an EA for trading and how to fix them

AI-generated code is not always perfect. Here are a few issues you might encounter, along with their solutions:

1. Issue: “Undeclared identifier” error in MQL5

Fix:  The AI may use a variable or function that isn’t defined. Double-check indicator calls like iMA() or iRSI() to ensure they’re correctly specified.Missing buy or sell functions

2. Issue: Missing buy or sell functions

Fix: Add trading functions manually. For example:

Example MQL5 code for an EA showing how to manually create a buy order using MqlTradeRequest and OrderSend().

3. Issue: Trade logic not working in Deriv cTrader

Fix: Make sure your code is inside the correct event handler, such as OnBar() or OnTick()

4. Issue: Incorrect lot size calculation

Fix: The AI may calculate position size based only on account balance, missing contract size. This can result in trades that are too large or too small. Always run a backtest and adjust the formula if necessary.


5. The best practices for using AI in trading 

Although AI can produce working code, it may lack efficiency or reliability. Consider these suggestions to improve your EA:

  • Add error handling for unexpected market conditions.
  • Use a trailing stop-loss to lock in profits.
  • Run backtests to optimise strategy performance.
  • Review the code manually or use the MetaEditor Debugger in Deriv MT5.


6. Coming soon: AI Debugging Agent

A new AI-powered EA Debugging Agent is in development. When released, it will:

  • Automatically fix syntax errors in AI-generated code
  • Improve execution efficiency
  • Explain each line of code in simple terms

This tool will make debugging quicker and more accessible, so stay tuned for updates.

Conclusion

With today’s AI tools, building an expert advisor for Deriv MT5 or Deriv cTrader is more accessible than ever. By providing clear prompts and testing your code thoughtfully, you can create, refine, and enhance your own trading algorithms. If you encounter challenges, refer to the common fixes and suggestions provided above.

Ready to create your own automated trading strategy? Try it now on Deriv MT5 or Deriv cTrader and let AI help you bring your trading ideas to life!

Quiz

No items found.

FAQs

Do I need previous coding experience to create an EA using AI?

No, with AI tools such as Claude, ChatGPT, and Gemini, even beginners can generate EA code by providing clearly defined trading rules.

What should I do if my AI-generated EA fails to trade as expected?

First, check for coding errors or logic mistakes. Ensure trade functions are present, and your logic is correctly placed within the main event handlers (like OnTick() or OnBar()). If you get error messages, paste them into your AI tool for guidance.

How can I improve the performance and reliability of my EA?

Enhance your code with extra error handling and consider using features like trailing stop-losses. Always perform thorough backtesting and, if possible, manually review or debug the code before deploying it on a live account.