
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
Andrei, do you need to replace the attached codes in the article? Please write in such cases to moderators to do it, okay?
Yes, Rashid, you need to update the archive with the codes. I first wrote to the moderator about it a couple of days ago.
Good day Andrey Voytenko! Thanks for the article, but I can not receive and output in Alert message from Telegram in the following way (each time returns an empty alert, that is, the fact of a new message is detected, but returns an empty variable):
{
for(int i=0; i<m_chats.Total(); i++)
{
CCustomChat *chat=m_chats.GetNodeAtIndex(i);
//--- if the message is not processed
if(!chat.m_new_one.done)
{
chat.m_new_one.done=true;
string text=chat.m_new_one.message_text;
Alert(text);
//--- start
if(text=="/start")
SendMessage(chat.m_id,"Hello, world! I am bot. \xF680");
//--- help
if(text=="/help")
SendMessage(chat.m_id,"My commands list: \n/start-start chatting with me \n/help-get help");
}
}
}
I tried to make a bot for myself to send a screenshot to telegram when a deal appears.
It is sent every once in a while for some reason, could you see what the problem is?
only this file, which is in the attachment.
Roman, if you need the bot only for sending screenshots, you can do this:
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);
}
//+------------------------------------------------------------------+
Thanks for this tutorial ,
I want to make a telegram bot for mt4 please provide me any tutorial for this.
Thanks
How about reading the actual article? https://www.mql5.com/en/articles/2355
It has step-by-step instructions...
You can try it, and if it does not work then post here and we can search for the solution.
Hi,
first of all thanks for the detailed description, much appreciated.
Forgive if this sounds silly but I wanted to try the Telegram_signal_EA and was hoping I could have alerts fired by an indicator being sent to a Telegram channel, however the code you gave for this in the third example, was it written for MT4 or MT5?

When I copy and paste the code into a new file in MetaEditor and compile it, I get a whole bunch of errors and I have no clue what it means, sure I should put in time to figure it all out, but with your given code it shouldn't be all too difficult to be able to achieve what I want right?
If anyone is willing to help me out or point me in the right direction I would really appreciate that.
Best regards,
Patrick