AI in MetaTrader 5: From Market Analysis to Trading Strategy Testing

 

Artificial intelligence in MetaTrader 5 is more than just a chatbot you can ask about the markets. With support for the Model Context Protocol (MCP), an AI agent can work directly with the data and functionality of the trading platform: analyze market prices and trading history, examine open positions, work with charts, test and optimize Expert Advisors, and even send trading orders to a broker.

In this video, we take an in-depth look at how AI integration works in MetaTrader 5, how to get started with the built-in assistant, and what practical tasks you can delegate to it.


How MCP Works in MetaTrader 5

The Model Context Protocol is an open standard that gives AI applications a unified way to interact with external data sources and tools. In MetaTrader 5, it serves as a bridge between the AI agent and the trading platform.

Without this integration, users have to gather market data manually, copy account information, share screenshots, and switch between different applications. MCP allows the agent to retrieve the context it needs directly from MetaTrader 5 and use the platform's available functionality to complete a given task.

Start with the Built-in AI Assistant

The easiest way to explore these new capabilities is to use the free AI Assistant built directly into MetaTrader 5. No initial configuration is required: simply install the latest version of the platform and sign in to your MQL5.community account.

You can then open the AI Assistant and give it your first task. For example, ask, "What can you do?" and the agent will show you the capabilities available to it.

The real advantage of an AI agent is not performing simple actions that a user can complete in a few clicks. Its value becomes much more apparent with multi-step tasks that require collecting large amounts of data, analyzing it, applying specific conditions, and producing a specific result.

Analyzing Positions and Trading History

The AI Assistant can use trading account data to perform comprehensive analysis. For example, you can ask it to group all open positions, calculate Buy and Sell volumes, show the current profit or loss, and identify exposure concentrated in particular instruments.

You can then continue the conversation with a more specific scenario: for example, ask the assistant to assess which open positions are likely to be most affected by a 1% strengthening of the US dollar.

Another use case is trading history analysis. The AI Assistant can examine trades over a selected period and break down the results by symbol, trade direction, day of the week, or position holding time. This makes it easier to identify recurring patterns without manually processing the trading history.

You can take this a step further by asking the agent to analyze past trades and identify recurring entry and exit conditions, as well as trend and volatility characteristics associated with successful trades. Based on these findings, the assistant can formulate a structured hypothesis about the trading approach.

Market Analysis Directly in MetaTrader 5

The AI agent can work with ticks, bars, charts, volumes, available symbols, and other data provided by the platform. For example, you can ask it to analyze EURUSD on the H1 and H4 timeframes, determine the trend and volatility, and identify support and resistance levels. The agent will retrieve the required data for both timeframes, perform the analysis, and prepare a summary of its findings.

For a broader market overview, you can ask the AI Assistant to scan the instruments from the Market Watch, find symbols trading near their seven-day highs and lows, rank them by volatility, and highlight the most significant price movements.

When access to web resources is enabled, the agent can also supplement MetaTrader 5 data with external context, such as news, economic events, and publicly available market statistics.

Working with Charts and the Trading Environment

The AI Assistant can do more than analyze information — it can also prepare your MetaTrader 5 workspace. With a single command, you can open charts for the required instruments on a specified timeframe and apply a saved template. Similarly, the agent can manage the contents of Market Watch—for example, keeping only instruments with open positions or recent trades and sorting them according to a specified criterion.

Instead of performing a long sequence of routine operations, the user simply describes the desired end result, and the agent carries out the necessary steps itself.

Trading Operations Through AI

MCP gives AI agents access to trading operations. They can open, close, and modify orders and positions.

The most interesting possibilities are complex, multi-step scenarios. For example, you can ask the agent to evaluate the currency pairs available in Market Watch using MACD, RSI, and ATR, identify the instruments that best match specified conditions, and execute the corresponding trading operations.

Another example is automatically setting Stop Loss and Take Profit levels for existing positions and pending orders based on each instrument's current volatility and a specified risk-to-potential-reward ratio.

Testing and Optimizing Trading Robots

One of the most powerful applications of agentic AI in MetaTrader 5 is working with the Strategy Tester. Testing an Expert Advisor normally involves a series of steps: configuring the parameters, running the test, waiting for the results, reviewing the report, adjusting the conditions, and repeating the process. Now, much of this work can be delegated to the AI Assistant.

