Skip to main content

What Did the AI Do? Review Connector Activity in MT5 History

Auditing AI trading agents requires moving beyond basic balance charts. Learn how to dissect MT5 Orders, Deals, and Journal logs to uncover execution drag.

Daniel Abramovich

15 min read

What Did the AI Do? Review Connector Activity in MT5 History Watch the video

This article

8sections 15min

  1. 01 What You'll Learn, minute 2, about 1 min
  2. 02 How Do Orders, Deals, and Positions Differ in MT5 History?, minute 2, about 2 minTo accurately audit an AI connector, you must understand the three-tier execution hierarchy: Orders represent the AI's intent, Deals record…
  3. 03 How Do You Identify AI Connector Trades Using Magic Numbers and Comments?, minute 4, about 2 minYou can identify specific AI connector trades by filtering your MT5 History for distinct 32-bit integer magic numbers and parsing the…
  4. 04 How Do You Audit AI Order Modifications and Journal Error Codes?, minute 6, about 2 minAuditing AI order modifications requires decoding server return codes (retcodes) in the MT5 Experts and Journal tabs to verify if…
  5. 05 Exporting and Filtering MT5 History for AI Performance Post-Mortems, minute 8, about 2 minTo conduct an AI performance post-mortem, filter your terminal history by custom periods and magic numbers, then right-click to export the…
  6. 06 How Do Account Commissions and Spreads Distort AI Strategy Audits?, minute 10, about 3 minAccount commissions and spread markups distort AI strategy audits by masking the execution drag that turns a gross-profitable backtest into…
  7. 07 Conclusion, minute 13, about 1 minAuditing AI trade connectors in MetaTrader 5 requires moving beyond high-level balance charts into the granular mechanics of Orders, Deals…
  8. 08 Frequently Asked Questions, minute 14, about 1 minA magic number is a unique 32-bit integer assigned to trades executed by an Expert Advisor (EA) or algorithmic connector. It allows traders…

Listen to this article

Also on Apple Podcasts

Listen (audio)

To review AI connector activity in MT5 History, switch the History tab to 'Deals' or 'Orders' mode, isolate your agent using its unique 32-bit magic number, and inspect the 31-character comment string for agent execution tags. Cross-reference deal timestamps with the MT5 Experts log to verify retcode 10009 fills against intended prompt parameters.

You deploy a new Python-based AI agent, go to sleep, and wake up to a string of unexpected losses. The default "Positions" tab just shows the bloody aftermath, but it won't tell you why the bot failed. Did the Large Language Model (LLM) hallucinate? Did the broker reject your orders due to volatility? Or did a dynamic trailing stop trigger too early? Here is exactly how to dissect your MT5 History to find out.

What You'll Learn

How Do Orders, Deals, and Positions Differ in MT5 History?

To accurately audit an AI connector, you must understand the three-tier execution hierarchy: Orders represent the AI's intent, Deals record the actual broker fills, and Positions represent your net market exposure.

The MT5 Execution Lifecycle: Orders vs. Deals vs. Positions

When your AI agent decides to buy EUR/USD, it sends an Order to the server. If the broker accepts it, that order translates into a Deal (a fill). This deal then opens or modifies a Position.

Intermediate algorithmic traders often make the mistake of only monitoring the Positions tab. This blinds you to critical execution anomalies. For example, if your AI sends a 1-lot buy order, but liquidity is thin, the broker might fill 0.5 lots at 1.0850 and 0.5 lots at 1.0852. The Positions tab will simply show a 1-lot position at an average price of 1.0851, completely hiding the slippage and split fills that occurred under the hood.

Configuring the Terminal History View for Forensic Auditing

To reconstruct the lifecycle of an autonomous trade, you need to change your terminal view. Right-click anywhere inside the MT5 History tab. You will see options to toggle between 'Positions', 'Deals', 'Orders', and 'Orders & Deals'.

An architectural flowchart illustrating the MT5 trade lifecycle, showing how an incoming Order triggers one or more execution
The MT5 execution hierarchy shows how an order leads to individual deals that aggregate into a net position.

Switching to 'Orders & Deals' provides the complete forensic timeline. You will see exactly when the AI requested the trade (the Order) and exactly when and how the broker executed it (the Deal).

Pro Tip: If you are using a netting account, multiple connector fills for the same symbol are aggregated into a single position ticket. If you are using a hedging account, each fill is isolated into its own position ticket. Always check which account type your AI is trading on before customizing an MT5 EA without coding.

How Do You Identify AI Connector Trades Using Magic Numbers and Comments?

You can identify specific AI connector trades by filtering your MT5 History for distinct 32-bit integer magic numbers and parsing the 31-character comment strings for agent metadata.

Using Magic Numbers as Agent Fingerprints

In MT5, every trade carries an EA_MAGIC number. This acts as a forensic identifier. Manual discretionary clicks are always assigned a magic number of 0. When connecting a broker connector or community MCP server to your MT5 login, you must assign a unique magic number (for illustration, 999111) to your AI agent. This allows you to instantly separate machine execution from human intervention in the history logs.

Deciphering the 31-Character MT5 Comment Limit

The MT5 comment field is notoriously strict. You only have 31 characters to stamp your metadata. Because the context window capacity for MQL5 AI provider interactions in MT5 terminal updates is now 500,000 tokens, modern trade connectors must aggressively compress their routing signatures.

A well-architected AI connector will use this space to log the agent ID, prompt hash, or model version.

Example: An optimized comment might look like GPT4o_B3_v1.2, which uses 13 of the 31 available characters, leaving room for a short prompt ID.

Isolating LLM Prompts from Broker Overwrites

Brokers often overwrite the comment field when a trade is modified or closed. If a trade hits its stop-loss, the broker might append [sl]. If it rolls over the weekend, you might see swap tags. To ensure your AI's metadata survives, the connector must record essential routing signatures in the initial order comments before deals are finalized.

To view this data rapidly, right-click the headers in your MT5 History tab and ensure the "Magic" and "Comment" columns are checked. This side-by-side visual filtering is critical when auditing complex automated portfolios.

How Do You Audit AI Order Modifications and Journal Error Codes?

Auditing AI order modifications requires decoding server return codes (retcodes) in the MT5 Experts and Journal tabs to verify if adjustments to stop losses, take profits, or pending orders were accepted or rejected.

Tracking Stop Loss, Take Profit, and Trailing Stop Adjustments

Autonomous agents often manage risk dynamically, adjusting trailing stops as a trade moves into profit. These micro-adjustments are executed via the TRADE_ACTION_SLTP command. While the Positions tab only shows the final stop-loss level, the 'Orders' view in your History tab will log every single modification request. If your bot is updating its stop-loss ten times a minute, your history will fill with modification orders, which is a key indicator of hyperactive agent logic.

Cross-Referencing Experts and Journal Logs with Return Codes

When an AI connector sends an order, the broker's server responds with a retcode. You must monitor the Experts and Journal tabs to decode these responses:

  • 10009 TRADE_RETCODE_DONE: The order was executed successfully.
A zoomed-in interface capture of the MT5 'Journal' and 'Experts' tabs featuring timestamped order modification requests
MT5 journal logs show trailing stop modifications, execution confirmations, and server rejection return codes.
  • 10004 TRADE_RETCODE_REQUOTE: The price changed, and the broker issued a requote.
  • 10006 TRADE_RETCODE_REJECT: The request was rejected (often due to off quotes).
  • 10016 TRADE_RETCODE_INVALID_STOPS: The AI attempted to place a stop-loss too close to the current market price.

By matching the millisecond server timestamps in the MT5 Journal against your AI's internal decision logs (such as Python terminal outputs), you can evaluate execution latency. If the AI decides to buy at 10:00:00.000, but the 10009 retcode arrives at 10:00:00.400, you have 400 milliseconds of latency to address.

Auditing Cancelled and Expired Autonomous Orders

Not all AI decisions result in a trade. If your bot places a pending limit order but the market never reaches that price, the order will eventually be purged. Look for ORDER_STATE_CANCELED or EXPIRED in your history. If you see hundreds of expired orders, your AI connector is likely failing to catch market moves due to unrealistically tight limit offsets, a common issue when fading the 4-hour 30-minute range.

Exporting and Filtering MT5 History for AI Performance Post-Mortems

To conduct an AI performance post-mortem, filter your terminal history by custom periods and magic numbers, then right-click to export the data as an Open XML or HTML report for external analysis.

Filtering Terminal History by Custom Periods and Magic Numbers

Before exporting, clean up your data view. Right-click in the History tab, select 'Custom Period', and set the exact date bounds of your AI's deployment. Next, use the search bar or column sorting to isolate the specific magic number of the connector you are auditing.

Once filtered, right-click again and select 'Report > Open XML'. This generates a structured data file that is vastly superior to a basic HTML printout for quantitative analysis.

Bridging MT5 Execution Data with LLM Prompt Logs

Once you have your XML or CSV history, you can import it into a Python data pipeline using pandas. The goal is to align the MT5 deal ticket numbers with your connector's prompt logs. This allows you to see exactly which LLM prompt generated which financial outcome.

This is where you calculate real execution slippage. By comparing the requested order price (ORDER_PRICE_OPEN) against the executed deal price (DEAL_PRICE), you can quantify the exact cost of broker latency.

Auditing Trade Frequency During Volatility

You must also audit trade frequency and duration metrics. Did the AI model adhere to its intended risk boundaries, or did it engage in hallucinated overtrading during high-volatility news events? Cross-referencing your XML report with China's data calendar for FX traders or FOMC releases will quickly highlight if your bot is recklessly executing during liquidity vacuums.

