Discussing the article: "Building AI-Powered Trading Systems in MQL5 (Part 9): Creating an AI Signal Dispatcher"

 

Check out the new article: Building AI-Powered Trading Systems in MQL5 (Part 9): Creating an AI Signal Dispatcher.

We turn the MQL5 AI trading assistant into a dispatch-driven system that routes seven trading actions through a single central dispatcher. A line-based key-value protocol constrains AI output, while each action maps to market or pending orders and instrument-aware stop levels. A canvas-based UI with a custom prompt editor and pixel-accurate text fitting makes signals consistent, auditable, and ready to render on the chart.

A dispatch-driven action system is a way of organizing several distinct user-triggered operations behind a single routing layer. Each operation carries a stable integer identifier, a label, an icon, and a handler. A central dispatcher receives an identifier and calls the matching handler. Adding a new action means adding a row to a table and a case to a switch — not editing five separate files. This is the structural answer to the pain of free-form chat: instead of forcing every analysis through one box, each operation gets its own data preparation, prompt template, parsing logic, and chart drawing, while the user sees a uniform set of buttons.

The seven actions we expose cover a spectrum of analytical scope. Get Chart Data dumps recent bars and indicators for follow-up questions. Twin Bars checks the last two closed bars and emits a buy, sell, or none decision when they share direction. Quick Scalp scans the last ten bars for candlestick patterns. Daily Signal pulls today's closed hourly bars and assesses directional momentum. Trend Read analyzes the last thirty bars and returns trend direction with two anchor points for a trendline. Key Level scans the last fifty bars for one significant horizontal level and indicates whether to bounce-trade or break-trade it. Clear Drawings wipes every chart object the program drew. Each AI-driven action follows a line-based key-value output protocol — one fact per line, no JSON, no nested braces — paired with an explicit bar-direction preamble that defines bullish as close greater than open and orders bars from newest to oldest, so the AI never has to guess our conventions.

Trade execution maps cleanly onto the protocol. Twin Bars, Quick Scalp, and Daily Signal place market orders at the current price. Key Level places a pending order whose type is hardcoded from a two-by-two matrix: support and bounce takes a buy limit, support and break takes a sell stop, resistance and bounce takes a sell limit, resistance and break takes a buy stop. The AI picks the level type and bias; the dispatcher picks the order type. Stop and target distances use a buffer computed as a fraction of recent bar range, so the same code works on any symbol without per-instrument tuning. Here is an illustration of our objectives.

AI EA NEW DISPATCH SYSTEM ARCHITECTURE

Author: Allan Munene Mutiiria