No description
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-10-27 01:32:52 +03:00
AI Canvas Editor.mqh Generated by MQL5 Wizard for the article https://www.mql5.com/en/articles/24272 2026-10-27 01:32:52 +03:00
AI Canvas Interact.mqh Generated by MQL5 Wizard for the article https://www.mql5.com/en/articles/24272 2026-10-27 01:32:52 +03:00
AI Canvas Primitives.mqh Generated by MQL5 Wizard for the article https://www.mql5.com/en/articles/24272 2026-10-27 01:32:52 +03:00
AI Canvas Render.mqh Generated by MQL5 Wizard for the article https://www.mql5.com/en/articles/24272 2026-10-27 01:32:52 +03:00
AI Canvas Scrollbar.mqh Generated by MQL5 Wizard for the article https://www.mql5.com/en/articles/24272 2026-10-27 01:32:52 +03:00
AI Canvas Shell.mqh Generated by MQL5 Wizard for the article https://www.mql5.com/en/articles/24272 2026-10-27 01:32:52 +03:00
AI Canvas State.mqh Generated by MQL5 Wizard for the article https://www.mql5.com/en/articles/24272 2026-10-27 01:32:52 +03:00
AI Canvas Theme.mqh Generated by MQL5 Wizard for the article https://www.mql5.com/en/articles/24272 2026-10-27 01:32:52 +03:00
AI EA PART 13.mq5 Generated by MQL5 Wizard for the article https://www.mql5.com/en/articles/24272 2026-10-27 01:32:52 +03:00
AI JSON FILE.mqh Generated by MQL5 Wizard for the article https://www.mql5.com/en/articles/24272 2026-10-27 01:32:52 +03:00
AI Logic.mqh Generated by MQL5 Wizard for the article https://www.mql5.com/en/articles/24272 2026-10-27 01:32:52 +03:00
Article-24272-Building-AI-Powered-Trading-Systems-In-MQL5-Part-13.mqproj Generated by MQL5 Wizard for the article https://www.mql5.com/en/articles/24272 2026-10-27 01:32:52 +03:00
README.md Generated by MQL5 Wizard for the article https://www.mql5.com/en/articles/24272 2026-10-27 01:32:52 +03:00

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.

Article preview

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

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

  1. 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.
  1. 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.
  1. 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.
  1. Parse arguments safely
  • Typed JSON helper readers are used so missing or malformed fields fall back safely rather than breaking execution logic.
  1. 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.
  1. 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.
  1. 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.
  1. Execute validated actions
  • The article shows a detailed place_order execution 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.
  1. 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.
  1. 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.
  1. 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.
  1. 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.
  1. 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.mqh
  • AI Canvas Primitives.mqh
  • AI JSON FILE.mqh
  • AI Canvas State.mqh
  • AI Canvas Scrollbar.mqh
  • AI Canvas Editor.mqh
  • AI Canvas Render.mqh
  • AI Logic.mqh
  • AI Canvas Interact.mqh
  • AI Canvas Shell.mqh
  • AI EA PART 13.mq5
  • MQL5.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