Need some help on Telegram_Signal_EA

To add comments, please log in or register
Angel Dickinson
161
Angel Dickinson  

Hey guys, so basically I have taken the source code provided from an Article titled create bots for telegram and basically edited the code for the telegram_signal_EA to basically send trade 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));
        }
     }
  }
//+------------------------------------------------------------------+
Fernando Carreiro
5075
Fernando Carreiro  
Angel Dickinson: Hey guys, so basically I have taken the source code provided from an Article titled create bots for telegram and basically edited the code for the telegram_signal_EA to basically send trade 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
  1. Why not ask the author himself by posting on the article's thread?
  2. Have you added Telegram's URL ("https://api.telegram.org") to MetaTrader's list of allowed URLs for the WebRequest function ("Tools" -> "Options" -> "Expert Advisors" -> "Allow WebRequest for listed URL:")?
To add comments, please log in or register