Telegram EOD Alert
Works with Any Long-Only AFL Strategy
Designed Exclusively for Daily Timeframe
This document describes how to automatically run a daily AFL exploration at 6:00 PM IST and send Telegram alerts using OpenAlgo.
//====================================================================
// UNIVERSAL TELEGRAM EXPLORATION MODULE (LONG ONLY)
// Plug-and-Play for any AFL strategy that defines Buy & Sell signals
//====================================================================
_SECTION_BEGIN("Telegram Alerts (Long Only)");
// ---------- OpenAlgo / Telegram parameters ----------
tgApiKey = ParamStr("OpenAlgo API Key", "your_api_key_here");
tgUserName = ParamStr("OpenAlgo Username", "your_openalgo_username");
tgHost = ParamStr("Host", "http://127.0.0.1:5000");
tgVer = ParamStr("API Version", "v1");
tgPriority = Param("Telegram Priority", 5, 1, 10, 1);
// Build endpoint URL
tgUrl = tgHost + "/api/" + tgVer + "/telegram/notify";
// ---------- Telegram sender function ----------
function SendTelegramAlert(tgMessage)
{
global tgApiKey, tgUserName, tgPriority, tgUrl;
pstr = StrFormat("%g", tgPriority);
postBody =
"{"
+ "\"apikey\":\"" + tgApiKey + "\","
+ "\"username\":\"" + tgUserName + "\","
+ "\"message\":\"" + tgMessage + "\","
+ "\"priority\":" + pstr
+ "}";
headers =
"Content-Type: application/json\r\n"
+ "Cache-Control: no-cache\r\n"
+ "Pragma: no-cache\r\n";
InternetSetHeaders(headers);
ih = InternetPostRequest(tgUrl, postBody);
if(ih)
{
resp = "";
line = "";
while((line = InternetReadString(ih)) != "")
resp += line;
InternetClose(ih);
_TRACE("Telegram Response: " + resp);
}
else
{
_TRACE("Telegram Error: InternetPostRequest failed");
}
}
//====================================================================
// EXPLORATION BLOCK (Drop-in for any Long-Only strategy)
//====================================================================
// Show all BUY / SELL in exploration
Filter = Buy OR Sell;
// Background coloring
bgColor = IIf(Buy, colorGreen, IIf(Sell, colorRed, colorBlack));
textColor = colorWhite;
// Exploration columns
AddTextColumn(Name(), "Symbol", 1, textColor, bgColor);
AddColumn(Close, "Close", 1.2, textColor, bgColor);
AddColumn(ROC(Close,1), "% Chg", 1.2, textColor, bgColor);
AddColumn(IIf(Buy, 1, 0), "Buy", 1, textColor, bgColor);
AddColumn(IIf(Sell,1, 0), "Sell",1, textColor, bgColor);
SetSortColumns(-2); // Sort by % change
//====================================================================
// TELEGRAM ALERT TRIGGER (Only when running Exploration)
//====================================================================
if(Status("action") == actionExplore)
{
lastBuy = LastValue(Buy);
lastSell = LastValue(Sell);
if(lastBuy OR lastSell)
{
sname = Name();
// capture latest bar prices for signals
bp = LastValue( ValueWhen(Buy, Close) );
sp = LastValue( ValueWhen(Sell, Close) );
// build message
if(lastBuy AND NOT lastSell)
{
txt =
"Symbol : " + sname + "\\n"
+ "Price : " + StrFormat("%.2f", bp) + "\\n"
+ "Signal Type : BUY Signal";
}
else
{
txt =
"Symbol : " + sname + "\\n"
+ "Price : " + StrFormat("%.2f", sp) + "\\n"
+ "Signal Type : SELL Signal";
}
// send alert
SendTelegramAlert(txt);
_TRACE("Telegram Sent -> " + txt);
}
}
_SECTION_END();
This module is intended for Daily timeframe only. Lower timeframes are not supported because they require special alert suppression logic.
1. Telegram Bot Setup (One-Time Process)
This step must be completed before AmiBroker can send alerts to your Telegram.
1.1 Create a Telegram Bot
Open the Telegram app.
Search for “BotFather”.
Send the command:
/newbotChoose a bot name and username.
BotFather will respond with:
HTTP API Token: 1234567890:ABCDEF...Save this token.
1.2 Configure the Bot Token in OpenAlgo
Open the OpenAlgo desktop application.
Go to “Telegram Settings”.
Paste the Bot Token received from BotFather.
Click “Start Bot”.
Your bot is now active.
1.3 Link Your Telegram Account with OpenAlgo
In Telegram, open your bot and send:
/link <your-openalgo-api-key> http://127.0.0.1:5000Example:
/link ABCD1234XYZ http://127.0.0.1:5000If successful, the bot will respond confirming the link. Your Telegram account is now authenticated with OpenAlgo and ready to receive alerts.
2. Add the Telegram Exploration Module to Your AFL Strategy
Your strategy must contain valid daily timeframe Buy and Sell signals:
Buy = ...; // Daily timeframe signal
Sell = ...; // Daily timeframe signalBelow your strategy code, insert the Long-Only Daily Telegram Exploration Module.
This module automatically:
Detects Buy/Sell signals on the latest daily bar
Sends formatted alerts via OpenAlgo when Exploration is executed
The alert format is:
Symbol : RELIANCE
Price : 1542.00
Signal Type : BUY SignalThis module is intended for Daily timeframe only.
3. Create an APX (Analysis Settings File)
Open AmiBroker’s Analysis window.
Load your AFL containing Buy/Sell signals and the Telegram module.
Set the following:
Apply To: Filter or All Symbols
Range: 1 recent day(s)
From/To: Today
Timeframe: Daily
Click “Explore” to verify signals display as expected.
Save the analysis settings:
File → Save As…Save as:
MyStrategy_Explore.apxThe APX stores:
Formulas
Symbol list
Date range
Exploration settings
4. Create a Batch File (.abb)
Go to:
File → New → BatchClick “Insert”.
Select Action: Explore.
Browse and choose your
.apxfile.Save the batch as:
MyStrategy_Batch.abbThis batch file will run exploration automatically.
5. Schedule Automatic Daily Execution at 6 PM IST
Open:
Tools → SchedulerClick “Add Task”.
Select your batch file.
Configure:
At specific date/time: 18:00:00
Repeat: Daily (Monday–Friday)
Click “OK”.
At the scheduled time, AmiBroker will automatically execute:
The batch
The exploration
The Telegram alert module
The alerts will be delivered to your linked Telegram account via OpenAlgo
6. Daily Execution Workflow
Every day at 6 PM IST:
AmiBroker loads the APX
Runs the daily exploration
Detects Buy/Sell signals from today’s daily bar
Sends Telegram alerts via OpenAlgo
No manual intervention is required
This works only on Daily timeframe strategies.
Notes and Restrictions
This module is exclusively designed for Daily timeframe.
Intraday or lower timeframes are not supported, because they require:
Bar-level alert deduplication
StaticVar suppression
Session segmentation
AmiBroker must remain running for Scheduler tasks to execute.
OpenAlgo must remain running for Telegram API to respond.
Internet connection must remain active.
Summary
1
Create Telegram bot + authenticate via OpenAlgo
Bot ready
2
Add Telegram module to strategy AFL
AFL with alerts
3
Save analysis settings as APX
MyStrategy_Explore.apx
4
Map APX in Batch file
MyStrategy_Batch.abb
5
Schedule daily at 6 PM IST
Automatic daily alerts
When combined, this provides a reliable fully automated Daily timeframe alerting system using AmiBroker + OpenAlgo + Telegram.
Last updated
Was this helpful?