Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

How to build AI trading expert advisors (EAs)

AI logo with rising candlestick chart and red trend line, symbolizing ChatGPT use in financial trading.

Whether you’re a seasoned algorithmic trader or a beginner exploring automated trading, AI can help you generate expert advisors (EAs) for platforms like Deriv MT5 and Deriv cTrader quickly and efficiently – without coding!

In this guide, we’ll walk you through EAs and how to use AI tools like Claude, ChatGPT, and Gemini to create, test, and improve trading algorithms. We’ll also explore an AI debugging agent that will further streamline the process.

What’s an expert advisor (EA)?

Expert Advisors (EAs) are automated trading programs designed to execute trades based on pre-set strategies, helping traders take advantage of market opportunities without the need for constant manual monitoring. EAs are available to use on platforms like Deriv MT5 and Deriv cTrader, where they are known as cBots. 

These tools enable traders to automate complex trading logic, analyse market conditions, and manage trades with speed and precision. By using AI bots for trading like Expert Advisors (EAs) or cBots, traders can better manage emotional decision-making and ensure consistent execution of their strategies. They not only improve efficiency but also allows for 24/7 market participation — even during volatile or fast-moving sessions. 

While EAs can be purchased or rented, building custom EAs to automate your own trading strategy is possible using MQL programming language on Deriv MT5 and C# for Deriv cTrader. Both platforms offer dedicated environments for backtesting and optimisation, allowing users to evaluate their strategies using historical data before applying them to live markets.

Build your own AI expert advisors

Traditionally, building expert advisors (EAs) requires knowledge of MQL5 for MT5 or C# for Deriv cTrader, making it inaccessible for many traders. However, modern AI models can now generate, refine, and even debug trading scripts, making automated trading more accessible than ever.

Instead of relying on coding tools, you can now utilise AI-powered models to:

  • Generate EA code instantly by describing your strategy in plain language.
  • Fix common coding errors without prior programming knowledge.
  • Optimise trading algorithms using AI-powered debugging tools.

This shift reduces the complexity of EA creation and allows traders to focus on strategy development and execution rather than syntax and debugging. Just follow the steps below:

Step 1: Choose the right AI model for EA generation

Various AI models can assist in generating AI bots for trading or EA code for Deriv MT5 and Deriv cTrader. Each has unique capabilities, and traders may find different models more suitable based on their needs.

Generally, there are three commonly used models for EA generation:

Claude by Anthropic
Known for structured and organised responses.

ChatGPT by OpenAI
Popular for coding-related tasks and conversational guidance.

Gemini by Google AI
Used for general AI-assisted trading automation queries.

However, since AI models evolve quickly, you should always explore different options and select the one that works best for your strategy development and coding requirements.

Step 2: Generating the EA’s code

One of the most important steps in AI-assisted coding is providing a precise and well-structured prompt. Make sure that your parameters, numbers, and indicators are clear and well-defined in the prompt. 

For example, suppose you want to create a Deriv MT5 Expert Advisor (EA) that uses the relationship between the 50-hour and 200-hour Simple Moving Averages (SMA) to trigger trading orders, sets the stop-loss at the last swing low (i.e., the lowest point in the previous 50 hourly candles), and risks 1% of your account balance per trade. In that case, you could prompt the AI model as follows:

"You are an MQL5 expert. Create an expert advisor (EA) in MQL5 that enters a buy trade when the 50-SMA crosses above the 200-SMA on the H1 timeframe. The EA should set the stop-loss at the last swing low, exit trades when the crossover is reversed, and ensure each trade risks 1% of the account balance."

Also, look at this prompt meant to help create an EA for Deriv cTrader:

"You are a C# expert. Write a Deriv cTrader trading bot in C# that enters a buy trade when RSI (14) is below 30, and the price closes above the 20-EMA on the H1 timeframe. The bot should exit trades when RSI reaches 70 and risk 2% of the account balance per trade."

In this prompt, you’re asking the AI model to write C# code for a strategy that buys when the market is oversold and showing signs of recovery. It enters a buy trade on the 1-hour chart when the RSI 14 is below the RSI 30, and the price closes above the 20-hour Exponential Moving Average (EMA). The trade is closed when the RSI reaches 70, indicating the market may be overbought. Each trade risks 2% of the account balance to manage risk effectively.

Pro tip: You can use AI to generate and refine the prompt for even better results. The more detailed your prompt, the more accurate and functional the AI-generated code will be! 

Step 3: Test, troubleshoot, and execute

Once the AI provides the code, the next step is testing it in Deriv MT5 or Deriv cTrader. Here's how:

For Deriv MT5 (MQL5):

  1. From Deriv MT5’s toolbar, click IDE
  2. At the top left corner, click New and select Expert Advisor
  3. Insert a name for your EA and follow the instructions
  4. At the MetaEditor, you can paste your code and check for errors
  5. Before implementation, backtest the EA to verify the functionality
  6. If the EA works as expected, go back to Deriv MT5, open Navigator → Right-click Expert AdvisorsRefresh
  7. Drag the EA to a chart and enable Algo Trading.

Tip: If errors occur, copy and paste the error messages into the AI for troubleshooting.

For Deriv cTrader (C#):

  1. Open Deriv cTrader and go to the Automate (Algo Trading) tab.
  2. Click New cBot, give it a name, and paste the AI-generated code.
  3. Click Build and check for errors.
  4. Before implementation, backtest the cBot to verify the functionality
  5. If the cBot works as expected, attach the cBot to a chart and test.

Give it a try!

AI is making algorithmic trading more accessible by removing coding barriers. By leveraging Claude, ChatGPT, or Gemini, traders can easily generate, test, and refine expert advisors for Deriv MT5 or Deriv cTrader.

Start today—experiment with AI-generated EA code and see how it enhances your automated trading strategy: https://deriv.com/

Disclaimer:

This content is not intended for EU residents. The information contained within this blog article is for educational purposes only and is not intended as financial or investment advice. The information may become outdated. No representation or warranty is given as to the accuracy or completeness of this information. We recommend you do your own research before making any trading decisions.