Explore Companies BySectors & Categories
Explore Companies ByUse Cases
Explore Companies ByProducts & Services
Explore Companies ByRankings & Reviews
Featured NewsCompaniesMarketsCryptoTechRegulatoryCommentaryUKUSWorldMore

    Latest Wires

      Daily Newsletter

      LF Daily News

      Daily industry focused newsletter giving you an overview for the financial & finTech industry.

      See All Newsletters
      By clicking "Sign Up" you are agreeing to our Terms of Service and Privacy Policy

      How to Build Your First MT5 Expert Advisor Using AI (No Coding MQL5 Walkthrough)

      Published: just now

      How to Build Your First MT5 Expert Advisor Using AI (No Coding MQL5 Walkthrough)

      TL;DR – Key Takeaways


      1. Turn Trading Rules into Auto-Traders: Convert your written trading strategy into a fully automated MetaTrader 5 (MT5) Expert Advisor (EA) without writing code.
      2. Two-Step AI Workflow: First, use your preferred Web AI (ChatGPT, Claude, or Gemini) to turn an educational strategy guide into an MT5 Master Prompt. Second, paste that prompt into your MT5 Terminal AI.
      3. Automatic File Creation: The MT5 Terminal AI automatically generates and saves the .mq5 Expert Advisor file directly into your MT5 Experts directory, no need to manually create new code files.
      4. One-Click MetaEditor Compilation: Open MetaEditor, verify your generated file, and click 'Compile' to bring your trading bot to life on your live or demo charts.
      5. Execution & Troubleshooting: Learn quick solutions for common AI and compiler errors.


      In our previous guides, we showed you how to connect Gemini AI to MT5 for free and how to activate MT5's built-in native MT5 AI assistant. We also introduced our Gold (XAUUSD) Price Action Strategy Framework to scan live charts using AI prompts.


      Scanning charts manually is great, but active traders face one major challenge: time. Key market breakouts on Gold or major currency pairs often happen during session overlaps when you are away from your screen or unable to monitor multiple timeframes.


      This guide takes your trading workflow to its natural conclusion: turning your strategy into a 24/7 automated Expert Advisor (EA). Using our two-step AI workflow, you don't need any programming background—your Web AI creates the master prompt, the MT5 Terminal AI generates and saves the EA file automatically, and MetaEditor compiles it with one click.


      Post illustration

      How to Build Your First MT5 Expert Advisor Using AI: Core MQL5 Architecture


      First, let's understand the difference between an MQL5 Script and an Expert Advisor (EA):

      1. An MQL5 Script executes once when you drop it onto a chart (for example, to close all open trades) and then stops.
      2. An Expert Advisor (EA) remains active on your chart. It monitors every price tick second by second, checking your strategy rules to open, manage, and close trades automatically.


      Every automated trading bot is built on four core building blocks that AI handles for you:

      1. 1. Startup Setup (OnInit): Initializes indicator settings and prepares the chart environment.
      2. 2. Price Watcher (OnTick): Continuously analyzes price movements on every tick to spot entry signals.
      3. 3. Trade Executor: Opens Buy or Sell positions automatically using MT5's native CTrade functions.
      4. 4. Risk Shield: Enforces mandatory Stop Loss and Take Profit bounds and calculates lot sizes based on your risk rules.


      Post illustration


      MetaEditor AI Assistant MQL5 Prompt Examples for EA Generation

      To ensure seamless code generation, we follow the exact Two-Step Prompt Engineering method established in our strategy training guide.


      Step 1: Generate Your MT5 Master Prompt Using Web AI

      First, open your preferred Web AI (ChatGPT, Claude, or Gemini Web) and feed it an educational strategy guide, such as ACY Securities' Gold Price Action Strategy guide along with the prompt instructions below:


      (EXAMPLE ONLY)

      Act as an expert MQL5 prompt engineer.Read the technical strategy guidelines from the following reference:[Paste your educational strategy notes, rules, or reference text here]
      Convert these guidelines into a structured, single-block MT5 Master Prompt designed to instruct an MT5 Terminal AI to generate a complete Expert Advisor (.mq5 file).
      --- STRATEGY SPECIFICATIONS TO INCLUDE ---1. SYMBOL & TIMEFRAME: XAUUSD (Gold), execution on H1 chart with Daily trend bias.2. ENTRY LOGIC: - BUY: Daily trend is Bullish (Price above 20 EMA) AND H1 price breaks above Resistance with a Bullish Engulfing candle. - SELL: Daily trend is Bearish (Price below 20 EMA) AND H1 price breaks below Support with a Bearish Engulfing candle.3. RISK MANAGEMENT: - Risk per trade: 1% of account balance (calculate lot size automatically). - Stop Loss: 15 pips outside recent swing high/low. - Take Profit: Minimum 1:2 Risk-to-Reward ratio.4. MQL5 CODE REQUIREMENTS: - Use native CTrade library (#include <Trade\Trade.mqh>). - Implement OnInit(), OnDeinit(), and OnTick() functions. - Restrict execution to ONE trade per candle setup. - Add error reporting via GetLastError().

      Pro Tip: Terms like "swing high" or "engulfing candle" can be coded in multiple ways. For the cleanest code output, tell your Web AI exact bar references—such as "use the highest high of the previous 10 completed bars for swing reference" and "confirm engulfing on bar close (Bar 1 vs Bar 2)."

      Post illustration

      Step 2: Paste the Master Prompt into MT5 Terminal AI (Automatic File Creation)


      Copy the formatted Master Prompt generated by your Web AI, switch to MetaTrader 5, and paste it directly into your active MT5 Terminal AI Chat Window (whether using Gemini 3.5 Flash-lite API or the native MQL5 Lite model).


      Important Note: The Major Advantage: When you prompt the MT5 Terminal AI to build an Expert Advisor, MT5 automatically generates and saves the .mq5 file directly into your platform's MQL5/Experts folder. You do not need to manually create a blank template file or write any code from scratch.

      Post illustration

      Post illustration

      Post illustration

      How to Use AI in MetaEditor MT5: Step-by-Step EA Compilation Walkthrough


      Because MT5 automatically creates the Expert Advisor file for you upon prompt submission, bringing your trading bot to life takes just a few quick clicks:


      Step 1: Open MetaEditor

      In your MT5 terminal top menu, click Tools -> MetaQuotes Language Editor (or press shortcut key F4).

      Post illustration

      Step 2: Open Your Auto-Generated EA File


      In MetaEditor's left-hand Navigator panel, expand the Experts folder. You will see your newly generated EA file (e.g., XAUUSD_AI_PriceAction_EA.mq5) already created and waiting for you. Double-click to open it.

      Post illustration

      Step 3: Compile the Source Code


      Click the green Compile button in the top menu bar (or press F7). Check the Toolbox panel at the bottom of your screen to confirm:

      Result: 0 errors, 0 warnings


      Your Expert Advisor is now fully compiled and visible under Navigator -> Expert Advisors inside MT5, ready to be attached to your live or demo chart

      Post illustration

      💡 Pro Tip for Automated Trading: Once your EA is running, make sure your MT5 connection is fast and your spreads are low. Fast execution ensures your robot enters trades at the exact price the AI intended.

      How to Fix Common MT5 AI Assistant Errors and MetaEditor MQL5 Bugs

      If you run into technical hurdles during setup, follow these quick solutions:


      Why is My MT5 AI Tab Missing?

      1. Update MT5: Ensure your terminal is running the latest build version.
      2. Log into MQL5: Go to Tools -> Options -> Community and log into your free MQL5 account.
      3. Enable Permissions: Go to Tools -> Options -> Expert Advisors and check Allow WebRequest and Allow DLL imports.


      How to Resolve API Authentication Errors in MT5

      1. Check Key Formatting: Ensure no extra spaces were copied before or after your secret key string.
      2. Select Free Tier Model: Confirm you selected Gemini 3.5 Flash-lite.
      3. Check Network Access: Ensure your firewall permits outbound HTTPS requests to Google AI services.


      How to Fix MetaEditor MQL5 Compiler Errors Using AI Debugging

      If clicking Compile (F7) triggers red error icons in MetaEditor, copy the exact error log and submit it back to your AI assistant with this debugging prompt:

      My MetaEditor compiler returned this error: "Error: 'CTrade' - undeclared identifier at line 24" (Example Only)
      Here is my current MQL5 code:[PASTE YOUR CODE HERE]
      Please identify the missing directive or syntax error, fix the code, and provide the updated MQL5 script.

      The AI will identify missing header files (such as #include <Trade\Trade.mqh>) and re-issue clean code ready for compilation.


      Frequently Asked Questions (FAQs)


      Can I run an AI-generated EA on a live trading account immediately?

      We strongly recommend testing any newly generated Expert Advisor on a demo account first or verifying historical performance using the MT5 Strategy Tester before risking real capital.


      Do I need to keep my computer turned on 24/5?

      If you want your EA to trade continuously around the clock without leaving your home computer running, deploy your MT5 platform on a Virtual Private Server (VPS).


      How do I pause or remove an active EA from my chart?

      To pause execution, click the Algo Trading button in the top MT5 toolbar to toggle it off. To remove the EA completely, right-click on the chart, hover over Expert Advisors, and click Remove.


      What’s Next in the MT5 AI Series?

      Now that your Expert Advisor is compiled and ready, the next essential step is validating its historical performance.

      In our final installment, Article 5: Stress-Testing Your AI EA: How to Backtest and Optimize Automated Strategies in MT5.


      We will cover:

      1. Running your EA through historical price data in the MT5 Strategy Tester.
      2. Evaluating key metrics: Profit Factor, Win Rate, and Maximum Drawdown.
      3. Using AI assistants to interpret backtest reports and fine-tune your strategy inputs for live market success.

      Put Your AI Trading Bot to the Test for Free!


      Now that your Expert Advisor is compiled, don't risk capital right away. Deploy your AI-generated EA on an ACY Securities Free MT5 Demo Account to monitor its live chart execution, entry triggers, and trade management in real-time market conditions with zero risk.


      Follow John Rey Cercado for practical AI trading guides, strategy automation, and MT5 tips on LinkedIn.


      Disclaimer:

      Trading Forex, Gold, CFDs, cryptocurrencies, commodities, indices, and other leveraged financial instruments involves a high degree of risk and may not be suitable for all investors or traders. Market conditions can change rapidly, and leveraged trading can result in losses that occur quickly.

      Before trading, carefully consider your investment objectives, level of experience, and risk tolerance. Only trade with capital you can afford to lose and seek independent financial or professional advice where appropriate.

      All market analysis, price forecasts, technical commentary, trading scenarios, educational materials, and opinions presented in this content are provided solely for general informational and educational purposes. They do not constitute financial advice, investment advice, a recommendation, solicitation, or an offer to buy or sell any financial instrument.

      Past performance and historical price movements are not reliable indicators of future results. Any price levels, targets, scenarios, or market outlooks discussed should be viewed as analysis rather than guarantees of future market performance.

      ACY Securities is one of Australia's fastest growing multi-asset online trading providers, offering ultra-low-cost trading, rock-solid execution, technologically superior account management and premium market analysis.

      This content may have been written by a third party. LiquidityFinder makes no representation or warranty and assumes no liability as to the accuracy or completeness of the information provided, nor any loss arising from any investment based on a recommendation, forecast or other information supplies by any third-party. This content is information only, and does not constitute financial, investment or other advice on which you can rely.
      Comments
      Most Recent
      Written By
      profile image formember on LiquidityFinder
      Digital Marketing Specialist, ACY Securities

      John Rey is a Digital Marketing Specialist specializing in MetaTrader 5 (MT5) architecture, algorithmic workflows, and applied artificial intelligence for financial markets. He integrates modern AI models directly with MT5 to automate strategy logic, optimize execution parameters, and backtest systematic setups across forex and multi-asset classes. Drawing on hands-on terminal testing and MQL5 code integration, he develops technical guides and frameworks to help traders implement disciplined, automated execution.

      Daily Newsletter

      LF Daily News

      Daily industry focused newsletter giving you an overview for the financial & finTech industry.

      See All Newsletters
      By clicking "Sign Up" you are agreeing to our Terms of Service and Privacy Policy
      RSS Feeds

      Create a custom RSS Feed

      Select the categories and companies you wish to follow directly to your person rss feed.

      Create Custom RSS Feed

      Related Categories:

      Related Tags:

      #ProviderNews#TradingPlatforms#MarketNews#FinTech

      Related Articles:

      Find The Right Partners for
      Your Trading Business

      Sign up and join over 5,000 professional members who receive personalized news alerts, curated professional connections, and more for free!

      Create Your FREE Account
      Get access to latest news, updates, real-time data, brokerage and trading firm insights and customized information feeds.

      Gold price forecast ahead of NFP: Explore XAUUSD support, resistance and the weekly 50 EMA, with bullish and bearish scenarios and key price targets.

      just now

      Learn how to convert custom price action strategies into fully automated MetaTrader 5 Expert Advisors (EAs) using a simple two-step AI prompt workflow.

      just now

      NAS100 price forecast as the Nasdaq 100 consolidates near key levels. Explore the trend, support and resistance, and potential breakout targets.

      just now

      BTCUSD price forecast for Bitcoin, covering key support and resistance levels, price action, market structure, 50 EMA, and bullish and bearish targets.

      just now

      B2PRIME has appointed Christina Barbash as Commercial Manager, bringing 13 years of financial markets experience from senior roles at PrimeXM, FINKIT Solutions, Point Nine and FXPRIMUS. Barbash will focus on client relationships and supporting B2PRIME's scaling efforts across the global financial landscape.

      just now

      Rob Wing has joined Trading Technologies (TT) as Head of FX Business Development, becoming the latest senior hire supporting TT's expansion in institutional foreign exchange.

      just now

      Fiserv's digital asset platform is now live with financial institution clients, launching Roughrider Coin, Bank of North Dakota's dollar-backed stablecoin. VersaBank issues the coin, Fireblocks provides infrastructure, and transactions run on Solana, enabling more efficient interbank money movement across the state.

      just now

      Robinhood has unveiled Robinhood Agents, Agent Apps, perpetual futures and earnings contracts at HOOD Summit 2026, alongside plans for 24/7 weekend equities trading, OCO orders and higher intraday margin, as the company looks to bring institutional grade trading tools to active retail traders.

      just now

      Exinity has appointed FXTM alum Constantina Georgiadou as Associate VP of Public Relations, based in Limassol. It is the second FXTM executive to return to the Group in three months, following Antonia Droussiotou's appointment as VP of Corporate Communications & CSR. Georgiadou brings fifteen years of industry experience, including nine years at Exness.

      just now

      Sucden Financial has appointed James Wheaton as Deputy Head of Softs. Wheaton joins from Amius Limited and previously served as Assistant Vice President of Softs at StoneX, bringing over ten years of front-office experience in agricultural derivatives across cleared and OTC markets and multiple trading platforms.

      just now
      Feed