For example, you can ask it to test an Expert Advisor on several currency pairs over the past two years using specified parameters, compare the results, and provide its conclusions. The agent will run the required tests sequentially and analyze the results.

The same approach can be applied to optimization. You can specify which Expert Advisor parameters need to be optimized and define the optimization criterion — for example, prioritizing lower drawdown over maximum net profit. The AI Assistant can coordinate this process and analyze the resulting data.

An AI Agent Instead of a Conventional Chatbot

The key advantage of AI integration in MetaTrader 5 is access to context and the ability to take action. The agent can access the platform data it needs and use its tools to solve complex, multi-step tasks.

At the same time, MetaTrader 5 allows users to control the AI Assistant's access to platform functions and data, including sensitive operations. You decide which capabilities are available to the agent.

Try the free AI Assistant directly in MetaTrader 5. Start with a simple task, then move on to more complex scenarios: analyze markets and trading history, configure your workspace, and test and optimize Expert Advisors.

Important: AI-generated results may contain errors, be incomplete, or be unsuitable for a particular situation. They do not constitute financial, investment, or trading advice. Always verify AI-generated results and actions before using them, and make your own trading decisions.
 
MetaQuotes:
You decide which capabilities are available to the agent.

Great video. Thank you.

Are there any potential security risks when using "All requests" instead of "GET requests only" with MQL5.community/MQL5 Lite?

Edit

Prompt: Are there any potential security risks of setting you to "All requests" instead of "GET requests only"?

Response: Good question. Yes — switching from "GET requests only" to "All requests" materially increases the risk surface. Here's the breakdown.

What the setting actually controls

This setting is an HTTP-method whitelist for the requests I'm allowed to make against your terminal/workspace connection:

Setting Allowed methods What it permits
GET requests only Read-only Market data, history, quotes, calendar, account info, looking at positions/orders — nothing changes state
All requests GET, POST, PUT, PATCH, DELETE File writes, compilation, Strategy Tester runs, service start/stop, and placing, modifying, or closing real orders

The real risks of "All requests"

  1. Real money can move. This is the big one. With GET-only, an erroneous action can only look at things. With All requests, trade tools (market orders, pending orders, close/modify positions) become part of my reachable surface. Those tools are guarded by explicit-instruction confirmation, but that's a human-in-the-loop safeguard, not a technical barrier.

  2. Prompt injection becomes dangerous. Files, logs, web articles, JSON payloads, and forum content can contain instructions written by third parties. I treat such content as data, not commands — but the blast radius of a successful injection is far smaller when write/trade endpoints are blocked. With All requests, injected text could theoretically be steered toward state-changing operations.

  3. Accidental state changes. A misdescribed request, a wrong file path in a broad instruction, or a misformatted parameter could edit the wrong file, delete something, or start an unintended tester run / service — even with my best intentions.

  4. Compromise via the session itself. If your session or credentials are shared, exposed, or hijacked, All requests turns a read-only spy into a write-enabled actor on files, compiler, tester, and account.

  5. Blast radius on files. Write access includes create/edit/delete in the allowed workspace roots and compiled artifacts — mistakes here are recoverable but can disrupt a working project.

What GET-only gives up (and why that's fine by default)

  • I can't write or compile files, run backtests, manage services, or trade.
  • So tasks like "create this EA and compile it" require All requests to function.

Recommendation

  • Keep "GET requests only" by default, especially if the connected account holds real funds.
  • Switch to All requests only when:
    • you're on a demo or secure test account,
    • you explicitly want file/compile/tester/trade capabilities, and
    • you accept that the session then has write+execute reach.

Defense-in-depth notes

  • Even with All requests, the trade tools require an explicit user instruction naming symbol/volume/tickets, and I still refresh positions/orders before acting — that's a deliberate guardrail, not an absolute one.
  • The safest practical posture: run your read-only analysis under GET-only, and use a demo account + All requests for development, compiling, and backtesting.

Net: my own behavior doesn't change based on the setting — but the damage a mistake, an injection, or a compromised session could do scales dramatically with All requests. That's the risk.