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

 
Nicholas Martins:

Thanks for sharing this code!

I just have a small issue, one of my brokers has lowercase letter on some symbols like EURUSDm, GBPUSDm, XAUUSDm...s 

Did you try Just sending without the m

or better yet this 

#include <Telegram.mqh>
input sring InpChannel;
input string InpToken;
void OnStart()
    {
        bot.Token(InpToken);
        string msg = "This currency pair/symbol is called: "+Symbol();
        bot.sendmessage(InpChannel, msg);
    }
 
Roman Zhitnik:

Most likely the error is that the Telegram apiche is blocked by Roskomnadzor. I encountered the same problem. Try VPN and that's it

Thanks Roman!

 


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

//--- global variables
CCustomBot bot;
int macd_handle;
datetime time_signal=0;
bool checked;
//+------------------------------------------------------------------+
//| Expert initialisation function |
//+------------------------------------------------------------------+
int OnInit()
{
time_signal=0;

bot.Token(InpToken);

#ifdef __MQL5__
macd_handle=iMACD(NULL,0,12,26,9,PRICE_CLOSE);
if(macd_handle==INVALID_HANDLE)
{
Print("Invalid iMACD 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 deinitialisation 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 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,"/\x2611");
bot.SendMessage(InpChannelName,"\x2705\x2705\x2705");
}
}
*/
//+------------------------------------------------------------------+
//| 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 macd[2]={};
double signal[2]={};

#ifdef __MQL4__
for(int i=0;i<=1;i++)
{
macd[i] = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,i);
signal[i]= iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,i);
}
#endif

#ifdef __MQL5__
if(CopyBuffer(macd_handle,0,1,2,macd)!=2)
return;
if(CopyBuffer(macd_handle,1,1,2,signal)!=2)
return;
#endif

time_signal=time[0];

//--- Send signal BUY
if(macd[1]>signal[1] &&
macd[0]<=signal[0] &&
macd[0]<0.0)
{
string msg=StringFormat("Name: MACD 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(macd[1]<signal[1] &&
macd[0]>=signal[0] &&
macd[0]>0.0)
{
string msg=StringFormat("Name: MACD 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));
}
}
}
//+------------------------------------------------------------------+

INDICATOR NAME ( MACD Coloured Histogram) , THAT IS THE QUESTION HOW TO MAKE A SIGNAL WITH THIS INDICATOR

Документация по MQL5: Константы, перечисления и структуры / Константы графиков / Свойства графиков
Документация по MQL5: Константы, перечисления и структуры / Константы графиков / Свойства графиков
  • www.mql5.com
Признак отрисовки ценового графика. Если установлено значение false, то отключается отрисовка любых атрибутов ценового графика и устраняются все отступы по краям графика: шкалы времени и цены, строка быстрой навигации, метки событий Календаря, значки сделок, тултипы индикаторов и баров, подокна индикаторов, гистограммы объёмов и т.д...
 
Andrey Voytenko:

Thanks for your positive feedback. But WebRequest() function cannot be executed in the Strategy Tester.


Dear Andrey,

thank you for your wonderful article!

Since WebRequest() function doesn't work with strategy tester, is there a way to receive notifications with bots while executing the Strategy Tester?

Thank you

 
Jefferson Metha:

Did you try Just sending without the m

or better yet this 

//+------------------------------------------------------------------+
string CTelebot::TradeSymbol(string txt)
  {
   string symbol;
   if(SymbolFind(txt))
     {
      symbol = txt;
      return symbol;
     }
   if(SymbolFind(txt + suffix))
     {
      symbol = txt + suffix;
      return symbol;
     }
   if(SymbolFind(GetSymbolDescription(txt)))
      return GetSymbolDescription(txt);
   else
      // symbol = SymbolGet(txt);
      symbol = "EMPTY";
   return symbol;
  }
//--------------------------------------------------+



I have a small problem guys How do I get channel / group name using chat.m_id

 
Andrey Voytenko:

Please fix the line 117:

Dear Andrey,

Your work is impressive! And the jobs performed as well


I have 1 issue and 1 question for the Telegram_Bot_EA

1. I get this message on the mt4. What could be the reason for it? Can you help with a solution?

   0    08:25:24.546    Telegram_Bot_EA mt4 GBPUSD,H1: Screenshot file 'NZDUSD60.gif' not created.

2. Where I have to change the size of the font of the Telegram buttons? - I would like to make the text a bit smaller


Thanks in advance for your help!

 

@Deyan Ivanov

I have this problems too, this is my code fixed for MT4. Edit file "Telegram_Bot_EA.mq4" replace method "int SendScreenShot(...)"

//+------------------------------------------------------------------+
   int               SendScreenShot(const long _chat_id,
                                    const string _symbol,
                                    const ENUM_TIMEFRAMES _period,
                                    const string _template=NULL)
     {

	......................

      Sleep(50);

      bool resultShot = ChartScreenShot(chart_id,filename,2560,1200,ALIGN_RIGHT);
      ChartClose(chart_id);
      if(resultShot)
        {
         Sleep(500);

         bot.SendChatAction(_chat_id,ACTION_UPLOAD_PHOTO);

         //---
         if(FileIsExist(filename))
           {
            string screen_id;
            result=bot.SendPhoto(photo_id,_chat_id,filename,_symbol+"_"+StringSubstr(EnumToString(_period),7));
           }
         else
           {
            string mask=m_lang==LANGUAGE_EN?"Screenshot file '%s' not created.":"Файл скриншота '%s' не создан.";
            PrintFormat(mask,filename);
           }

        }


      
....................
     }
 
Hello, Andrey. Could you help me please - is there a way to send a message about closing a deal with/without takeprofit?
 
volohovnp:
Hello, Andrey. Could you help me please - is there a way to send a message about closing a deal with/without takeprofit?
I send a comment with each trade, then I send message stating Symbol, OrderType and the Comment, and the Action I want done 

Message e.g
Close 
EurUSD Buy 
Trade #23 

Or 

Close by 0.21 lots    or Close by 50% 
<Other parameters I will change based on Order>
 
Hi, this we request function takes many time, better make by sockets, I tried but I couldn't convert, can someone help to change webreq to socket?