- MQL5 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| AI Canvas Editor.mqh | ||
| AI Canvas Interact.mqh | ||
| AI Canvas Primitives.mqh | ||
| AI Canvas Render.mqh | ||
| AI Canvas Scrollbar.mqh | ||
| AI Canvas Shell.mqh | ||
| AI Canvas State.mqh | ||
| AI Canvas Theme.mqh | ||
| AI EA PART 13.mq5 | ||
| AI JSON FILE.mqh | ||
| AI Logic.mqh | ||
| Article-24272-Building-AI-Powered-Trading-Systems-In-MQL5-Part-13.mqproj | ||
| README.md | ||
Article-24272-Building-AI-Powered-Trading-Systems-In-MQL5-Part-13
This repository is an article-derived reference project based on the original MQL5 article. It does not claim to reproduce the full original source code unless files are explicitly attached.
Overview
This repository is derived from the MQL5 article “Building AI-Powered Trading Systems in MQL5 (Part 13): Letting the Assistant Execute Trades Behind an Approval Card”. The article extends an AI-enabled MetaTrader 5 assistant from read-only analysis into controlled trade execution.
The core idea is to let an AI assistant propose account-changing actions such as placing, modifying, closing, or deleting trades, while keeping the final decision in human hands through an approval card. The article also covers validation, broker volume normalization, ownership scoping, queued action handling, paused tool-loop resumption, and a non-trading chart drawing tool.
Original Article
- Article ID: 24272
- Title: Building AI-Powered Trading Systems in MQL5 (Part 13): Letting the Assistant Execute Trades Behind an Approval Card
- Author: Allan Munene Mutiiria
- Publication date: Not available
- Categories: Integration, Statistics
- Article URL: https://www.mql5.com/en/articles/24272
- Author URL: https://www.mql5.com/en/users/29210372
Repository Purpose
This repository exists as a reference implementation and study companion for the article’s architecture.
A reader can use it to understand how an MQL5-based AI assistant can:
- expose trading actions as callable tools,
- distinguish read-only tools from account-changing tools,
- validate proposed actions before execution,
- gate execution behind explicit human approval,
- resume an interrupted AI tool-call loop after approval or rejection,
- scope bulk actions to allowed trade ownership groups.
Because the project is article-derived, it is most useful for learning the design pattern and reconstructing or reviewing the workflow described by the author.
Key Concepts
- Integration
- Statistics
- AI-assisted trading workflows
- Human-in-the-loop trade approval
- Tool-based action execution
- Trade validation and safety limits
- Broker lot normalization
- Position and order ownership scoping
- Paused and resumed tool-call loops
- Chart annotation tools
Algorithm / Architecture Summary
- Separate tool families
- The assistant exposes read-only tools and action tools.
- Read-only tools run immediately.
- Action tools are treated as proposals, not direct commands.
- Advertise actions conditionally
- Action tools are only included when the relevant input switch is enabled.
- The article explicitly describes tools for placing, modifying, closing, and deleting trades, plus a chart drawing tool.
- Classify whether a tool changes the account
- A predicate determines whether a tool is an execution-sensitive action.
- Account-changing tools are approval-gated.
- The chart drawing tool is intentionally excluded from that gate because it does not affect the account.
- Parse arguments safely
- Typed JSON helper readers are used so missing or malformed fields fall back safely rather than breaking execution logic.
- Validate every approved action
- The safety gate checks whether actions are globally enabled.
- It can restrict actions to the chart symbol.
- It verifies symbol availability.
- It enforces per-action lot limits.
- It optionally enforces an open-position ceiling for exposure-adding actions.
- Normalize requested volume to broker constraints
- Requested lots are snapped to the broker’s volume step.
- Volume is clamped to symbol minimum and maximum limits.
- Validation is performed again after normalization because rounding can change the effective size.
- Scope actions by ownership
- Trades are grouped by origin, such as this EA, manual trades, or other EAs.
- Bulk actions can then be constrained to the ownership scope allowed by the user or requested in context.
- Execute validated actions
- The article shows a detailed
place_orderexecution flow: - resolve symbol and arguments,
- validate direction and order kind,
- run the safety gate,
- normalize and revalidate lots,
- map request parameters to order types,
- convert stop-loss and take-profit point distances into absolute price levels if needed,
- reject invalid stop or target placement,
- dispatch to market or pending order execution,
- return a plain-text result.
- Pause the AI tool loop when approval is required
- If the model proposes one or more action tools, the loop does not execute them immediately.
- Instead, it parks the round, stores pending tool-call data, and raises an approval card for the first unresolved action.
- Present one approval card at a time
- The card includes a fixed header, tool name, and human-readable action description.
- This helps ensure that the user approves a concrete operation rather than a raw function call.
- Resolve approval or rejection
- Approving executes the parked action.
- Rejecting records that it was refused and not executed.
- The system then either advances to the next pending action card or resumes the paused loop once all pending actions are resolved.
- Resume the interrupted conversation
- Tool results are inserted back into the parked message flow.
- The shared tool loop restarts from the next round so the model can react and finish its response.
- Support non-account chart drawing inline
- A drawing tool can annotate the chart with a level or label.
- Since it does not affect account state, it executes immediately without approval.
Mentioned or Attached Files
Explicitly attached files
The article attachment table explicitly lists the following files:
AI Canvas Theme.mqhAI Canvas Primitives.mqhAI JSON FILE.mqhAI Canvas State.mqhAI Canvas Scrollbar.mqhAI Canvas Editor.mqhAI Canvas Render.mqhAI Logic.mqhAI Canvas Interact.mqhAI Canvas Shell.mqhAI EA PART 13.mq5MQL5.zip
ZIP attachment
- An attached ZIP archive is available:
https://www.mql5.com/en/articles/download/24272_277665.zip?s=e804f89dc941c5f8f80814b2dc88dd3a786d63f5787df75cb18d170ddf1a59d4&t=1793036164
Statistics
- Word count: Not available
- Reading time: Not available
- Image count: Not available
- Code block count: Not available
- File count: Not available
Tags
- mql5
- metatrader-5
- integration
- statistics
- difficulty-advanced
Difficulty
Advanced
Reason: the article combines MQL5 trade execution, JSON-based tool argument parsing, approval-gated state management, queued action handling, UI interaction, and conversation loop resumption for an AI-assisted trading interface.
Limitations
- This repository is based on an article-derived reconstruction and reference interpretation.
- Full behavior depends on the files actually attached or otherwise provided by the author.
- Although the article includes an attachment list and ZIP archive, this README does not claim independent verification of every implementation detail beyond what is described in the processed input.
- The project should not be assumed production-ready solely from the article description.
- Safe use in live trading would require additional testing, review, and risk controls beyond the article summary.
Reference
- Original article: https://www.mql5.com/en/articles/24272
- Author profile: https://www.mql5.com/en/users/29210372
