HomeSample Page

Sample Page Title


This text is a step-by-step information for builders who purchased Telegram SDK (compiled library) and need to combine Telegram notifications into their very own MQL4/MQL5 code. It covers each variations: MT4 and MT5.

Merchandise

Not a coder? Use the ready-to-run “Ship To Telegram” utilities

When you do not write code and also you need a answer you may simply connect to a chart and configure through inputs, use these merchandise as an alternative (they’re full-featured, extremely customizable, and able to run):

1) Who this SDK is for (necessary)

Limitations you need to know


2) After buy: the place the information are & the right way to set up

Necessary be aware about #import paths (MQL4/MQL5)

In each MQL4 and MQL5, #import searches relative to the Libraries folder:

Subsequently, to make use of this SDK as an imported library, you need to place the .ex4/.ex5  file into Libraries after which import it by filename.

Step 2.1 — Open your terminal knowledge folder

  1. In MetaTrader: File → Open Information Folder
  2. Go to the MQL4 or MQL5 folder relying in your platform.

Step 2.2 — Obtain from Market (inside terminal)

  1. Open the Market tab:
    • MT4: View → Terminal → MarketBought
    • MT5: View → Toolbox → MarketBought
  2. Discover the product and click on Obtain/Set up.

Step 2.3 — The place the Market places the downloaded file (precise location)

After set up, this product is positioned beneath the ScriptsMarket folder contained in the terminal Information Folder:

Step 2.4 — Required step: copy the SDK file into Libraries and import

As a result of #import resolves libraries from the Libraries folder, you need to copy the compiled file from ScriptsMarket to Libraries:

Then import by filename:

#import "Telegram SDK.ex4"
   // declarations...
#import
#import "Telegram SDK.ex5"
   // declarations...
#import

Tip: After copying, restart MetaEditor (and/or the terminal) if MetaEditor doesn’t detect the library instantly.

Tip: MetaEditor can generate an import/embody stub routinely from an exported library (Instruments → Generate Embody File). This can be a handy solution to keep away from handbook prototype errors.


3) Telegram stipulations (token + chat id)

Step 3.1 — Create a bot token

  1. In Telegram, seek for @BotFather
  2. Create a bot and replica the bot token (seems like 123456789:AA…. )

Step 3.2 — Get your chat_id (non-public / group / channel)


4) MetaTrader settings (WebRequest whitelist)

You have to permit WebRequest for Telegram API in terminal choices, in any other case calls fail.

  1. Go to: Instruments → Choices → Skilled Advisors
  2. Allow: Permit WebRequest for listed URL
  3. Add this URL:
https://api.telegram.org

5) Import stub (copy/paste)

MT4 Import Stub

