Discusión sobre el artículo "Cómo crear un bot para Telegram en el lenguaje MQL5" - página 5

 
Rashid Umarov:
Andrei, ¿es necesario sustituir los códigos adjuntos en el artículo? Por favor, escriba en tales casos a los moderadores para hacerlo, ¿de acuerdo?
Sí, Rashid, es necesario actualizar el archivo con los códigos. En primer lugar escribí sobre ello al moderador hace un par de días.
 
Andrey Voytenko:
Sí, Rashid, tienes que actualizar el archivo con los códigos. Escribí al moderador al respecto hace un par de días.
El archivo del artículo ha sido actualizado. Pido disculpas por el retraso.
[Eliminado]  

¡Buenos días Andrey Voytenko! Gracias por el artículo, pero no puedo recibir y salida en mensaje de alerta de Telegram de la siguiente manera (cada vez devuelve una alerta vacía, es decir, el hecho de un nuevo mensaje es detectado, pero devuelve una variable vacía):

   void ProcessMessages(void)
     {
      for(int i=0; i<m_chats.Total(); i++)
        {
         CCustomChat *chat=m_chats.GetNodeAtIndex(i);
         //--- si el mensaje no se procesa
         if(!chat.m_new_one.done)
           {
           chat.m_new_one.done=true;
            string text=chat.m_new_one.message_text;
Alert(text);
            //--- inicio
            if(text=="/start")
               SendMessage(chat.m_id,"Hello, world! I am bot. \xF680");

            //--- ayuda
            if(text=="/help")
               SendMessage(chat.m_id,"My commands list: \n/start-start chatting with me \n/help-get help");
           }
        }
     }
 
Buenas tardes.

He intentado hacerme un bot para enviar una captura de pantalla a telegram cuando aparece una oferta.

Se envía de vez en cuando por alguna razón, ¿podría ver cuál es el problema?

sólo este archivo, que está en el archivo adjunto.
Archivos adjuntos:
 

Roman, si necesitas el bot sólo para enviar capturas de pantalla, puedes hacer esto:

1. Pide al bot @MyTelegramID_bot tu número de chat.

2. Escribe un bot sencillo que compruebe si hay novedades y envíe imágenes al chat con el ID especificado. Un ejemplo es:

#include <Telegram.mqh>
//+------------------------------------------------------------------+
//| Parámetros de entrada|
//+------------------------------------------------------------------+
input ENUM_LANGUAGES    InpLanguage=LANGUAGE_EN;//Idioma
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);

//--- actualizar gráfico
   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);

      //--- espera 30 segundos para guardar la captura de pantalla
      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);
  }

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

Gracias por este tutorial ,

Quiero hacer un bot telegrama para mt4 por favor me proporcione cualquier tutorial para esto.

Gracias

 

¿Qué tal si lees el artículo ? https://www.mql5.com/es/articles/2355

Tiene instrucciones paso a paso...

Puedes intentarlo, y si no funciona entonces postea aquí y podemos buscar la solución.

How to create bots for Telegram in MQL5
How to create bots for Telegram in MQL5
  • 2016.06.27
  • Andrey Voytenko
  • www.mql5.com
This article contains step-by-step instructions for creating bots for Telegram in MQL5. This information may prove useful for users who wish to synchronize their trading robot with a mobile device. There are samples of bots in the article that provide trading signals, search for information on websites, send information about the account balance, quotes and screenshots of charts to you smart phone.
 
Gracias Andrey Voytenko..
 
Hola yo corrí mi bot y quería enviar foto. En meta trader abre el gráfico y guardarlo . y veo bot me está enviando la foto. pero después de un momento todo se detiene poco. y no puedo recibir la foto ¿por qué?
 

Hola

en primer lugar gracias por la descripción detallada, muy apreciado.

Perdona si parece una tontería pero quería probar el Telegram_signal_EA y esperaba poder tener alertas disparadas por un indicador que se envía a un canal de Telegram, sin embargo el código que diste para esto en el tercer ejemplo, ¿fue escrito para MT4 o MT5?

Cuando copio y pego el código en un nuevo archivo en MetaEditor y compilarlo, me sale un montón de errores y no tengo ni idea de lo que significa, seguro que debería poner en el tiempo para averiguarlo todo, pero con el código dado no debería ser demasiado difícil de ser capaz de lograr lo que quiero ¿verdad?

Si alguien está dispuesto a ayudarme o me apunte en la dirección correcta realmente lo agradecería.

Saludos,

Patrick

registro de errores