Telegram Trade Notifier
MQL4 has no trade-transaction callback the way MQL5 does, so the MQL4 version detects events by polling the order pool and history and comparing against the last known state of every tracked ticket. The MQL5 version uses the same poll-and-diff design deliberately, even though OnTradeTransaction() exists there - a single shared detection approach across both platforms is simpler to reason about and to keep in sync than maintaining an event-driven MQL5 path alongside a polling MQL4 one, and polling already gives the same InpCheckIntervalSec-bounded latency either way. A shallow version of this idea would just watch whether the open-trade count changed, which cannot tell an open from a close happening in the same interval and cannot see a stop-loss or take-profit edit at all. This tracks each tracked trade's SL and TP explicitly, so a modify is its own event rather than a silent gap. Outgoing messages go through a small queue instead of calling the Telegram API directly from the point an event is detected. Several events can be detected in the same poll - a basket close, say - and Telegram penalises a burst of sends from one bot; the queue drains one message at a time no faster than InpMinSendGapMs apart, and a failed send is put back at the front rather than dropped. The other trap this avoids is a silent, permanent failure. WebRequest returns a plain error if api.telegram.org has not been added to the terminal's allowed URL list, and a naive implementation would log that on every single failed attempt forever, or say nothing useful at all. This EA logs the exact fix, once, the first time it happens. Notes and limitations - Message text outside plain ASCII (accented characters, non-Latin order comments) is not UTF-8 encoded byte-by-byte - characters above code point 127 are sent as a "?" placeholder rather than corrupted bytes. - Detection is poll-based, not instant. An open, close or modify is picked up within InpCheckIntervalSec of happening, not the instant it happens. - If a trade opens and closes again within the same poll interval, only the close event is sent - the open was never observed as a distinct state. - Reattaching the EA seeds tracking from whatever is currently open without sending "opened" messages for pre-existing trades, so a restart does not flood the chat with history. - If WebRequest is not permitted for the Telegram URL, the EA logs the exact fix once and otherwise runs normally; it does not retry every tick once that specific failure has been identified. - This EA only sends notifications. It never opens, closes or modifies a trade itself.
Expert advisor · MT5 · v1.0 · Free
About Telegram Trade Notifier
Telegram Trade Notifier is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 9 settings, such as Bot token, Chat id and Notify on open. MQL source code included.
Files in the download: TelegramNotifier.ex5, TelegramNotifier.mq5, TelegramNotifier.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Bot token | Telegram bot token from @BotFather | |
| Chat id | Telegram chat ID to send to | |
| Notify on open | true | Send a message when a trade opens |
| Notify on close | true | Send a message when a trade closes |
| Notify on modify | false | Send a message when SL/TP changes on an open trade |
| Symbol only | false | Only track trades on this chart's symbol |
| Magic filter | 0 | Only track this magic number (0 = all magic numbers) |
| Check interval sec | 3 | Seconds between polls of open positions |
| Min send gap ms | 1200 | Minimum gap between outgoing messages, milliseconds |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Telegram · Alerts · MT5 Expert Advisor · MQL5 Source Code