#import "Telegram SDK.ex4"
   int    TG_Init(string token, string chat_id);
   void   TG_SetTimeoutMs(int ms);
   void   TG_SetRetries(int n);
   void   TG_SetDebug(bool on);
   string TG_Version();

   // Base ship (handbook reply id)
   int TG_SendMessage(string token, string chat_id, string textual content,
                      string parse_mode, bool disable_preview, bool disable_notification,
                      int reply_to_message_id);
   int TG_SendMessageDefault(string textual content, string parse_mode, bool disable_preview, bool disable_notification,
                             int reply_to_message_id);

   // Threading (circulation cũ)
   int TG_SendMessageThread(string token, string chat_id, string thread_key,
                            string textual content, string parse_mode,
                            bool disable_preview, bool disable_notification,
                            bool saveAsRoot, bool replyToRoot);
   int TG_SendMessageThreadDefault(string thread_key,
                                   string textual content, string parse_mode,
                                   bool disable_preview, bool disable_notification,
                                   bool saveAsRoot, bool replyToRoot);

   // Legacy int key (MT4 ticket)
   int TG_SendMessageThreadInt(string token, string chat_id, int key,
                               string textual content, string parse_mode,
                               bool disable_preview, bool disable_notification,
                               bool saveAsRoot, bool replyToRoot);
   int TG_SendMessageThreadIntDefault(int key,
                                      string textual content, string parse_mode,
                                      bool disable_preview, bool disable_notification,
                                      bool saveAsRoot, bool replyToRoot);

   // Photograph base
   int TG_SendPhotoFile(string token, string chat_id, string file_path,
                        string caption, string parse_mode,
                        bool disable_notification, int reply_to_message_id);

   // Photograph default
   int TG_SendPhotoFileDefault(string file_path,
                               string caption, string parse_mode,
                               bool disable_notification, int reply_to_message_id);

   // Photograph threading
   int TG_SendPhotoFileThread(string token, string chat_id, string thread_key,
                              string file_path,
                              string caption, string parse_mode,
                              bool disable_notification,
                              bool saveAsRoot, bool replyToRoot);
   int TG_SendPhotoFileThreadDefault(string thread_key,
                                     string file_path,
                                     string caption, string parse_mode,
                                     bool disable_notification,
                                     bool saveAsRoot, bool replyToRoot);

   // Photograph threading legacy int key
   int TG_SendPhotoFileThreadInt(string token, string chat_id, int key,
                                 string file_path,
                                 string caption, string parse_mode,
                                 bool disable_notification,
                                 bool saveAsRoot, bool replyToRoot);
   int TG_SendPhotoFileThreadIntDefault(int key,
                                        string file_path,
                                        string caption, string parse_mode,
                                        bool disable_notification,
                                        bool saveAsRoot, bool replyToRoot);

   // Map (optionally available, power-user)
   bool TG_SaveRootMessageId(string key, int message_id);
   int  TG_GetRootMessageId(string key);

   // Validate
   bool TG_ValidateToken(string token);
   bool TG_ValidateChatID(string token, string chat_id);

   // Final error
   int    TG_GetLastHttpCode();
   int    TG_GetLastErrorCode();
   string TG_GetLastErrorMessage();
   string TG_GetLastResponseRaw();
#import

MT5 Import Stub

#import "Telegram SDK.ex5"
   int    TG_Init(string token, string chat_id);
   void   TG_SetTimeoutMs(int ms);
   void   TG_SetRetries(int n);
   void   TG_SetDebug(bool on);
   string TG_Version();

   // Base ship (handbook reply id)
   int TG_SendMessage(string token, string chat_id, string textual content,
                      string parse_mode, bool disable_preview, bool disable_notification,
                      int reply_to_message_id);
   int TG_SendMessageDefault(string textual content, string parse_mode, bool disable_preview, bool disable_notification,
                             int reply_to_message_id);

   // Threading (circulation cũ)
   int TG_SendMessageThread(string token, string chat_id, string thread_key,
                            string textual content, string parse_mode,
                            bool disable_preview, bool disable_notification,
                            bool saveAsRoot, bool replyToRoot);
   int TG_SendMessageThreadDefault(string thread_key,
                                   string textual content, string parse_mode,
                                   bool disable_preview, bool disable_notification,
                                   bool saveAsRoot, bool replyToRoot);

   // Legacy MT5 ticket key (ulong)
   int TG_SendMessageThreadULong(string token, string chat_id, ulong key,
                                 string textual content, string parse_mode,
                                 bool disable_preview, bool disable_notification,
                                 bool saveAsRoot, bool replyToRoot);
   int TG_SendMessageThreadULongDefault(ulong key,
                                        string textual content, string parse_mode,
                                        bool disable_preview, bool disable_notification,
                                        bool saveAsRoot, bool replyToRoot);

   // Photograph base
   int TG_SendPhotoFile(string token, string chat_id, string file_path,
                        string caption, string parse_mode,
                        bool disable_notification, int reply_to_message_id);

   // Photograph default
   int TG_SendPhotoFileDefault(string file_path,
                               string caption, string parse_mode,
                               bool disable_notification, int reply_to_message_id);

   // Photograph threading
   int TG_SendPhotoFileThread(string token, string chat_id, string thread_key,
                              string file_path,
                              string caption, string parse_mode,
                              bool disable_notification,
                              bool saveAsRoot, bool replyToRoot);
   int TG_SendPhotoFileThreadDefault(string thread_key,
                                     string file_path,
                                     string caption, string parse_mode,
                                     bool disable_notification,
                                     bool saveAsRoot, bool replyToRoot);

   // Photograph threading legacy ulong key
   int TG_SendPhotoFileThreadULong(string token, string chat_id, ulong key,
                                   string file_path,
                                   string caption, string parse_mode,
                                   bool disable_notification,
                                   bool saveAsRoot, bool replyToRoot);
   int TG_SendPhotoFileThreadULongDefault(ulong key,
                                          string file_path,
                                          string caption, string parse_mode,
                                          bool disable_notification,
                                          bool saveAsRoot, bool replyToRoot);

   // Map (optionally available, power-user)
   bool TG_SaveRootMessageId(string key, int message_id);
   int  TG_GetRootMessageId(string key);

   // Validate
   bool TG_ValidateToken(string token);
   bool TG_ValidateChatID(string token, string chat_id);

   // Final error
   int    TG_GetLastHttpCode();
   int    TG_GetLastErrorCode();
   string TG_GetLastErrorMessage();
   string TG_GetLastResponseRaw();
