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

 

Aimak:

I would appreciate if you could help me finding the error. Thanks in advance.

Switch your channel to public mode. Or using chatID (not channel name) for communication with your private channel.

 
Aimak:

The channel is public and I getting the same result using channel name or ID. See screenshot

Do you use the latest release of Telegram.mqh and Jason.mqh?

 

Dear Andrey, 

thanks a lot for your work. I've installed your files and configured an expert that does the following:

1) the expert sends messages to the bot every x minutes (just for test) ,

2) i read the message on telegram and click "open trade" on the keyboard of telegram client,

3) the metatrader opens the trade (if possible).

Everything works fine but after a while the bot is not anymore reachable; to make it work again i have to wake up him by pressing some command on the keyboard menu (for example charts or /start or account info....). The metatrader says "bad request:chat not found" but if I wake up the bot again it works perfectly for one hour or more but then it stops.

I've created the bot as you have suggested (with botFather). How can I solve this issue?

Thanks again

Files:
error.gif  26 kb
 

Hi Andrey,

why the bot keep getting Error: HTTP request failed, tq

 

Hi Andrey,

why the bot keep getting Error: HTTP request failed, tq


 

Maybe they changed the protocol.

Have you checked Telegram API ?

 
Haijie Qi:

Hi Andrey,

why the bot keep getting Error: HTTP request failed, tq

I debugged the 'Telegram_Bot_EA' on your PC using TeamViewer and have found that WebRequest() returned -1. _LastError = 5203.

But I dont know why. Perhaps your firewall blocks TCP packets.

 
Andrey Voytenko:

I debugged the 'Telegram_Bot_EA' on your PC using TeamViewer and have found that WebRequest() returned -1. _LastError = 5203.

But I dont know why. Perhaps your firewall blocks TCP packets.


thanks Andrey, 

 turn off firewall still error,

i will look more deep :) 

 

Hey guys, so basically I have taken the source code and basically edited the code for the telegram_signal_EA to send trades based off my strategy. So I compiled to check for errors and everything works fine even when I apply the EA to the chart the experts tab shows that its recognized my telegram bot. Now my issue lies in sending the alert itself, I am not receiving alerts to telegram when my rules for a trade are met. Any help on this guys? Here's the code below

//+------------------------------------------------------------------+
//|                                           Telegram_Signal_EA.mq5 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property strict

#include <Telegram.mqh>

//--- input parameters
input string InpChannelName="ForexSignalChannel";//Channel Name
input string InpToken="";//Token

//--- global variables
CCustomBot bot;
int ema_handle;
int ema2_handle;
int rsi_handle;
datetime time_signal=0;
bool checked;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   time_signal=0;

   bot.Token(InpToken);

#ifdef __MQL5__   
   ema_handle=iMA(NULL,0,200,0,MODE_EMA,PRICE_CLOSE,0);
   if(ema_handle==INVALID_HANDLE)
      return(INIT_FAILED);
      
   ema2_handle=iMA(NULL,0,400,0,MODE_EMA,PRICE_CLOSE,0);
   if(ema2_handle==INVALID_HANDLE)
      return(INIT_FAILED);
      
   rsi_handle=iRSI(NULL,0, 14,PRICE_CLOSE,0);
   if(ema2_handle==INVALID_HANDLE)
      return(INIT_FAILED);
//--- add the indicator to the chart
   int total=(int)ChartGetInteger(0,CHART_WINDOWS_TOTAL);
   ChartIndicatorAdd(0,total,macd_handle);
#endif   

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   if(reason==REASON_PARAMETERS ||
      reason==REASON_RECOMPILE ||
      reason==REASON_ACCOUNT)
     {
      checked=false;
     }

//--- delete the indicator
#ifdef __MQL5__ 
   int total=(int)ChartGetInteger(0,CHART_WINDOWS_TOTAL);
   for(int subwin=total-1; subwin>=0; subwin--)
     {
      int amount=ChartIndicatorsTotal(0,subwin);
      for(int i=amount-1; i>=0; i--)
        {
         string name=ChartIndicatorName(0,subwin,i);
         if(StringFind(name,"MACD",0)==0)
            ChartIndicatorDelete(0,subwin,name);
        }
     }
#endif
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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");
     }
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

   if(!checked)
     {
      if(StringLen(InpChannelName)==0)
        {
         Print("Error: Channel name is empty");
         Sleep(10000);
         return;
        }

      int result=bot.GetMe();
      if(result==0)
        {
         Print("Bot name: ",bot.Name());
         checked=true;
        }
      else
        {
         Print("Error: ",GetErrorDescription(result));
         Sleep(10000);
         return;
        }
     }

//--- get time
   datetime time[1];
   if(CopyTime(NULL,0,0,1,time)!=1)
      return;

//--- check the signal on each bar
   if(time_signal!=time[0])
     {
      //--- first calc
      if(time_signal==0)
        {
         time_signal=time[0];
         return;
        }

     double ema = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, 0);
      double ema2 = iMA(NULL, 0, 400, 0, MODE_EMA, PRICE_CLOSE, 0); 
      double rsi = iRSI(NULL, 0, 14, PRICE_CLOSE, 0);


      time_signal=time[0];

      //--- Send signal BUY
      if ((Bid > ema)&&(Bid < ema2)&&(rsi < 30))
      
        {
         string msg=StringFormat("Name: BossPips Signal\xF4E3\nSymbol: %s\nTimeframe: %s\nType: Buy\nPrice: %s\nTime: %s",
                                 _Symbol,
                                 StringSubstr(EnumToString((ENUM_TIMEFRAMES)_Period),7),
                                 DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits),
                                 TimeToString(time[0]));
         int res=bot.SendMessage(InpChannelName,msg);
         if(res!=0)
            Print("Error: ",GetErrorDescription(res));
        }

      //--- Send signal SELL
      
       if ((Bid < ema)&&(Bid > ema2)&&(rsi > 70))
       
        {
         string msg=StringFormat("Name: BossPips Signal\xF4E3\nSymbol: %s\nTimeframe: %s\nType: Sell\nPrice: %s\nTime: %s",
                                 _Symbol,
                                 StringSubstr(EnumToString((ENUM_TIMEFRAMES)_Period),7),
                                 DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits),
                                 TimeToString(time[0]));
         int res=bot.SendMessage(InpChannelName,msg);
         if(res!=0)
            Print("Error: ",GetErrorDescription(res));
        }
     }
  }
//+------------------------------------------------------------------+
 
Any version for mq4?
Reason: