The article describes an example of creating a class for working with the trade server return codes and all the errors that occur during the MQL-program run. Read the article, and you will learn how to work with classes and objects in MQL5. At the same time, this is a convenient tool for handling errors; and you can further change this tool according to your specific needs.
我回复的时候还没有代码,我知道你可以用一个将信息添加到突发列表的函数来替换 bot.SendMessage 函数。你也可以不断增加信息并将其从循环中发送出去,但这样会受到字符数的限制。
一个简单的示意图可以是这样的
感谢您的回复,我会尝试您的方法
您好!
例如,要使用粗体字体,您需要在 Telegram.mqh 中启用 HTML 发送功能。
然后用 <b> 标签发送文本。
Never mind....
我通过将 AsHTML 标志设置为 true 找到了答案......
bot.SendMessage(InpTelegramId,"<b>Balance: $10056.21</b>",true);
抱歉...
您好,能分享一下如何实现这一功能的代码吗?我还在寻找将文本加粗、斜体并发送到电报服务器的代码。
在发送 .gif 文件时,我收到错误 400,说明 SendPhoto() 函数中的 某个函数不工作(我使用的是<Telegram.mqh> 文件 655 行中三个函数模型中的第二个),能否请您更新代码使其工作?
Roman,如果您只需要机器人发送截图,您可以这样做:
1.向 @MyTelegramID_bot 询问您的聊天号码。
2.编写一个简单的机器人,检查是否有新项目,并将图片发送到指定 ID 的聊天室。例如
//+------------------------------------------------------------------+
//| 输入参数|
//+------------------------------------------------------------------+
input ENUM_LANGUAGES InpLanguage=LANGUAGE_EN;//语言
input string InpToken="";//代币
input long ChatId=0; //聊天 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);
//--- 更新图表
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);
//--- 等待 30 秒以保存屏幕截图
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);
}
//+------------------------------------------------------------------+
大家好、
我正试图使用机器人从 MT5 向 Telegram 发送信息。但是,由于出现错误,我无法从 MT5 向 Telegram 发送消息:错误代码 400 说明 "错误请求:未找到聊天"。
有人遇到过同样的问题吗?您能解释一下为什么会出现这种错误吗?
我在网上做了很多研究,但没有得到正确的答案。
关于交易、自动交易系统和测试交易策略的论坛
在 telegram 消息中添加表情符号。
Frédéric LEBRE, 2023.12.04 13:56
您好、
请帮帮我。
我尝试使用 emoji 向 telegram 发送信息。
当 emoji unicode 为 U+2702 时,我使用字符串值 " \x2702" 并成功发送。
SendTelegramMessage(TelegramApiUrl, TelegramBotToken, ChatId, "\x2702");
但当 unicode 像这样 :U+1F648 时却不起作用。
我在主题中看到了 <Telegram.mqh>,但我不知道如何做得更多。
感谢您的解答。
我找到了方法,如果有人感兴趣,请向我咨询)。
找到方法了,有兴趣的人可以问问 )
你可以直接写下来。这样别人就不用找你问了。