#import

6) Fast Begin (minimal working instance)

This minimal EA sends 1 message on startup. Notice: the SDK helps |n as a newline placeholder.

MT4 Minimal EA

#property strict

#import "Telegram SDK.ex4"
   int  TG_Init(string token, string chat_id);
   void TG_SetDebug(bool on);
   int  TG_SendMessageDefault(string textual content, string parse_mode, bool disable_preview, bool disable_notification,
                              int reply_to_message_id);
   int    TG_GetLastHttpCode();
   int    TG_GetLastErrorCode();
   string TG_GetLastErrorMessage();
#import

int OnInit()
n<b>Telegram SDK</b>", "HTML", true, false, 0);

   Print("mid=", mid,
         " http=", TG_GetLastHttpCode(),
         " err=",  TG_GetLastErrorCode(),
         " msg=",  TG_GetLastErrorMessage());

   return(INIT_SUCCEEDED);


void OnDeinit(const int motive) {}
void OnTick() {}

MT5 Minimal EA

#property strict

#import "Telegram SDK.ex5"
   int  TG_Init(string token, string chat_id);
   void TG_SetDebug(bool on);
   int  TG_SendMessageDefault(string textual content, string parse_mode, bool disable_preview, bool disable_notification,
                              int reply_to_message_id);
   int    TG_GetLastHttpCode();
   int    TG_GetLastErrorCode();
   string TG_GetLastErrorMessage();
#import

int OnInit()
n<b>Telegram SDK</b>", "HTML", true, false, 0);

   Print("mid=", mid,
         " http=", TG_GetLastHttpCode(),
         " err=",  TG_GetLastErrorCode(),
         " msg=",  TG_GetLastErrorMessage());

   return(INIT_SUCCEEDED);

7) Textual content messages (Base API)

7.1 TG_Init + Default calls

  • Name TG_Init(token, chat_id) as soon as (e.g., in OnInit() ).
  • Then use …Default() strategies so that you don’t go token/chat_id each time.

7.2 parse_mode

  • Use “HTML” if you’d like formatting like <b>daring</b> , <i>italic</i> , and so forth.
  • Use “Markdown” or “MarkdownV2” in case you favor Markdown fashion.
  • Use “” (empty) for plain textual content.

7.3 disable_preview / disable_notification

  • disable_preview=true avoids hyperlink previews (cleaner channels).
  • disable_notification=true sends silently (no notification sound).

8) Threading (the “circulation cũ”)

Threading right here means: you ship one ROOT message, then later updates can reply to that ROOT message, holding a clear timeline per commerce/order.

