Professional library of Telegram Bot integration for MetaTrader 5. A complete solution for sending trading signals, screenshots, reports and real-time notifications to Telegram channels and groups.
Main features
- 📨 Real-time trade notifications - Instant alerts on opening/closing/modifying positions
- 📸 Chart screenshots - Automatically capture charts with annotations
- 📊 A ccount Reports - Daily, weekly and monthly performance reports
- ⚠️ Risk Management Alerts - Drawdown, margin level and stop-out alerts
- 🔄 Message queuing system - Reliable delivery with retry mechanism
- 👥 Multi-channel support - Send to multiple Telegram chats/channels
- 📝 Template system - Customisable message templates
- 🎯 S mart rate limiting - Prevent API blocking
Requirements
- MetaTrader 5 version 2375 or higher
- Telegram Bot token (get it from @BotFather)
- Chat or channel ID
- Internet connection
Installation
Step 1: Create a Telegram Bot
- Open Telegram and find @BotFather
- Send the command /newbot
- Choose a name for your bot
- Select username (must end with 'bot')
- Save the token provided by BotFather
Step 2: Obtain a Chat ID
- Add the bot to a group/channel or start a private chat room
- Send any message to the bot
- Go to: https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates
- Find the chat ID in the reply
Step 3: Setup MT5
- Open MT5 → Service → Settings → Expert Advisors
- Tick the "Allow WebRequest for the following URLs" box
- Add URL: https://api.telegram.org
- Click OK
Step 4: Install files
- Copy TelegramBot.mqh to the MQL5/Include/ folder.
- Copy TelegramBot_Example.mq5 to the MQL5/Experts/ folder.
- Compile both files
Quick Start
#include <TelegramBot.mqh> CTelegramBot bot; int OnInit() { // Initialising the bot if(!bot.Initialize("YOUR_TOKEN"., "YOUR_CHAT_ID")) { Print("Failed to initialise bot"); return INIT_FAILED; } // Sending a test message bot.SendMessage("Bot successfully connected!"); // Send a screenshot of the graph bot.SendChartScreenshot("Current market situation."); return INIT_SUCCEEDED; }
API Reference
Basic Messages
bool SendMessage(string text); bool SendHTMLMessage(string text); bool SendMarkdownMessage(string text); bool SendMessageToAll(string text);
Trading Signals
bool SendTradeSignal(ENUM_SIGNAL_TYPE type, string symbol, double price); bool SendPositionOpened(ulong ticket, string symbol, ENUM_POSITION_TYPE type, double volume, double price); bool SendPositionClosed(ulong ticket, string symbol, double profit, double commission, double swap);
Media files
bool SendPhoto(string file_path, string caption); bool SendDocument(string file_path, string caption); bool SendChartScreenshot(); bool SendChartScreenshot(string caption);
Reports
bool SendAccountStatus(); bool SendDailyReport(); bool SendWeeklyReport(); bool SendMonthlyReport();
Risk Management
bool SendRiskAlert(double drawdown_percent); bool SendMarginWarning(double margin_level); bool SendStopOutWarning();
Expert Advisor example
The package includes a fully functional example of the Expert Advisor, demonstrating:
- Position monitoring with notifications
- Automatic screenshots at trading events
- Periodic account status updates
- Risk management alerts
- Daily reports
- Demo trading signals
Message formatting
HTML format (recommended)
string message = "<b> Жирный текст</b>\n"; message += "<i> Курсив</i>\n"; message += "<code> Моноширинный код</code>\n"; message += "<a href='http://example.com'> Ссылка</a>"; bot.SendHTMLMessage(message);
Markdown format
string message = "Bold text{\n}"; message += "Italics."; message += "Monospaced code."; message += "[Link](http://example.com)"; bot.SendMarkdownMessage(message);
Performance
- Message Speed: Up to 30 messages per minute
- File size limit: 50MB per file
- Message length: 4096 characters
- Signature length: 1024 characters
- Queue size: 100 messages
- Average response time: 50-200ms
Error handling
The library includes complex error handling:
- Connection checking
- Limit overrun protection
- Automatic retries on failure
- Queuing system for failed messages
- Detailed error logging
- Documentation: Full API documentation is included in the source code
- EA example: Working example with all features
- Debug Mode: Built-in debugging for troubleshooting
Version History
Version 1.0.0 (2024)
- First release
- Full integration of Telegram Bot API
- Support for multiple channels
- Queuing system
- Template engine
- Risk management alerts
Licence
This library is provided "as is" for use in MetaTrader 5. It is free for personal and commercial use.
Forex Trading Blueprint
(Stepan Sinic)
Disclaimer
This software is provided "as is" without warranty of any kind. Trading involves a substantial risk of loss and is not suitable for all investors. Past performance is not an indicator of future results.
If you find this library useful, please rate it on MQL5 CodeBase!
Detailed setup instructions
Creating a bot in Telegram
-
Find BotFather
- Open Telegram
- Type @BotFather in the search
- Press START
-
Create a new bot
- Send the command /newbot
- Enter the bot's name (for example: "My Trading Bot")
- Enter the bot's username (for example: my_trading_bot)
- Save the token of the form: 123456789:ABCdefGHIjklMNOpqrsTUVwxyz
-
Configure the bot
- Send /setprivacy and select DISABLE (for working in groups).
- Send /setjoingroups and select ENABLE (to add to groups)
Getting a Chat ID
For private messages:
- Start a dialogue with your bot
- Send any message
- Open in your browser: https://api.telegram.org/bot<TOKEN>/getUpdates
- Find "chat":{"id":123456789} - this is your Chat ID
For a group:
- Add the bot to a group
- Send a message in the group
- Open in a browser: https://api.telegram.org/bot<TOKEN>/getUpdates
- Find "chat":{"id":-123456789} is a negative number for groups
For channel:
- Add a bot as a channel administrator
- Send a message to the channel
- Or use @username of the channel as Chat ID
Frequent Problem Solution
WebRequest error:
Solution: 1. Tools → Settings → Advisors 2. ✓ Allow WebRequest for the following URLs 3. Add: https://api.telegram.org 4. Restart MT5
Bot is not responding:
Check: 1. Correct token 2. Chat ID is correct 3. Internet connection 4. WebRequest settings
Messages are not getting through:
Possible causes: 1. API limit exceeded (30 messages/minute) 2. Incorrect HTML format in the message 3. Message is too long (>4096 characters)
Usage Examples
Sending a buy signal
bot.SendTradeSignal(SIGNAL_BUY, "EURUSD", 1.1850, 1.1800, 1.1900);
Sending a screenshot with annotation
string caption = "<b> Точка входа</b>\n"; caption += "Пара: EURUSD\n"; caption += "Тип: BUY\n"; caption += "Цена: 1.1850"; bot.SendChartScreenshot(caption);
Sending account status
bot.SendAccountStatus();
// Automatically send balance, equity, margin, etc. Setting up daily reports
// In OnTimer() advisor if(TimeHour(TimeCurrent()) == 23 && TimeMinute(TimeCurrent()) == 0) { bot.SendDailyReport(); }
Drawdown alert
double drawdown = CalculateDrawdown(); // Your calculation function if(drawdown > 20.0) // The drawdown is more than 20% { bot.SendRiskAlert(drawdown); }
Message structure
Position open
[POSITION OPENED] ↑ ================ Ticket: #12345678 Symbol: EURUSD Type: BUY Volume: 0.10 Price: 1.18500 Time: 2024.01.15 10:30 ================
Position closed
[POSITION CLOSED] ================ Ticket: #12345678 Symbol: EURUSD Profit: +125.50 USD Commission: -2.00 Swap: -0.50 Total: +123.00 USD Time: 2024.01.15 14:45 ================
Daily report
[DAILY REPORT] ================ Date: 2024.01.15 ACCOUNT SUMMARY ---------------- Balance: 10,125.50 USD Equity: 10,250.00 USD Floating P/L: +124.50 USD TRADING ACTIVITY ---------------- Trades Today: 5 Today's Result: +250.00 USD Open Positions: 2 BOT STATISTICS ---------------- Messages Sent: 45 Signals Sent: 8 Success Rate: 98.5% ================