Voir comment télécharger gratuitement des robots de trading
Retrouvez-nous sur Telegram !
Rejoignez notre page de fans
Un script intéressant ?
Poster un lien vers celui-ci -
laisser les autres l'évaluer
Vous avez aimé le script ? Essayez-le dans le terminal MetaTrader 5
Bibliothèque

MT5 to Telegram Professional Library - bibliothèque pour MetaTrader 5

Vues:
849
Note:
(2)
Publié:
Mise à jour:
\MQL5\Include\ \MQL5\Experts\
testbot.mq5 (42.56 KB) afficher
MQL5 Freelance Besoin d'un robot ou d'un indicateur basé sur ce code ? Commandez-le sur Freelance Aller sur Freelance

Key Features

  • 📨 Real-time Trading Notifications - Instant alerts for position open/close/modify
  • 📸 Chart Screenshots - Automatic chart captures with annotations
  • 📊 Account Reports - Daily, weekly, and monthly performance reports
  • ⚠️ Risk Management Alerts - Drawdown, margin level, and stop-out warnings
  • 🔄 Message Queue System - Reliable delivery with retry mechanism
  • 👥 Multi-Channel Support - Broadcast to multiple Telegram chats/channels
  • 📝 Template System - Customizable message templates
  • 🎯 Smart Rate Limiting - Prevents API throttling

Requirements

  • MetaTrader 5 build 2375 or higher
  • Telegram Bot Token (obtain from @BotFather)
  • Chat ID or Channel ID
  • Internet connection

Installation

Step 1: Create Telegram Bot

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

Step 2: Get Chat ID

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

Step 3: Configure MT5

  1. Open MT5 → Tools → Options → Expert Advisors
  2. Check "Allow WebRequest for listed URL"
  3. Add URL: https://api.telegram.org
  4. Click OK

Step 4: Install Files

  1. Copy TelegramBot.mqh to MQL5/Include/
  2. Copy TelegramBot_Example.mq5 to MQL5/Experts/
  3. Compile both files

Quick Start

#include <TelegramBot.mqh>

CTelegramBot bot;

int OnInit()
{
    // Initialize bot
    if(!bot.Initialize("YOUR_TOKEN", "YOUR_CHAT_ID"))
    {
        Print("Failed to initialize bot");
        return INIT_FAILED;
    }
    
    // Send test message
    bot.SendMessage("Bot connected successfully!");
    
    // Send chart screenshot
    bot.SendChartScreenshot("Current market situation");
    
    return INIT_SUCCEEDED;
}

API Reference

Basic Messaging

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

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();

Example Expert Advisor

The package includes a fully functional example EA demonstrating:

  • Position monitoring with notifications
  • Automatic screenshots on trade events
  • Periodic account status updates
  • Risk management alerts
  • Daily reports
  • Demo trading signals

Message Formatting

HTML Format (Recommended)

string message = "<b>Bold text</b>\n";
message += "<i>Italic text</i>\n";
message += "<code>Fixed-width code</code>\n";
message += "<a href='http://example.com'>Link</a>";
bot.SendHTMLMessage(message);

Markdown Format

string message = "*Bold text*\n";
message += "_Italic text_\n";
message += "`Fixed-width code`\n";
message += "[Link](http://example.com)";
bot.SendMarkdownMessage(message);

Performance

  • Message Rate: Up to 30 messages per minute
  • File Size Limit: 50MB per file
  • Message Length: 4096 characters
  • Caption Length: 1024 characters
  • Queue Size: 100 messages
  • Average Response Time: 50-200ms

Error Handling

The library includes comprehensive error handling:

  • Connection validation
  • Rate limiting protection
  • Automatic retries on failure
  • Queue system for failed messages
  • Detailed error logging

Support

  • Documentation: Full API documentation included in source
  • Example EA: Working example with all features
  • Debug Mode: Built-in debugging for troubleshooting

Version History

Version 1.0.0 (2024)

  • Initial release
  • Full Telegram Bot API integration
  • Multi-channel support
  • Queue system
  • Template engine
  • Risk management alerts

License

This library is provided as-is for use in MetaTrader 5. Free for personal and commercial use.

Author

Financial Blueprint
Professional Trading Solutions

Disclaimer

This software is provided "as is" without warranty of any kind. Trading involves substantial risk of loss and is not suitable for all investors. Past performance is not indicative of future results.


If you find this library useful, please rate it on MQL5 CodeBase!

Detailed Setup Instructions

Creating a Telegram Bot

  1. Find BotFather

    • Open Telegram
    • Search for @BotFather
    • Press START
  2. Create New Bot

    • Send /newbot command
    • Enter bot name (e.g., "My Trading Bot")
    • Enter bot username (e.g., my_trading_bot)
    • Save the token like: 123456789:ABCdefGHIjklMNOpqrsTUVwxyz
  3. Configure Bot

    • Send /setprivacy and select DISABLE (for group functionality)
    • Send /setjoingroups and select ENABLE (to add to groups)

Getting Chat ID

For Private Messages:

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

For Groups:

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

For Channels:

  1. Add bot as channel administrator
  2. Send message to channel
  3. Or use @channelname as Chat ID

Troubleshooting Common Issues

WebRequest Error:

Solution: 1. Tools → Options → Expert Advisors 2. ✓ Allow WebRequest for listed URL 3. Add: https://api.telegram.org 4. Restart MT5

Bot Not Responding:

Check: 1. Token correctness 2. Chat ID correctness 3. Internet connection 4. WebRequest settings

Messages Not Delivered:

Possible causes: 1. API limit exceeded (30 messages/minute) 2. Invalid HTML format in message 3. Message too long (>4096 characters)

Usage Examples

Send Buy Signal

bot.SendTradeSignal(SIGNAL_BUY, "EURUSD", 1.1850, 1.1800, 1.1900);

Send Screenshot with Annotation

string caption = "<b>Entry Point</b>\n";
caption += "Pair: EURUSD\n";
caption += "Type: BUY\n";
caption += "Price: 1.1850";
bot.SendChartScreenshot(caption);

Send Account Status

bot.SendAccountStatus();
// Automatically sends balance, equity, margin, etc.

Setup Daily Reports

// In EA's OnTimer()
if(TimeHour(TimeCurrent()) == 23 && TimeMinute(TimeCurrent()) == 0)
{
    bot.SendDailyReport();
}

Drawdown Alert

double drawdown = CalculateDrawdown(); // Your calculation function
if(drawdown > 20.0) // Drawdown greater than 20%
{
    bot.SendRiskAlert(drawdown);
}

Message Structure

[POSITION OPENED] ↑
================
Ticket: #12345678
Symbol: EURUSD
Type: BUY
Volume: 0.10
Price: 1.18500
Time: 2024.01.15 10:30


[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]
================
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%
================


Martingale Pulse EA Martingale Pulse EA

Introducing MP by SPLpulse, a sophisticated and highly versatile Expert Advisor designed for the modern trader. Whether you are a scalper, a trend follower, or a reversal trader, MP by SPLpulse combines multiple trading strategies with an institutional-grade risk management suite to adapt to your unique trading style. Take control of your trading with unparalleled customization and powerful automation.

WaveTrend WaveTrend

The WaveTrend Indicator (WT) is a powerful technical analysis tool designed to identify trend direction and potential reversal points. It plots two lines, WT1 and WT2 , in a separate window, calculated based on price momentum and smoothed averages.

Accelerator Oscillator (AC) Accelerator Oscillator (AC)

The Acceleration/Deceleration Indicator (AC) measures acceleration and deceleration of the current driving force.

MACD Signals MACD Signals

Indicator edition for new platform.