How Do Account Commissions and Spreads Distort AI Strategy Audits?

Account commissions and spread markups distort AI strategy audits by masking the execution drag that turns a gross-profitable backtest into a net-negative live reality.

Gross Edge vs. Net Reality in Algorithmic Performance

Looking only at the gross P&L in MT5 History is dangerous for algorithmic traders. An AI agent might capture 2 pips of gross profit per trade, which looks fantastic on a chart. However, if the broker charges a wide spread and heavy commissions, those 2 pips of edge are instantly erased. To calculate your true net expectancy per lot, you must analyze the 'Commission', 'Fee', and 'Swap' columns in your MT5 Deals history alongside your gross profit.

A comparison bar chart and ledger breakdown contrasting raw gross profits against net realized profits after accounting
A chart and MT5 ledger break down gross strategy edge against realized net returns after accounting for execution friction.

Matching Connector Style to NX Flex Dials

Because different AI strategies require different cost structures, aligning your bot with the right account terms is critical. This is where the NX Flex account model becomes highly relevant. It offers 72 combinations, allowing you to choose between 6 commission tiers ($0 to $9 per lot round-turn) and 6 spread markups (0.0 raw to 2.5 pips).

If you are running a high-frequency scalping agent, execution friction is your biggest enemy. You would likely configure your NX Flex account for the lowest possible spread, selecting a 0.0 pip markup (the raw market spread still applies) paired with a fixed commission. Conversely, if your AI is a low-frequency swing model that targets 100-pip moves, you might prefer a $0 commission setup with a slightly wider spread markup to eliminate ticket fees entirely.

Auditing Swap Costs on Multi-Day AI Swing Positions

Overnight holding costs can quietly destroy a swing trading bot's profitability. When auditing your history, check the 'Swap' column for multi-day holds.

If your strategy holds trades for several days, you can utilize the NX Flex swap-free switch. Available on every combination (starting from a $500 minimum net deposit up to the $10,000 tier), this setting provides up to 14 days swap-free per position. If a position stays open longer, the swap is charged for every night it was open, then daily until it closes. For clients who cannot pay or receive swap, an AI swing hold closed within those 14 days incurs no overnight financing.

Conclusion

Auditing AI trade connectors in MetaTrader 5 requires moving beyond high-level balance charts into the granular mechanics of Orders, Deals, and Journal logs. By isolating bot activity with distinct 32-bit magic numbers, deciphering 31-character comment tags, and matching server retcodes (such as 10009 TRADE_RETCODE_DONE) against agent decision timestamps, intermediate traders can identify whether poor performance stems from prompt logic errors, broker latency, or excessive execution drag.

Furthermore, aligning your strategy's frequency with your account structure—such as configuring NX Flex's customizable commission ($0 to $9 per lot) and spread markup (from 0.0 pips) dials—ensures your algorithmic edge is not erased by execution friction. Take control of your automated systems: export your latest MT5 Deals report today, verify your agent's actual fill prices against its intended orders, and eliminate execution blind spots before deploying increased capital.

Frequently Asked Questions

What is an MT5 magic number?

A magic number is a unique 32-bit integer assigned to trades executed by an Expert Advisor (EA) or algorithmic connector. It allows traders to filter and track the performance of specific automated strategies separately from manual trades (which always have a magic number of 0).

How do I view MT5 deal history instead of positions?

Right-click anywhere inside the MT5 History tab and select "Deals" or "Orders & Deals" from the context menu. This changes the view from aggregated net positions to the individual execution fills and order requests made by your trading agent.

What does retcode 10009 mean in MT5?

Retcode 10009 (TRADE_RETCODE_DONE) is the MetaTrader 5 server response indicating that an order request was successfully completed and filled by the broker. Monitoring for this code in the Journal log confirms your AI connector's trade was accepted.

How long are algorithmic trade records kept?

Under MiFID II regulations, algorithmic and automated order records must be retained by financial institutions for a minimum of 5 years. For retail traders, exporting your MT5 history regularly ensures you maintain your own long-term performance data.

Trading CFDs involves risk of loss; better terms do not change market risk.

End of article

General information and education, never investment advice.

CFDs are complex, leveraged instruments with a high risk of losing money rapidly. 64% of retail investor accounts lose money trading CFDs with this provider.

Written by Daniel Abramovich.

Crypto-Forex Analyst

All articles by Daniel
Publisher
FXNX Global Markets Ltd
Company
Saint Lucia 2025-00128
Published
October 16, 2026

Next step

Now practise it,
on a demo.

Open an account and practise with virtual money on live prices. No deposit, no ID.

$10,000
Demo balance, ready on your first visit. Or pick $1,000 or $100,000.

Demo results don't predict live results.