Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

MetaTrader 5 Libraries | MT5 to Telegram - Professional Trading Notifications Library

MetaTrader Experts, Indicators, Scripts and Libraries

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

  1. Open Telegram and find @BotFather
  2. Send the command /newbot
  3. Choose a name for your bot
  4. Select username (must end with 'bot')
  5. Save the token provided by BotFather

Step 2: Obtain a Chat ID

  1. Add the bot to a group/channel or start a private chat room
  2. Send any message to the bot
  3. Go to: https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates
  4. Find the chat ID in the reply

Step 3: Setup MT5

  1. Open MT5 → Service → Settings → Expert Advisors
  2. Tick the "Allow WebRequest for the following URLs" box
  3. Add URL: https://api.telegram.org
  4. Click OK

Step 4: Install files

  1. Copy TelegramBot.mqh to the MQL5/Include/ folder.
  2. Copy TelegramBot_Example.mq5 to the MQL5/Experts/ folder.
  3. 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

  1. Find BotFather

    • Open Telegram
    • Type @BotFather in the search
    • Press START
  2. 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
  3. 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:

  1. Start a dialogue with your bot
  2. Send any message
  3. Open in your browser: https://api.telegram.org/bot<TOKEN>/getUpdates
  4. Find "chat":{"id":123456789} - this is your Chat ID

For a group:

  1. Add the bot to a group
  2. Send a message in the group
  3. Open in a browser: https://api.telegram.org/bot<TOKEN>/getUpdates
  4. Find "chat":{"id":-123456789} is a negative number for groups

For channel:

  1. Add a bot as a channel administrator
  2. Send a message to the channel
  3. 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%
================
63585

Best MetaTrader Indicators + Profitable Expert Advisors