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

 
Valeriy Yastremskiy #:

Yes, I don't get it, I don't know, I can't send to bot by name either, only by ID. How do you send it to yourself? Or rather, how do you get your id in the cart? I only get it to the bot.

I get any ID through the bot Get My ID

 
Andrey Kaunov #:

I get any ID through the Get My ID bot.

Yes, mixed up my id and the bot. We send to ourselves in a private message from our own bot))))

From Andrei's article

It should be noted that in these examples we pass the chat_id as the recipient of the message. We can't know it in advance to send a message to the user until he/she starts chatting with the bot first. There is also no way to contact the user by their mobile phone number or @username. This is done, obviously, for security purposes, so that bots do not send spam. But bots can publish messages on the channel by addressing the user by his/her name using the second SendMessage option.

 

Hello,

I am trying to add a new language to Search file but I have these hex parameters that I don't understand the meaning:

TLanguage languages[6]=
{
   {"English","\xF1EC\xF1E7","en"},
   {"Русский","\xF1F7\xF1FA","ru"},
   {"中文",    "\xF1E8\xF1F3","zh"},
   {"Español","\xF1EA\xF1F8","es"},
   {"Deutsch","\xF1E9\xF1EA","de"},
   {"日本語",   "\xF1EF\xF1F5","ja"}
};

What is that \xF1EC\xF1E7 in the english, for example, and how to convert it to obtain pt flag?

 

I had some glitch last week - the function of reading message queue from Telegram stopped working. I.e. outgoing messages are sent as before, both text and screenshots, but the GetUpdates() function returns nothing, the chat queue is always empty.

Has anyone encountered such a glitch? What can be the reason?

 
Hello!
Thank you so much for this kind of work!!!!
Could you please tell me how to change font, background, text colour?
Thanks
 
lbgraf #:
Hello!
Thank you so much for this kind of work!!!!
Could you please tell me how to change font, background, text colour?
Thanks

All tags are described in the docs on Telegram API.

 

hello guys,

I have completed the code for sending message from telegram to mt5 but i am having a small error, when sending close command of many close commands at the same time, it can only send one order but not many orders.

Can anyone help me see where I'm going wrong?

//--- now process the list of closed positions
   max_time = 0;
   double day_profit = 0;
   bool is_closed = false;
   int totalhis = hist_position.PositionsTotal();
   for(int i = 0; i < totalhis; i++) {
      //---
      pos_symbol = PositionGetSymbol(i); // Get the symbol name
      digits = (int)SymbolInfoInteger(pos_symbol, SYMBOL_DIGITS); // Get the number of digits in the price
      //--- Select a closed position by its index in the list
      if(hist_position.SelectByIndex(i)) {
         ulong    ticket            = hist_position.Ticket();
         datetime time_open         = hist_position.TimeOpen();
         ulong    time_open_msc     = hist_position.TimeOpenMsc();
         datetime time_close        = hist_position.TimeClose();
         ulong    time_close_msc    = hist_position.TimeCloseMsc();
         long     type              = hist_position.PositionType();
         string   type_desc         = hist_position.TypeDescription();
         long     magic             = hist_position.Magic();
         long     pos_id            = hist_position.Identifier();
         double   volume            = hist_position.Volume();
         double   price_open        = hist_position.PriceOpen();
         double   price_sl          = hist_position.StopLoss();
         double   price_tp          = hist_position.TakeProfit();
         double   price_close       = hist_position.PriceClose();
         double   commission        = hist_position.Commission();
         double   swap              = hist_position.Swap();
         double   profit            = hist_position.Profit();
         string   symbol            = hist_position.Symbol();
         string   open_comment      = hist_position.OpenComment();
         string   close_comment     = hist_position.CloseComment();
         string   open_reason_desc  = hist_position.OpenReasonDescription();
         string   close_reason_desc = hist_position.CloseReasonDescription();
         string   deal_tickets      = hist_position.DealTickets(",");
         //---
         int      deals_count       = HistoryDealsTotal();   // of the selected position
         int      orders_count      = HistoryOrdersTotal();  // of the selected position
         
         if(TimeToString(TimeCurrent(), TIME_DATE) == TimeToString(time_close, TIME_DATE)) {
            day_profit += profit + swap + commission;
         }
         if(time_close <= _closed_last_time) continue;
         //is_closed = true;
         string msg = StringFormat
                      (
                         "ACCOUNT: { #%s } \n" +
                         "------------ { CLOSE } -----------\n" +
                         "CLOSE ORDER - %s %s\n" +
                         "Time (GTM+0): %s\n" +
                         "------------ { CLOSE } -----------\n" +
                         "Volume: %s\n" +
                         "Open Price: %s\n" +
                         "Close Price: %s\n" +
                         "Gain/Loss: %s USD\n" +
                         "---TOTAL PROFIT TODAY---\n" +
                         "%s USD\n",
                         IntegerToString(login),
                         symbol,
                         PositionTypeToString(type),
                         TimeToString(time_close, TIME_DATE | TIME_SECONDS),
                         DoubleToString(volume, 2),
                         DoubleToString(price_open, digits),
                         DoubleToString(price_close, digits),
                         DoubleToString(profit, 2),
                         DoubleToString(day_profit, 2)
                      );
         
         int res = bot.SendMessage(InpChannelName, msg);
         if(res != 0)
            Print("Error: ", GetErrorDescription(res));
         max_time = MathMax(max_time, time_close);
      }
      _closed_last_time = MathMax(max_time, _closed_last_time);
   }
 
Bui Huy Dat #:

hello guys,

I have completed the code for sending message from telegram to mt5 but i am having a small error, when sending close command of many close commands at the same time, it can only send one order but not many orders.

Can anyone help me see where I'm going wrong?

Improperly formatted code removed by moderator. @Bui Huy Dat Please EDIT your post and use the CODE button when you insert code.

If you are serving many users via the bot there is a 30 interactions per second limit i think 

 
Lorentzos Roussos #:

If you are serving many users via the bot there is a 30 interactions per second limit i think 

I only use it personally and only to send each mt5 account to telegram.
but when opening or closing the command at the same time, it can only send one message to telegram

 
Bui Huy Dat #:

I only use it personally and only to send each mt5 account to telegram.
but when opening or closing the command at the same time, it can only send one message to telegram

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 : 

  1. You have a string array called "Outbox"
  2. A time interval within which you process the Outbox , so "OnTimer()" (you may already be using it if you are reading from telegram too)
  3. You then enforce -yourself- a milliseconds limit between each message not with the Sleep() function but by remembering when the last message was sent
  4. You can use GetTickCount() for polling milliseconds and you would store the last ms that the message left and subtract it from the current ms to get the distance in time.There is a very very very rare occasion here that the end time is < than the start time in which case you do this : (UINT_MAX-start_time+end_time)
  5. If your distance in milliseconds since the last message is bigger than the limit in milliseconds you enforce then you send the next message from the Outbox
  6. Instead of calling bot.SendMessage in the loop you now call Outbox.add_message_for_sending or something.
  7. With a modification that also stores the chat ids you could also store where the message is going and that would be the solution for multiple users.