Async Promises Timers MT5
AsyncPro: JavaScript-Style Promises & Non-Blocking Timers for MQL5
"After purchase, I will send you the complete source code with MCP Server. Please leave your email address in the comments."
Overview Are you tired of your Expert Advisor (EA) freezing completely when executing Sleep(), making external API calls, or waiting for trade confirmations?
AsyncPro brings the power of JavaScript's Asynchronous Event Loop (Promises, setTimeout, setInterval) directly into MQL5. It allows your EA to execute time-consuming tasks in the background without blocking the main thread. Your terminal stays responsive, ticks are never missed, and complex multi-step logic becomes incredibly easy to write.
Key Features
-
True Non-Blocking Execution: Replace Sleep() with Timer::setTimeout(). Your EA continues to analyze the market while waiting for delays to finish.
-
Method Chaining: Avoid messy code. Use elegant .then(), .ccatch(), and .finally() blocks to handle multi-step executions.
-
Advanced Static Methods: Handle multiple tasks simultaneously using Promise::all(), Promise::race(), and Promise::any().
-
Memory-Leak Proof: Built-in auto-garbage collection safely destroys pointers upon EA removal.
-
Universal Integrator: Includes built-in external parameters allowing users to manually input API Webhook URLs, JSON payloads, Python scripts, and DLLs.
Input Parameters
-
InpEnableDebugLogs: Toggle terminal prints for a clean journal during live trading.
-
InpMaxPromises: Limits maximum concurrent promises in memory to protect resources.
-
InpApiUrl / InpJsonPayload: Text fields for custom Webhook URLs and JSON data.
-
InpCustomIndicator / InpPythonScript: Map external files without hardcoding them into the source.
How It Works AsyncPro uses MetaTrader's native hardware timer (OnTimer) to create an asynchronous task queue. When you create a new Promise(), the library registers the task and immediately returns control to the EA. Once the background task finishes, it automatically triggers your callback functions.
Best Use Cases
-
API / WebRequests: Calling external REST APIs (Binance, News data, ChatGPT) without hanging the terminal.
-
Telegram/Discord Bots: Sending trade alerts in the background.
-
Complex Grid/Martingale EAs: Managing spaced-out order executions to avoid broker requote errors.
-
Python/DLL Bridges: Waiting for a local script to process data and return a signal.
Developer Note: Created by Deepak / Deepak Fx Trader. Designed to bring modern web development architecture to algorithmic trading in MQL5.
