Rajandran R Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

How to Send Alerts from Amibroker to Telegram Channel using Telgram API

1 min read

In this tutorial we will be discussing practical examples of how to send alerts from Amibroker to a Telegram channel using Telegram Bot API

In order to be able to do so, you will have first to:

  • Create a Telegram public channel
  • Create a Telegram BOT via BotFather
  • Set the bot as administrator in your channel

Getting the BOT API key from BotFather in Telgram APP

Provided that you did the above, now you can send a message to your channel by issuing an HTTP GET request to the Telegram BOT API at the following URL:

 https://api.telegram.org/bot[BOT_API_KEY]/sendMessage?chat_id=[MY_CHANNEL_NAME]&text=[MY_MESSAGE_TEXT] 

where:

  • BOT_API_KEY is the API Key generated by BotFather when you created your bot
  • MY_CHANNEL_NAME is the handle of your channel (e.g. @my_channel_name)
  • MY_MESSAGE_TEXT is the message you want to send (URL-encoded)

One can send Telgram Alerts from Amibroker in two different ways

1)Modern Way to access HTTP API using InternetOpenURL functions (Supports Amibroker 6.17 or higher)
2)Using AFL scripting (VBScript) inside the AFL Program (legacy method compatible with most of the versions of Amibroker)

Legacy Method 
Using AFL scripting (VBScript)

If you understand Amibroker from a coding perspective it supports AFL scripting host. AFL scripting host is an interface between AFL engine and JScript/VBScript engines (aka. Active Scripting technologies) available as a part of Internet Tools & Technologies platform provided by Microsoft.

https://gist.github.com/21f80cd8278403d7e8c335706e272436

Modern Method
using InternetOpenURL functions

Code requires Amibroker 6.17 as some of the new AFL functions like InternetClose( handle ) , InternetOpenURL( “url” ) , InternetReadString( handle ) – which is essecial to read from internet resource/http api is available from v6.17 or higher version.

https://gist.github.com/f42f1d0a684eee96a89a134bad1ef3d0

Amibroker Controls

1)Apply the AFL to the chart and over the chart -> right click and select Properties

2)Enter the Telegram Bot API Key and Channel ID as per your requirement

3) Press the Send Alert (Trigger Button)

4)Bingo you are done. You should be able to see the Telegram Alert from Amibroker in your Telegram Channel

Hope you enjoyed this article!

If you are interested  in getting  Amibroker Installation Setup  and Datafeeds (NSE Cash, NSE Futures, MCX Futures, NSE Currencies) setup you can fill  up the 3 days Demo form here

www.marketcalls.in/demo
For any inquiries can reach our support team at  9535133445 /8861522875 ( 9a.m – 6p.m IST Mon – Sat)

Rajandran R Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

What is QuantZilla?

Quantzilla is 75+ hours of code mentoring program designed for noncoders who want to learn the coding program right from designing indicators, scanners, trading...
Rajandran R
58 sec read

Things to Consider While Building a Bracket Order Execution…

Building a Bracket Order Strategy is the most demanded request we got from most of the algomojo traders. This article explains the list of...
Rajandran R
12 min read

PlaceOrder – Multi Broker Exectuion Code Snippets for Amibroker

This tutorial explains how to build a button trading right from scratch and with a click of a button how you can send orders...
Rajandran R
7 min read

25 Replies to “How to Send Alerts from Amibroker to Telegram Channel…”

  1. excellent code..im already follow this instruction but alert not send to telegram… what i missed? should i change my own code? thanks

  2. Hi Rajandran, thank for share.
    but i can’t run after use ur code like this:

    _SECTION_BEGIN(“Telegram Alerts – Legacy Method”);

    TelegramAlerts = ParamTrigger(“Telegram Alert”,”Send Alert”);
    TelegramAPI_ID = ParamStr(“Telegram Bot API Key”,”727373270:AAFTaMLexxxxxxxxxxI”); //Get the Bot API key via BotFather in Telgram
    TelgramCHAT_ID = ParamStr(“Telegram Channel ID”,”-1001389xxxxxx”); //Channel ID example : @marketcalls_in

    //User Defined Function -> Created using VBscript
    EnableScript(“VBScript”);
    // “normal” AFL statements
    Buy=Cover=Cross(j,nw);
    Sell=Short=Cross(nw,j);

    // “normal” AFL statements
    Buy = ExRem( Buy, Sell );

    tg = GetScriptObject();

    if (TelegramAlerts)
    {
    //code for Telegram alerts to channel

    tg.Telegram(“This is Telegram Alert from Amibroker”);

    }//end Telegram alert

    _SECTION_END();

  3. _SECTION_BEGIN(“Telegram Alerts – Legacy Method”);

    TelegramAlerts = ParamTrigger(“Telegram Alert”,”Send Alert”);
    TelegramAPI_ID = ParamStr(“Telegram Bot API Key”,”727373270:AAFTaMLeQYsehpVxxxxxxxxxxxxxxI”); //Get the Bot API key via BotFather in Telgram
    TelgramCHAT_ID = ParamStr(“Telegram Channel ID”,”-100xxxxxxx”); //Channel ID example : @marketcalls_in

    //User Defined Function -> Created using VBscript
    EnableScript(“VBScript”);
    // “normal” AFL statements
    Buy=Cover=Cross(j,nw);
    Sell=Short=Cross(nw,j);

    // “normal” AFL statements
    Buy = ExRem( Buy, Sell );

    tg = GetScriptObject();

    if (TelegramAlerts)
    {
    //code for Telegram alerts to channel

    tg.Telegram(“This is Telegram Alert from Amibroker”);

    }//end Telegram alert

    _SECTION_END();

  4. Code requires Amibroker 6.17 :
    please code a sample for this:

    InternetOpenURL(“https://api.telegram.org/bot”+TelegramAPI_ID+”/sendMessage?chat_id=”+TelgramCHAT_ID+”&text=”+Message );

    i can’t run arlert this step

      1. how to send amibroker exploration signal to telegram channel.

        only ‘this is a test message from amibroker’ is sent

  5. Thank you Rajandran. I have learnt many things from this site. I could replicate the technique and able to include it along with the exploration.

    For the benefit of readers, if your script has to send M&M.NSE then you need to send M%26M.NSE

    url encoding online:
    https://www.urlencoder.io/

  6. Sir, I cud able to send test msg after writing your given code in the afl, but when some Buy Sell Signal coming on chart, that signals is not going to the telegram. pls help

  7. Hello Sir,

    It is showing below error even i added correct telegram id and api key.

    A connection with the server could not be established

  8. hi … your coding is work for me, then I try to send photo (chart from AB and local file) but it doesn’t work. Try to make via multipart data from and still doesn’t work (maybe its wrong coding). Can you give me an example how to sendphoto with caption?

    thank you
    Hayanto Hadiwijoto
    Indonesian Trader

  9. Sir, how to limit the message to be sent only one time after an indicator signal triggered? This code works but non-stop to send messages and cause amibroker nearly .

  10. Dear sir,
    When i add buy/sell trigger , the messages repeat too much, how can i solve this problem???

    Thnks you

  11. I also suffer from the same problem. Messages come non-stop. Please help solve the problem

  12. HI, Good Evening Shri Rajendran.

    Thanks for the Code. It is working fine on my system. However it is orking only on one chaRT WHICH IS OPEN AND ACTIVE AT THE TIME. hOW TO GET ALLERTS FROM DIFFERENT charts at a time.

  13. I am facing kind different error. Which is error 65 internet handle passed to internet close( ) function is invalid…

    Same code is running well on other Amibroker user tried several things but error remain same
    Could anyone replay on This..

    Thanks

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More