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:
Choose a bot name and username.
BotFather will respond with:
Save this token.
1.2 Configure the Bot Token in OpenAlgo
Open OpenAlgo in your browser (default
http://127.0.0.1:5000).Go to the Telegram Bot page at
/telegram, then open Configuration (/telegram/config).Paste the Bot Token received from BotFather and click “Save Configuration”.
Return to
/telegramand click “Start Bot”.
Your bot is now active. The bot has to stay started: /api/v1/telegram/notify rejects requests with HTTP 409 while the bot is stopped, so a scheduled exploration will run but no alert will be delivered.
1.3 Link Your Telegram Account with OpenAlgo
In Telegram, open your bot and send:
Example:
If 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:
Below 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:
This 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:
Save as:
The APX stores:
Formulas
Symbol list
Date range
Exploration settings
4. Create a Batch File (.abb)
Go to:
Click “Insert”.
Select Action: Explore.
Browse and choose your
.apxfile.Save the batch as:
This batch file will run exploration automatically.
5. Schedule Automatic Daily Execution at 6 PM IST
Open:
Click “Add Task”.
Select your batch file.
Configure:
At specific date/time: 18:00:00
Repeat: Daily (Monday to 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.
The Telegram bot must be started in OpenAlgo. If it is stopped,
POST /api/v1/telegram/notifyreturns HTTP 409 and nothing is delivered.The OpenAlgo Username parameter must match the OpenAlgo account that ran
/linkin Telegram. If no linked user matches, the API returns HTTP 404.Telegram Priority is clamped to the range 1 to 10; anything outside it falls back to 5.
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