Video summary

How to Build an MT5 Expert Advisor with ChatGPT Full MQL5 EA Code + Prompts #aitrends #trading

Main summary

Key takeaways

Technology

Summary of the Video (Tech Concepts, Features, and Tutorial Steps)

The video is a walkthrough for building an MT5 Expert Advisor (EA) using ChatGPT-assisted MQL5 code. It covers the exact prompts used by the creator, how they validate and fix compiler errors, and how they test and optimize EA inputs in MT5 Strategy Tester.


1) Using ChatGPT to Generate an MT5 EA from an MQL5 Reference

The creator uses ChatGPT to:

  • Ingest a provided MQL5 PDF reference, using an auto-generated prompt like:

    “Read this entire MQL5 PDF… internalize the full MQL5 reference”

  • Wait for further instructions before writing code.

  • Emphasize that the generated MQL5 code should be efficient, mentioning considerations like execution speed and system resource usage.

2) Prompt-Driven EA Specification (Core Strategy Behavior)

The EA behavior is defined in a prompt (Prompt #2) and includes the following mechanics:

Entry Trigger

  • Trade US30 (via a symbol input).
  • First entry at the market open time 16:30.
  • Additional entries occur on pullbacks, measured using ATR (Average True Range) of the day.

Position Management

  • “Build a position over time.”
  • Move stops to break-even when price moves to approximately 1.5 × daily ATR.
  • Ensure break-even stop movement happens only once per trade.
  • Allow multiple trades, but limit them so there is one trade at a time (no overlapping “new trade” stacking).

Exit Logic

  • Close trades when price reaches a target related to ATR:
    • A stop/target offset described as 1.2 × ATR lower than the entry price (the exact interpretation depends on how the EA defines target vs. stop).
  • Include a failsafe stop:
    • Close all trades if equity drops by an input percentage (prop-firm friendly risk control).

The video notes that the full code and how to set inputs come directly from the ChatGPT output.


3) Implementation Workflow in MetaEditor (Coding + Compile-Fix Loop)

The tutorial demonstrates a practical workflow for inserting and compiling ChatGPT-generated EA code:

  1. Open MetaEditor / MQL5 IDE.
  2. Create a new Expert Advisor template.
  3. Paste the generated code and compile (press F7).
  4. If there are compiler errors:
    • Copy the compiler error lines (possibly in multiple rounds).
    • Paste the errors back into ChatGPT with questions and guidance such as:
      • “Why aren’t you fixing it?”
      • “Rewrite ensuring it is MQL5” (with emphasis like “deep thought”).
    • Manually patch specific problematic logic when needed (e.g., fixing a “close all” function).

Result: after repeated error-feedback iterations, the EA eventually compiles successfully.


4) Strategy Testing / Validation in MT5 (Functional Verification)

The EA is tested in Strategy Tester, using:

  • Visual mode to observe behavior step-by-step.
  • Checks to confirm expected behavior, including:
    • Trades appear at 16:30
    • Additional entries happen on ATR pullbacks
    • Stops move toward break-even under the expected conditions
    • The failsafe can close all positions based on drawdown

The video also mentions:

  • Observing equity/balance changes on the chart.
  • Seeing multiple daily trade cycles.
  • Journal logs referencing behavior like:

    “draw down, fail safe, hit, closing all”


5) Changing from Fixed Equity Target to Percentage-Based Target

A key change is introduced after noticing unexpected behavior:

  • Initially, the EA uses a fixed equity target (e.g., 3,300), but it may:
    • Continue placing trades even after closure conditions are met.
  • The creator asks ChatGPT to modify the logic so “target equity” becomes a percentage-based input (e.g., 10%).

After rewriting:

  • The EA hits the percentage target and exits more consistently.
  • The creator notes the updated EA runs slower in testing, likely due to more frequent equity monitoring/checks while trades are active.

6) Efficiency Prompt (Optional / Not Executed)

The creator mentions a potential next improvement:

  • “Make the code as efficient as possible” considering:
    • system resources,
    • latency,
    • MT5 limits.

However, the creator does not run that prompt because performance is “okay” and behavior matches expectations.


7) Optimization of EA Inputs Using Strategy Tester (Genetic / Fast Algorithm)

The video transitions from single backtests to parameter optimization using a fast genetic algorithm.

Optimized Inputs (Examples)

  • Target gain (percentage): explored from about 1% up to 40
  • Max drawdown: explored from about 4% up to 20

The creator describes running many iterations (e.g., 200 iterations per target step set, with overall run described as hundreds of iterations).

Optimization Metrics Used

  • Profit factor
  • Expected payoff
  • Best ending balance/equity

Example Selected Configuration

  • “target equity is 21%”
  • “max drawdown set to 8%”

Then, the creator runs a single test on the best configuration to inspect equity/drawdown progression.


8) Reporting and Analysis of Backtest Statistics (With Cautions)

The EA’s backtest output includes detailed statistics, including example ranges such as:

  • Starting equity ~$3K
  • Ending equity ~$6,222
  • Profit factor ~1.26
  • Drawdown:
    • Max balance drawdown around 22%
    • Max equity drawdown around 75%
  • Trade outcomes:
    • Win rate around 40%
    • Loss rate around 59%
    • Average profit per trade around $61
  • Streak metrics:
    • Max consecutive wins ~36
    • Max consecutive losses ~39
  • Day/Month insights:
    • “best day/month” based on trade close times

The creator warns that day-of-week/month attribution can be misleading, since:

  • trades may open on one day and close later, causing stats attribution quirks.

9) Where to Get Prompts and Code

The creator states that:

  • All prompts and full EA code are available on a website linked in the video description.

Main Speakers / Sources

  • Primary speaker: the video author/instructor (speaks throughout the tutorial, referencing “prompt number one/two/three” and demonstrating steps).
  • Source material used for coding: an MQL5 PDF reference provided/uploaded into ChatGPT.
  • Systems/tools referenced: ChatGPT, MetaEditor (MQL5), MT5 Strategy Tester, and US30/indices symbol usage.

Original video