8.1 The core thought

  • thread_key identifies the thread (instance: ticket id, order id, customized string like “EURUSD#A1” ).
  • saveAsRoot = retailer the returned message_id because the ROOT for that key.
  • replyToRoot = routinely reply to the saved ROOT message_id.

Necessary: ROOT mapping is saved in reminiscence. When you restart the terminal/EA, you need to ship ROOT once more (or retailer/reload mapping your self).

8.2 Minimal “circulation cũ” demo — MT4 (int key)

#property strict

#import "Telegram SDK.ex4"
   int  TG_Init(string token, string chat_id);
   void TG_SetDebug(bool on);

   int TG_SendMessageThreadIntDefault(int key,
                                      string textual content, string parse_mode,
                                      bool disable_preview, bool disable_notification,
                                      bool saveAsRoot, bool replyToRoot);

   int    TG_GetLastHttpCode();
   int    TG_GetLastErrorCode();
   string TG_GetLastErrorMessage();
#import

int OnInit()
nSL moved...",
                                                  "HTML", true, false,
                                                  false, true);

   Print("root_mid=", root_mid, " reply_mid=", reply_mid,
         " http=", TG_GetLastHttpCode(),
         " err=",  TG_GetLastErrorCode(),
         " msg=",  TG_GetLastErrorMessage());

   return(INIT_SUCCEEDED);

8.3 Minimal “circulation cũ” demo — MT5 (ulong key)

#property strict

#import "Telegram SDK.ex5"
   int  TG_Init(string token, string chat_id);
   void TG_SetDebug(bool on);

   int TG_SendMessageThreadULongDefault(ulong key,
                                        string textual content, string parse_mode,
                                        bool disable_preview, bool disable_notification,
                                        bool saveAsRoot, bool replyToRoot);

   int    TG_GetLastHttpCode();
   int    TG_GetLastErrorCode();
   string TG_GetLastErrorMessage();
#import

int OnInit()
nTP modified...",
                                                    "HTML", true, false,
                                                    false, true);

   Print("root_mid=", root_mid, " reply_mid=", reply_mid,
         " http=", TG_GetLastHttpCode(),
         " err=",  TG_GetLastErrorCode(),
         " msg=",  TG_GetLastErrorMessage());

   return(INIT_SUCCEEDED);

9) Ship pictures (sendPhoto)

9.1 The place to place picture information

The SDK reads picture information utilizing the terminal sandbox. The best rule:

  • Put your picture into:
    • MT4: <Information Folder>MQL4Files
    • MT5: <Information Folder>MQL5Files
  • Then go file_path as simply the filename (instance: “shot.png” ) or a subfolder path inside Information.

9.2 Photograph examples

Ship picture (default)

// caption helps parse_mode too (e.g. "HTML")
int mid = TG_SendPhotoFileDefault("shot.png",
                                 "Chart screenshot|n<b>XAUUSD</b>",
                                 "HTML",
                                 false,
                                 0);

Ship picture threaded (save ROOT + reply later)

// ROOT picture
int root_photo = TG_SendPhotoFileThreadDefault("commerce#10001",
                                              "shot.png",
                                              "ROOT screenshot",
                                              "",
                                              false,
                                              true,   // saveAsRoot
                                              false); // replyToRoot

10) Error dealing with & debugging (must-read)

10.1 At all times test these after a ship

  • TG_GetLastHttpCode() — HTTP response code (200 = OK)
  • TG_GetLastErrorCode() — Telegram error code or inner code
  • TG_GetLastErrorMessage() — human-readable message
  • TG_GetLastResponseRaw() — uncooked JSON response (helpful for troubleshooting)

10.2 Frequent failure causes

  • WebRequest not allowed: You forgot to whitelist https://api.telegram.org in Choices.
  • Flawed token/chat_id: Telegram returns an error in JSON (test LastErrorMessage).
  • Price limits (429): Too many messages too quick. Use fewer calls, or hold TG_SetRetries(n) cheap.

10.3 Efficiency tip

Don’t ship a message on each tick. As an alternative, set off solely on occasions (new commerce, shut, SL/TP change, and so forth.), or implement a easy throttling/queue.


11) Really helpful settings

  • TG_SetTimeoutMs(10000) for a secure community surroundings.
  • TG_SetRetries(2) or 3 to outlive quick outages, however don’t spam.
  • TG_SetDebug(true) whereas integrating; flip off in manufacturing if you’d like a clear Journal.

12) Last notes + please help the product ❤️

If Telegram SDK saved you improvement time and labored nicely to your undertaking, please contemplate leaving a 5-star evaluation on the Market web page. It helps lots with product rating and future updates.

And once more — if you’d like a ready-to-run model for non-coders:

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles