文章 "如何采用 MQL5 创建用于 Telegram 的 bots" - 页 15

 
Andrey Voytenko:

好的。但如果您使用的是私人频道,请使用频道 ID,而不是频道名称。

你好,安德烈


您的 mt5 库似乎无法在电报异步模式下工作。


当 mt5 机器人在同一时刻发送两条信息时,其中一条信息会丢失。


我测试了很多次,您能解决这个问题吗?

 

你好, 安德烈


首先非常感谢您抽出宝贵的时间,您的文章对我帮助很大,我已经阅读了所有的出版物。

通过阅读,我终于能够在 MT5 中使用 "Telegram_Bot_EA"。

在尝试将 "Telegram_Signal_EA "导入 MT5 时,我无法使用 "MA "或 "MACD "或自定义指标 发送任何信号。

但是我知道它配置得很好,因为我可以使用 "Telegram_Bot_EA"。

我查看了 EA 和 telegram.mqh 的代码,没有发现问题所在,我被卡住了。EA(Telegram_Signal_EA) 无法发送任何文本信息。

您能帮帮我吗?

在这个论坛上,我看到了这段代码,但我认为这不是我的问题:

   //+------------------------------------------------------------------+
   int SendMessage(const string _channel_name,
                   const string _text,
                   const bool   _as_HTML=false,
                   const bool   _silently=false)
     {
      //--- 检查令牌
      if(m_token==NULL)
         return(ERR_TOKEN_ISEMPTY);

      string name=StringTrim(_channel_name);
      if(StringGetCharacter(name,0)!='@')
         name="@"+name;

      string out;
      string url=StringFormat("%s/bot%s/sendMessage",TELEGRAM_BASE_URL,m_token);
      string params=StringFormat("chat_id=%s&text=%s",name,UrlEncode(_text));
      if(_as_HTML)
         params+="&parse_mode=HTML";
      if(_silently)
         params+="&disable_notification=true";
      // Print(params);
      int res=PostRequest(out,url,params,WEB_TIMEOUT);
      return(res);
     }

   //+------------------------------------------------------------------+


注:我确定它能运行,因为 "Telegram_Bot_EA "运行良好。


还有一个:

//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam)
  {
   if(id==CHARTEVENT_KEYDOWN && 
      lparam=='Q')
     {
         
         bot.SendMessage(InpChannelName,"ee\nAt:100\nDDDD");
     }
  }

注:我在机器人聊天或频道聊天中按 "Q "键,但不起作用....,我想如果你按下这个键,机器人就会向你发送文本......对吗?这个选项不起作用。我不明白...编译所有 mql5 代码时都没有任何错误或警告。


简历: 我想向电报发送有关您的示例指标或我的自定义指标规则的文本信号(买入/卖出),但我不明白为什么不起作用。


谢谢您,祝您愉快。


更新1(已解决)


我检查了日志,得到以下信息

HL 0 06:24:00.729 Telegram_Signal_EAEVO (DE30,M1) Error:错误请求

LH 0 06:40:00.916 Telegram_Signal_EAEVO (DE30,M1) {"ok":false, "error_code":400, "description": "Bad Request: chat not found"}

RG 0 06:40:00.916 Telegram_Signal_EAEVO (DE30,M1) Error:错误:错误请求

KQ 0 07:31:00.442 Telegram_Signal_EAEVO (DE30,M1) {"ok":false, "error_code":400, "description": "Bad Request: chat not found"}

MO 0 07:31:00.442 Telegram_Signal_EAEVO (DE30,M1) Error:错误请求

我添加了一个新的父亲,并解决了上次的错误,但还是无法向机器人发送消息...

EF 0 12:26:44.372 Telegram_Signal_EAEVO (DE30,H1) NAME_bot:NAMEsignalsbot


更新2(已解决):

我查看了此链接http://usefulmix.com/send-message-telegram-channel-bot-http-api/


在文本中 :


因此,我们需要将该频道设为私有频道,但这样一来,上述 HTTP API 调用将停止工作,这就是尝试发布消息的结果:


{
  "ok": false,
  "error_code": 400,
  "description": "Bad Request: chat not found"
}

我使用 url 样本进行了检查,结果如下:

        
ok      false
error_code      404
description     "Not Found"


在 common.mqh 中列出了这个错误,但我对此很迷茫....,我需要进一步研究。

问题 "出在转换令牌上,我编写并键入了这段代码进行测试,而机器人却写给了我:

//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+

//Original code:

// {
// 
// if(id==CHARTEVENT_KEYDOWN && lparam=="Q")
//bot.SendMessage(InpChannelName, "ee\nAt:100\nDDDD");
//}

