Article-23893-Building-AIPo.../README.md

194 lines
7.6 KiB
Markdown

# Article-23893-Building-AIPowered-Trading-Systems-MQL5-Part-12
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](https://c.mql5.com/2/240/Screenshot_2026-08-05_192531_1200x628.jpg)
## Overview
This repository documents and references the MQL5 article **“Building AI-Powered Trading Systems in MQL5 (Part 12): Giving the Assistant Chart Vision and Tool Access.”** It is an article-derived MQL5 project focused on extending an AI trading assistant with two major capabilities:
- chart vision through screenshots and image attachments
- tool access for live terminal, market, account, and calendar data
The article describes how an Expert Advisor-based assistant can move beyond plain text chat by sending chart images to a multimodal model and by allowing the model to request specific live data through a controlled tool-calling workflow.
## Original Article
- **Article ID:** 23893
- **Title:** Building AI-Powered Trading Systems in MQL5 (Part 12): Giving the Assistant Chart Vision and Tool Access
- **Author:** Allan Munene Mutiiria
- **Publication date:** Not available
- **Categories:** Trading Systems, Integration, Expert Advisors, Statistics
- **Article URL:** https://www.mql5.com/en/articles/23893
- **Author URL:** https://www.mql5.com/en/users/29210372
## Repository Purpose
This repository exists to preserve the structure and technical ideas presented in the original article in a reusable repository format.
A reader can use this repository to:
- understand how chart screenshots can be captured and sent to an AI model from MQL5
- study a multimodal message flow that combines text and image content
- learn how tool-calling can expose controlled terminal data to an assistant
- reuse the article’s architectural ideas for MQL5 dashboard panels, image rendering, and request orchestration
- inspect the project file layout explicitly listed in the article attachments
Because this repository is article-derived, its completeness depends on the files actually attached or otherwise provided by the author.
## Key Concepts
- Trading Systems
- Integration
- Expert Advisors
- Statistics
- Multimodal AI messaging
- Chart screenshot capture
- Base64 image encoding
- Tool calling
- Live market context injection
- Chart object inspection
- Trade history summarization
- Economic calendar access
- Canvas-based UI rendering
## Algorithm / Architecture Summary
The article presents a combined UI, image-processing, and AI-integration workflow for an MQL5 assistant.
1. **Capture chart imagery**
- The assistant captures the current chart as a screenshot.
- The panel UI is temporarily hidden so the screenshot contains only the chart.
- PNG is used for request payload/archive purposes, while BMP is used for local panel display.
2. **Encode the image for transport**
- The PNG bytes are converted to base64.
- Line breaks are removed so the encoded image can be embedded safely into JSON.
3. **Stage the attachment before sending**
- A pending attachment state stores:
- image base name
- width and height
- base64 payload
- The user can attach or remove the staged screenshot before sending the message.
4. **Build multimodal request content**
- The outgoing message becomes a content array rather than plain text.
- It includes:
- a text item for the prompt
- an image item using a base64 data URL
- This allows the model to reason about actual chart visuals instead of typed descriptions only.
5. **Render image previews inside the panel**
- The local BMP copy is decoded for display.
- Thumbnails are cached using a bounded cache strategy.
- Inline thumbnails and a compose-chip preview are drawn into the dashboard.
6. **Open a full-image viewer**
- Clicking a thumbnail opens a native-resolution viewer.
- The viewer supports:
- full-resolution image display
- vertical and horizontal scrolling
- grab-pan interaction
- close controls
- This is handled through dedicated viewer state and interaction routing.
7. **Clean up image files**
- Stored chat history references image markers.
- When a chat is deleted, related PNG/BMP files are also deleted.
8. **Define callable tools for the model**
- The article defines a JSON tool menu for the model with functions for:
- indicator retrieval
- open positions
- chart objects
- trade history
- economic calendar events
9. **Dispatch tool calls inside MQL5**
- Tool-call arguments are parsed from JSON.
- A dispatcher routes the request to the appropriate MQL5 function.
- Tool results are returned as readable text rather than raw binary or complex structures.
10. **Attach automatic market context**
- A live market snapshot can be appended automatically to each message.
- This context includes current symbol/timeframe details, prices, recent candles, positions, and account status.
11. **Run a tool-call loop during send**
- The assistant sends the request with optional vision content and tool definitions.
- If the model responds with tool calls:
- the terminal executes each requested tool
- tool outputs are appended to the conversation
- the request loop continues until the model returns final text or the round limit is reached
Overall, the architecture combines a chart-facing UI layer, an image handling pipeline, a tool exposure layer, and a controlled model interaction loop.
## Mentioned or Attached Files
### Explicitly attached files
The article explicitly lists these attached 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 12.mq5`
- `MQL5.zip`
### ZIP attachment
An attached ZIP archive is available in the processed input:
- `https://www.mql5.com/en/articles/download/23893_271278.zip?s=0cee6d030d20a2b0f90ab6d2f4d447bafd07f9c216585854de7d946f8ee1b136&t=1790945720`
### Files mentioned in text
The article also mentions internal image storage outputs used by the implementation:
- PNG screenshot copies
- BMP screenshot copies
## 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
- trading-systems
- integration
- expert-advisors
- statistics
- difficulty-advanced
## Difficulty
**Advanced**
Reason: the article combines MQL5 UI rendering, chart screenshot handling, base64 encoding, JSON request construction, multimodal AI messaging, tool schema design, live terminal data extraction, and iterative tool-call orchestration.
## Limitations
- This repository is derived from the article and may not reproduce the full original project unless the attached files are included here.
- The implementation depends on files actually attached or provided by the author.
- The README is based on article metadata and article content analysis, not on verification of every attached source file inside the ZIP archive.
- Internal ZIP contents were described in the article, but repository completeness still depends on what was actually extracted and committed.
- The project should not be assumed production-ready unless explicitly stated by the original author, which was not established in the processed input.
## Reference
- Original article: https://www.mql5.com/en/articles/23893
- Author profile: https://www.mql5.com/en/users/29210372