Discussion of article "How to create bots for Telegram in MQL5" - page 52

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
There was no code when i replied , i see that you can replace the bot.SendMessage with a function that adds the message to a burst list . You could also keep growing the message and send it out of the loop but you would hit character limitations there.
A brief schematic could be like this :
Thank you for replying. I will try your way
Hello!
For example for bold font you need to enable HTML sending in Telegram.mqh.
And then send text in <b> tag.
Never mind....
I found the answer by setting AsHTML flag to true...
bot.SendMessage(InpTelegramId,"<b>Balance: $10056.21</b>",true);
Sorry...
Hi, can u share the code on how to do that ? I am also searching for the code to make the Text Bolded and in Italic style and send to telegram server.
.
Roman, if you need the bot only for sending screenshots, you can do it this way:
1. Ask the @MyTelegramID_bot for your chat number.
2. Write a simple bot that will check for new items and send pictures to the chat with the specified ID. An example is:
//+------------------------------------------------------------------+
//| Input parameters|
//+------------------------------------------------------------------+
input ENUM_LANGUAGES InpLanguage=LANGUAGE_EN;//Language
input string InpToken="";//Token
input long ChatId=0; //Chat ID
//---
CCustomBot bot;
int pos_count;
//+------------------------------------------------------------------+
int OnInit()
{
bot.Token(InpToken);
int res=bot.GetMe();
if(res!=0)
{
Print(GetErrorDescription(res));
}
pos_count=PositionCount(_Symbol);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
void OnTick()
{
int pos_count_new=PositionCount(_Symbol);
if(pos_count_new>pos_count)
{
pos_count=pos_count_new;
int result=SendScreenShot(ChatId,_Symbol,0,NULL);
if(result!=0)
Print(GetErrorDescription(result,InpLanguage));
}
}
//+------------------------------------------------------------------+
int PositionCount(const string _symbol)
{
int count=0;
int orders_total=OrdersTotal();
for(int i=0; i<orders_total; i++)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
PrintError(ERR_ORDER_SELECT);
return(-1);
}
//---
if(_symbol==NULL || OrderSymbol()==_symbol)
count++;
}
//---
return(count);
}
//+------------------------------------------------------------------+
int SendScreenShot(const long _chat_id,
const string _symbol,
const ENUM_TIMEFRAMES _period,
const string _template=NULL)
{
int result=0;
long chart_id=ChartOpen(_symbol,_period);
if(chart_id==0)
return(ERR_CHART_NOT_FOUND);
ChartSetInteger(ChartID(),CHART_BRING_TO_TOP,true);
//--- update chart
int wait=60;
while(--wait>0)
{
if(SeriesInfoInteger(_symbol,_period,SERIES_SYNCHRONIZED))
break;
Sleep(500);
}
if(_template!=NULL)
if(!ChartApplyTemplate(chart_id,_template))
PrintError(_LastError,InpLanguage);
ChartRedraw(chart_id);
Sleep(500);
ChartSetInteger(chart_id,CHART_SHOW_GRID,false);
ChartSetInteger(chart_id,CHART_SHOW_PERIOD_SEP,false);
string filename=StringFormat("%s%d.gif",_symbol,_period);
if(FileIsExist(filename))
FileDelete(filename);
ChartRedraw(chart_id);
Sleep(100);
// if(ChartScreenShot(chart_id,filename,800,600,ALIGN_RIGHT))
if(ChartScreenShot(chart_id,filename,1024,768,ALIGN_RIGHT))
{
Sleep(100);
bot.SendChatAction(_chat_id,ACTION_UPLOAD_PHOTO);
//--- waitng 30 sec to save screenshot
wait=60;
while(!FileIsExist(filename) && --wait>0)
Sleep(500);
//---
string screen_id;
result=bot.SendPhoto(_chat_id,filename,screen_id,_symbol+"_"+StringSubstr(EnumToString(_period),7));
}
ChartClose(chart_id);
return(result);
}
//+------------------------------------------------------------------+
Hi everyone,
I am trying to send a message from MT5 to Telegram using a bot. However, I could not send the message from MT5 to Telegram due to the error: Error Code 400 Description "Bad request: chat not found"
Has anyone encountered the same problem? Can you give some reasons why this error might have occurred?
I did a lot of research online, but I could not get the right answers.
Forum on trading, automated trading systems and testing trading strategies
Adding emoji in telegram messages.
Frédéric LEBRE, 2023.12.04 13:56
Hello,
Please could you help me.
I try to send a message to telegram using emoji.
when emoji unicode is for example : U+2702 i use as string value " \x2702" and if works.
SendTelegramMessage(TelegramApiUrl, TelegramBotToken, ChatId, "\x2702");
But when unicode is like this : U+1F648 nothing works.
I included <Telegram.mqh> as i read in topics, but i do not know how to do more.
Thx for your answers.
I found how to do it, if anyone is interested, please ask me).
Found how to do it, anyone interested ask )
You could just write it down. So that others do not need to look for you and ask.