// 测试代码:

 {

  
   if(id==CHARTEVENT_KEYDOWN && 
      lparam=="Q")
   
      //--- 设置标记
   bot.Token(InpToken);
    bot.SendMessage("ID CHAT OR USER","ITS A TEST!");

}
     

图像:

我又读了一遍总的帖子,因为有一个人谈到了这个问题。


TO UPDATE 3!

How to send a message to a Telegram channel using the HTTP bot sendMessage API
How to send a message to a Telegram channel using the HTTP bot sendMessage API
  • 2018.10.08
  • admin
  • usefulmix.com
Here’s a practical example how to send a message to a Telegram channel using a Telegram Bot and the HTTP bot sendMessage API. In order to be able to do so, you will have to the following: Create a Telegram public channel (we’ll make this private later) Create a Telegram BOT via BotFather Set the bot as administrator in your channel After...
 

您好,请确保导入 telegram.mqh 并在此处查看:

https://www.mql5.com/en/forum/285054/page2#comment_11220261

MT4 to Telegram
MT4 to Telegram
  • 2019.04.04
  • www.mql5.com
Can anyone code or have any idea how to send trade details from MT4 to a Telegram channel. This is the sort of thing I am talking about. Thanks...
 
Marco vd Heijden:

Hola, asegúrese de importar telegram.mqh y vea aquí:

https://www.mql5.com/en/forum/285054/page2#comment_11220261

我检查一下......我需要时间......稍后我会给您写信。谢谢!!!!!
 

非常感谢 Nguyen Van Tuan,
现在,它可以在私人频道工作了。之前,我的机器人只能在公共频道工作。

谨致问候,
Junior


Nguyen Van Tuan:

你好、

当我使用Andrey Voytenkoon MT5 的这个库进行测试时,效果并不好,所以我有一些更简单的步骤。遇到相同错误的人可以像我一样尝试更改:

1.确认将https://api.telegram.org 添加为允许对列出的 URL 进行 WebRequest 访问

2.当您使用 chat_id(如"-1001301234105")代替 @channel_name 时,这段代码会出错,所以我做了修改

做完以上两件事后,我确认这个库在 MT5 中运行良好。

再次感谢Andrey Voytenko

 

对同样的问题!!!!



Junior:

非常感谢 Nguyen Van Tuan,
现在,它可以在私人频道工作了。之前,我的机器人只能在公共频道工作。

谨致问候,
Junior


 
您好

我有一个从 MT4 向 Telegram 发送信息的脚本,我尝试将其转换为 MQL5,但失败了,我通过本论坛请求帮助,将 MQ4 文件格式转换为 MQL5,以便进一步学习 .....。

我包含的文件


感谢愿意提供帮助的人



附加的文件:
 

你好,我更新了 metatrader v 并重新编译了代码,但却收到了警告:


MT5 5.00 build:2170 4 / oct / 2019:

"" 过时行为,在未来版本的 MQLTelegram.mqh 编译器中将禁用对隐藏方法的调用 ""


引用调用:"StringReplace"


我正在寻找替代方案,但目前还没有找到。在未来的修订版 ..... 中,有什么想法吗?


谢谢


代码


 //+------------------------------------------------------------------+
   void UserNameFilter( const string username_list)
     {
      m_users_filter.Clear();

       //--- 解析
       string text=StringTrim(username_list);
       if (text== "" )
         return ;

       //---
       while ( StringReplace (text, "  " , " " )> 0 );
       StringReplace (text, ";" , " " );
       StringReplace (text, "," , " " );
      

       //---
       string array[];
       int amount= StringSplit (text, ' ' ,array);
       for ( int i= 0 ; i<amount; i++)
        {
         string username=StringTrim(array[i]);
         if (username!= "" )
           {
             //--- 删除第一个 @
             if ( StringGetCharacter (username, 0 )== '@' )
               username= StringSubstr (username, 1 );

            m_users_filter.Add(username);
           }
        }

     }
   //+------------------------------------------------------------------+ 
 
satrifx7:
你好

我有一个从 MT4 向 Telegram 发送信息的脚本,我尝试将其转换为 MQL5,但失败了,我通过本论坛请求帮助,将 MQ4 文件格式转换为 MQL5,以便进一步学习 .....。

我包含的文件


感谢愿意提供帮助的人



您不需要转换代码。该代码可以在两个版本中运行,请再次查看帖子或代码。
 
odlambda:

你好,我更新了 metatrader v 并重新编译了代码,但却收到了警告:

请在论坛中只使用英语。

这次我用网站工具编辑并翻译了您的帖子