ExMachina Telegram Bridge - MetaTrader 5 Expert - MT4/MT5 Resources


The EA detects trading events through two independent mechanisms: OnTradeTransaction handler for real-time detection and periodic trading history scanning as a backup. The deduplication system ensures that you never receive the same notification twice, even if both mechanisms trigger on the same event.
Supported notifications:
— Opening transactions: trading type, direction (buy/sell), trading volume, price, stop loss, take profit, magic number, transaction order
— Transaction end: symbol, trading volume, closing price, total profit and loss, commission, overnight interest, net profit and loss, updated balance
— SL/TP modification: old and new values displayed side by side (e.g. SL: 1924.00 → 1926.50)
— Pending orders: type (Buy Limit, Sell Limit, Buy Stop, Sell Stop, Buy Stop Limit, Sell Stop Limit), price, trading volume
— Position reversal: new direction, closing position with profit and loss
— Deposits and withdrawals: amounts and updated balances
— Regular account summary: balance, equity, available margin, floating P&L, session P&L, open positions, highest/lowest equity for the day, drawdown percentage
— Connect and disconnect messages with session statistics
Setup — step by step
You need two things Telegram provides: a bot token and your chat ID.
Step 1: Create a Telegram bot
Open Telegram, search for @BotFather, and start a conversation. Send command /newbot. BotFather will ask you to choose a display name (any name you like) and a username (must end in "bot"). Once created, BotFather will send you an API token - a long string similar to 7123456789:AAH1bCdEfGhIjKlMnOpQrStUvWxYz. Copy this token.
Step 2: Get your chat ID
In Telegram, search for @userinfobot (or @getmyid_bot) and send any message to it. It will reply with your numeric chat ID (eg 123456789). Copy this number.
For group notifications: Add your bot to a Telegram group and use @getidsbot in the group to get the group chat ID (negative number, for example -1001234567890).
Step 3: Start a conversation with your bot
This step is easy to forget. Find your bot by username in Telegram search, open it and press "Start". If you skip this step, Telegram's API will reject all messages.
Step 4: Allow WebRequest in MetaTrader 5
In MT5, go to Tools → Options → Expert Advisor. Check Allow WebRequests for listed URLs. Click Add and enter exactly: https://api.telegram.org — then click OK. This is a one-time configuration. If you skip this step, you will see WebRequest error 4014 in the Experts tab and no message will be sent.
Step 5: Install EA
Copy ExMachina_TelegramBridge.mq5 to your MQL5/Experts/ folder (accessed via File → Open Data Folder in MT5). Open MetaEditor (F4), navigate to the file, and press Compile (F7). You should see 0 errors, 0 warnings.
Step 6: Attach to Chart
Drag the EA from the Navigator panel onto any chart. In the settings dialog, paste your bot token and chat ID. Click OK. Within a few seconds, you should receive a connection message in Telegram showing your account number, server, balance, equity and number of open positions.
input parameters
Telegram configuration:
— Bot Token: API token from @BotFather (required)
— Chat ID: Your numerical chat ID (required, can be a group ID)
Notification settings:
— Trading opening notification: true/false (default value: true)
— Notify when transaction is closed: true/false (default: true)
— Stop loss/take profit notification modification: true/false (default value: true)
— Notify pending orders: true/false (default: true)
— Deposit/withdrawal notification: true/false (default: true)
Account Summary:
— Summary reporting intervals: off, every 1 hour, every 4 hours, every 8 hours, every 24 hours (default: every 4 hours)
— include equity in summary: true/false (default: true)
— Include retracement information: true/false (default: true)
Display and style:
— Message style: Minimal (compact one line), Detailed (complete information with labels), or Emoji-rich (details with Unicode icons). Default: Rich emoticons.
— Show dashboard on chart: true/false (default: true)
— Dashboard background, text color, accent color: customizable. The ExMachina Steel palette is used by default.
— Symbol filter: Comma-separated list of symbols to monitor. Leave all symbols blank. Example: "EURUSD,XAUUSD"
— Minimum lot size for notification: the minimum amount to trigger notification. 0 = no filter. Helps ignore microbatches.
— Magic number filter: Notify only transactions with that specific magic number. -1 = all transactions (including manual).
Minimal - compact single line format:
Gold USD | Buy | 0.50 lots @1928.45
Verbose—Use tag fields for structuring:
────────────────────────────────────────────────────────────────────────────
Close position: sell (close position buy)
Trading volume: 0.50 lots
───────────────────
Total profit and loss: +$340.00
Commission: -$2.50
Net profit or loss: +$337.50
Balance: $10,585.00
Transaction #182947363
Rich Emoticons (Default) - Same as Details, but with Unicode icons for each field. A trade opens with a green circle for buying and a red circle for selling. Closing a position shows a check mark for profit and a cross mark for loss.
The magic number filter is especially useful if you run multiple EAs on the same account. Set it to the magic number of a specific EA to only receive notifications from that EA. Set it to -1 to receive everything (including manual trades).
The symbol filter accepts a comma separated list: "XAUUSD,EURUSD,GBPUSD". Only transactions on these symbols will generate notifications. Leave blank to monitor all symbols.
Account summary
Periodic summaries include: balance, equity, available margin, number of open positions, total floating profit and loss (including swaps), period profit and loss since EA launch, daily high equity, daily low equity, and drawdown percentage calculated from the day's high.
Useful for proprietary traders who need to monitor daily drawdown limits remotely. Set the interval to 1 hour during active sessions.
Chart dashboard
The compact status panel in the upper left corner of the chart shows:
— Connection status: connected (green) or disconnected (red)
—bot username
— Running counter: sent and failed messages
— ExMachina tagline
The dashboard uses the ExMachina Steel color palette by default (Background C'8,10,18', Accent C'0,180,220') and can be customized or disabled via display input.
Step 1: Attach the EA to any chart on the demo account. Check "Connected to Bot @YourBotName" in Experts tab. Check the connection message in Telegram.
Step 2: Manually open a small market order (for example, 0.01 lots of EURUSD). You should receive a "TRADE OPENED" notification.
Step 3: Modify the stop loss or take profit of your position (right click → Modify). You should receive a "SL/TP MODIFIED" notification showing old value → new value.
Step 4: Close the position. You should receive a "Trade Closed" notification with profit and loss details.
Step 5: Place a pending order (e.g. buy limit). You should receive an "Order Pending" notification.
Step 6: Remove the EA from the chart. You should receive a "Disconnected" message with session statistics.
Quick browser test: To verify your token and chat ID before using the EA, paste this URL into any browser (replace the placeholders):
https://api.telegram.org/bot
If you see {"ok":true} in the response, your credentials are correct.
Quick smoke test script: save it as a script (not EA) in MQL5/Scripts/, compile and run on the demo chart:
#include <trade\trade.mqh>
CTrade Trading;
trade.Buy(0.01, "EUR/USD");
sleep(3000);
for(int i = PositionsTotal()-1; i >= 0; i--)
if(PositionGetSymbol(i) == "EURUSD")
trade.PositionClose(PositionGetTicket(i));
You should receive opening and closing notifications in Telegram.
Important note: This EA cannot be run in the Strategy Tester. Strategy Tester does not support WebRequest (network calls). The EA must be run on a live or demo chart with internet access.
Run with other EAs
MT5 only allows one EA per chart. Connect Telegram Bridge to a separate chart (any symbol). It monitors the entire account, not just the charts attached to it. Regardless of which chart the bridge is running on, all trades and manual trades from all EAs will be detected.
Use magic number filters to limit notifications to specific EAs.
troubleshooting
No message received:
1. Check whether https://api.telegram.org is located in Tools → Options → Expert Advisors → Allow WebRequest
2. Verify that the Bot Token and Chat ID are correct (no extra spaces)
3. Make sure you press "Start" in the bot's Telegram chat
4. Check for error messages in the Experts tab (View → Toolbox → Experts)
WebRequest Error 4014: Telegram URL is not in the allowed list. This is the most common question.
HTTP 401 Unauthorized: Invalid robot token. Copying this from @BotFather again.
HTTP 400 Bad Request: The chat ID is wrong, or you haven't started a conversation with the bot yet.
HTTP 429 Too many requests: Telegram rate limiting. The EA has built-in retry logic with backoff functionality. This only happens when trading frequency is extremely high.
EA shows INIT_PARAMETERS_INCORRECT: both bot token and chat ID are required. Make sure both fields are not empty.
Dashboard not showing: Make sure "Show dashboard on chart" in EA input is set to true.
technical details
— Transaction detection: dual mechanism via OnTradeTransaction (real-time) + transaction history polling every 2 seconds (fallback)
— Deduplication: processed transactions are stored in memory (last 500 transactions tracked)
— Stop Loss/Take Profit detection: array of position snapshots compared on each price move, triggered on any change
— Telegram API: HTTPS POST via WebRequest, URL-encoded payload, Markdown parsing mode
— Retry logic: Up to 3 attempts per message, 1 second delay between retries, 3 second delay on HTTP 429
— Connection test: The /getMe endpoint is called on init to verify the token and retrieve the bot name
— Summary timer: EventSetTimer(60) checks whether the configured time interval has elapsed
— Chart Objects: All dashboard objects are prefixed with "EXTB_" and cleared on deinit
— No external DLLs, no third-party servers. Direct MT5 → Telegram communication via HTTPS.
This EA is free and open source. Feedback, ratings and suggestions are welcome.
ExMachina Trading System – Precision over Profit.
Attachment download
📎 screenshot_telegram_bridge.png (68.45 KB)
📎 ExMachina_TelegramBridge.mq5 (42.57 KB)
Source: MQL5 #70383
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •