Discusión sobre el artículo "Cómo crear un bot para Telegram en el lenguaje MQL5" - página 5
Está perdiendo oportunidades comerciales:
- Aplicaciones de trading gratuitas
- 8 000+ señales para copiar
- Noticias económicas para analizar los mercados financieros
Registro
Entrada
Usted acepta la política del sitio web y las condiciones de uso
Si no tiene cuenta de usuario, regístrese
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, tienes que actualizar el archivo con los códigos. Escribí al moderador al respecto hace un par de días.
¡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):
{
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");
}
}
}
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.
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:
//+------------------------------------------------------------------+
//| 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.
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