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

 

Hola,


Mi bot está enviando el mismo mensaje varias veces, ¿alguna idea de dónde está el problema? aquí está el código :<Link removed>


Gracias

 
thegosutrader:

Hola,


Mi bot está enviando el mismo mensaje varias veces, ¿alguna idea de dónde está el problema? aquí está el código :<Link removed>


Gracias

Por favor, adjunte el código aquí en lugar de enlazar a un sitio web externo.

 
Keith Watford:

Por favor, adjunte el código aquí en lugar de enlazar a un sitio web externo.

El bot está enviando el mismo mensaje varias veces, el registro dice : "Too many requests: retry after 10","parameters":{"retry_after":10}

Aquí está mi archivo mq4:

#include <Telegram.mqh>


input string InpChannelName="@xxx";//Nombre del canal
input string InpToken="1049045330:AxxxxxxbFxxx0-IxwKXyxxxxxxxx";//Bot Token


CCustomBot bot;

datetime time_signal=0;
//int SendMessage(const cadena nombre_canal,
                //const cadena texto);




//+------------------------------------------------------------------+
//| Función de inicialización experta|
//+------------------------------------------------------------------+
int OnInit()
  {
   time_signal=0;

//--- set token
   bot.Token(InpToken);


//--- hecho
   return(INIT_SUCCEEDED);
  }
 
  datetime _opened_last_time = TimeCurrent() ;
  datetime _closed_last_time = TimeCurrent()  ;
  
 

//+------------------------------------------------------------------+
//| Función de desinicialización experta|
//+------------------------------------------------------------------+
void OnDeinit(const int reason)

{

}
     
  
//+------------------------------------------------------------------+
//| Función tick experto|
//+------------------------------------------------------------------+
void OnTick()
  {
  

   string message = "";
   int total=OrdersTotal();
  
        
   for(int pos=0;pos<total;pos++){  // Pedidos actuales -----------------------
     if(OrderSelect(pos,SELECT_BY_POS)==false) continue;
     if(OrderOpenTime() <= _opened_last_time) continue;
     
     message += StringFormat("Order opened!\r\nType: %s\r\nSymbol: %s\r\nPrice: %s\r\nSL: %s\r\nTP: %s\r\nTime: %s\r\nTicket:.%s ",
     order_type(),
     OrderSymbol(),
     DoubleToStr(OrderOpenPrice(),MarketInfo(OrderSymbol(),MODE_DIGITS)),
     DoubleToStr(OrderStopLoss(),MarketInfo(OrderSymbol(),MODE_DIGITS)),
     DoubleToStr(OrderTakeProfit(),MarketInfo(OrderSymbol(),MODE_DIGITS)),
     TimeToStr(OrderOpenTime(),TIME_MINUTES),
     IntegerToString(OrderTicket())
          
      );
      
     int res=bot.SendMessage(InpChannelName,message);
     if(res!=0)
         Print("Error: ",GetErrorDescription(res));
     
     }
     
      bool is_closed = false;

  
  total = OrdersHistoryTotal();
      
   for(int pos=0;pos<total;pos++){  // Historia pedidos-----------------------
      if(OrderSelect(pos,SELECT_BY_POS,MODE_HISTORY)==false) continue;
      if(OrderCloseTime() <= _closed_last_time) continue;
     printf(OrderCloseTime());
     is_closed = true;
     
     message += StringFormat("Order closed!\r\nTicket: %s\r\nSymbol: %s\r\nClosing Price: %s\r\nTime: %s",
     IntegerToString(OrderTicket()),
     OrderSymbol(),
     DoubleToStr(OrderClosePrice(),MarketInfo(OrderSymbol(),MODE_DIGITS)),
     TimeToStr(OrderCloseTime(),TIME_MINUTES),
     DoubleToStr(order_pips(),1)
     
     
     );
      
      int res=bot.SendMessage(InpChannelName,message);
     if(res!=0)
         Print("Error: ",GetErrorDescription(res));
      
     }
 
   }
   
   
double order_pips() {
   double pips;
   
   if(OrderType() == OP_BUY) {
      pips =  (OrderClosePrice()-OrderOpenPrice())/MarketInfo(OrderSymbol(),MODE_POINT);
   } else {
      pips =  (OrderOpenPrice()-OrderClosePrice())/MarketInfo(OrderSymbol(),MODE_POINT);
   }
   return pips/10;
}

string order_type_to_str(int type)
{
   return StringSubstr(EnumToString((ENUM_ORDER_TYPE)type), 11);
}
string order_type () {
   return order_type_to_str(OrderType());
   
   if(OrderType() == OP_BUY)        return "BUY";
   if(OrderType() == OP_SELL)       return "SELL";
   if(OrderType() == OP_BUYLIMIT)   return "BUY LIMIT";
   if(OrderType() == OP_SELLLIMIT)  return "SELL LIMIT";
   if(OrderType() == OP_BUYSTOP)    return "BUYSTOP";
   if(OrderType() == OP_SELLSTOP)   return "SELLSTOP";
   
   return "{err}";
}
   

   
//---

Gracias

 
Antonio Vargas:

Hola!, lo he conseguido hacer ya que también funcionan en canales privados, todo está en el Telegram.mqh, hay una parte en el archivo donde se encuentran las "@", lo que he hecho ha sido sustituirlas por "-", y a la hora de colocar el nombre del canal con la variable InpChannelName allí colocar lo siguiente "-10014749xxxxx", el token del canal con el bot

Hola,

Para los que quieran enviar a un canal privado

1) sustituir la "@" por "-" en el Telegram.mqh en la línea 1009 y línea 1010 (ver imagen adjunta),

2) en el archivo mq4, pones el token de tu canal empezando por -1000xxxx así: InpChannelName="-10000xxxx";//Nombre del canal

y deberias recibir los mensajes despues de poner tu canal como privado.

Buena suerte.

Archivos adjuntos:
 

Hola,


Para los múltiples mensajes enviados, este es el mensaje de error que estoy recibiendo en MT4 diario :


{"ok":false, "error_code":429, "description": "Demasiadas solicitudes: reintentar después de 11","parameters":{"retry_after":11}}


y


Error: Error desconocido 66965


Gracias por su ayuda.

 
thegosutrader:

Hola,

Para aquellos que quieran enviar a un canal privado,

1) sustituir la "@" por "-" en el Telegram.mqh en la línea 1009 y línea 1010 (ver imagen adjunta),

2) en el archivo mq4, pones el token de tu canal empezando por -1000xxxx así: InpChannelName="-10000xxxx";//Nombre del Canal

y deberías recibir los mensajes después de configurar tu canal como privado.

Buena suerte.

Entonces, si ya he configurado el canal privado cambiando "@" por "-", cuando quiera enviar al canal público, ¿tendré que volver a cambiarlo?


Gracias

 
Agus Wahyu Pratomo:

Entonces, si ya he configurado el canal privado cambiando "@" por "-", cuando quiera enviar a un canal público, ¿tendré que volver a cambiarlo?


Gracias

Sí, supongo, pero no soy un codificador, así que creo que hay una manera de enviar a público y privado al mismo tiempo ...
 
¿Es posible utilizar un bot para obtener datos de canales de Telegram en los que no se puede añadir como administrador? Si es posible, ¿cómo se hace?
 
¡¡¡Post de 2016 pero aún muy actual, para los que empiezan...es excelente!!!
 

Hola Andrey, por favor estoy recibiendo HTTP request failed


Por favor ayuda


Gracias

Archivos adjuntos: