Telegram EOD Alert
Works with Any Long-Only AFL Strategy
Designed Exclusively for Daily Timeframe
//====================================================================
// 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();
1. Telegram Bot Setup (One-Time Process)
1.1 Create a Telegram Bot
1.2 Configure the Bot Token in OpenAlgo
1.3 Link Your Telegram Account with OpenAlgo
2. Add the Telegram Exploration Module to Your AFL Strategy
3. Create an APX (Analysis Settings File)
4. Create a Batch File (.abb)
5. Schedule Automatic Daily Execution at 6 PM IST
6. Daily Execution Workflow
Notes and Restrictions
Summary
Step
Description
Output
Last updated